³ò žl‡Jc @sSdZdZddkZddkZddkZddkTddkZddkTdZei deƒZ ei deefƒZ ei dd ƒZ d fd „ƒYZd „Zei eid eeiƒƒZd„Zd„Zdfd„ƒYZedjoKdZx>ddddfD]*ZdeGHeieeeƒdƒGHHqWndS(s6distutils.fancy_getopt Wrapper around the standard getopt module that provides the following additional features: * short and long options are tied together * options have help strings, so fancy_getopt could potentially create a complete usage summary * options set attributes of a passed-in object s8$Id: fancy_getopt.py 37828 2004-11-10 22:23:15Z loewis $iÿÿÿÿN(t*s[a-zA-Z](?:[a-zA-Z0-9-]*)s^%s$s ^(%s)=!(%s)$t-t_t FancyGetoptcBs¤eZdZdd„Zd„Zd„Zddd„Zd„Zd„Z d„Z d„Z d „Z d „Z ddd „Zd „Zdd „Zddd„ZRS(sÕWrapper around the standard 'getopt()' module that provides some handy extra functionality: * short and long options are tied together * options have help strings, and help text can be assembled from them * options set attributes of a passed-in object * boolean options can have "negative aliases" -- eg. if --quiet is the "negative alias" of --verbose, then "--quiet" on the command line sets 'verbose' to false cCsv||_h|_|io|iƒnh|_h|_g|_g|_h|_h|_h|_ g|_ dS(N( t option_tablet option_indext _build_indextaliastnegative_aliast short_optst long_optst short2longt attr_namet takes_argt option_order(tselfR((s)/sys/lib/python/distutils/fancy_getopt.pyt__init__.s          cCs6|iiƒx"|iD]}||i|d= 2is:invalid short option '%s': must a single character or Noneiÿÿÿÿt=t:s>invalid negative alias '%s': aliased option '%s' takes a valuesginvalid alias '%s': inconsistent with aliased option '%s' (one of them takes a value, the other doesn'tsinvalid long option name '%s' s'(must be letters, numbers, hyphens onlyN(R R R RtrepeatRtlent ValueErrorR t StringTypeRtNoneRR RtgetRt longopt_retmatchRR (RRtlongtshortthelpR,talias_to((s)/sys/lib/python/distutils/fancy_getopt.pyt_grok_option_table“sd      &  &       c Cs0|djotid}n|djotƒ}d}nd}|iƒti|iƒ}y"ti|||i ƒ\}}Wn!ti j o}t |‚nXxj|D]b\}}t |ƒdjo&|ddjo|i |d}n6t |ƒdjo|d djpt‚|d}|ii|ƒ} | o | }n|i|pJ|djp td‚|ii|ƒ} | o| }d}q¢d}n|i|} |o3|ii| ƒdj ot|| dƒd}nt|| |ƒ|ii||fƒq­W|o||fSn|SdS( sParse command-line options in args. Store as attributes on object. If 'args' is None or not supplied, uses 'sys.argv[1:]'. If 'object' is None or not supplied, creates a new OptionDummy object, stores option values there, and returns a tuple (args, object). If 'object' is supplied, it is modified in place and 'getopt()' just returns 'args'; in both cases, the returned 'args' is a modified copy of the passed-in 'args' list, which is left untouched. iiiRs--tsboolean option can't have valueN(R0tsystargvt OptionDummyR8RtjoinR tgetoptR terrortDistutilsArgErrorR-R R"RR1R RR R,tgetattrtsetattrRR( Rtargstobjecttcreated_objectR toptstmsgR&tvalRtattr((s)/sys/lib/python/distutils/fancy_getopt.pyR>ësH     " $+      cCs(|idjo td‚n|iSdS(s«Returns the list of (option, value) tuples processed by the previous run of 'getopt()'. Raises RuntimeError if 'getopt()' hasn't been called yet. s!'getopt()' hasn't been called yetN(RR0t RuntimeError(R((s)/sys/lib/python/distutils/fancy_getopt.pytget_option_order+s c Csñd}x‚|iD]w}|d}|d}t|ƒ}|ddjo|d}n|dj o|d}n||jo |}qqW|ddd}d}||} d|} |o |g} n d g} x|iD] }|d \}}} t| | ƒ} |ddjo|dd!}n|djoD| o"| id ||| dfƒqÃ| id ||fƒnKd ||f}| o"| id ||| dfƒn| id|ƒx#| dD]}| i| |ƒqÎWqÞW| S(sŒGenerate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object. iiiÿÿÿÿR*iiiNt sOption summary:is --%-*s %ss --%-*s s%s (-%s)s --%-*sN(RR-R0t wrap_textR(Rtheadertmax_optRR4R5tlt opt_widtht line_widtht text_widtht big_indenttlinesR6ttextt opt_names((s)/sys/lib/python/distutils/fancy_getopt.pyt generate_help6sL            "  cCsI|djo ti}nx(|i|ƒD]}|i|dƒq*WdS(Ns (R0R:tstdoutRXtwrite(RRNtfiletline((s)/sys/lib/python/distutils/fancy_getopt.pyt print_helpŠs   N(t__name__t __module__t__doc__R0RRRRRRR'R(R)R8R>RKRXR](((s)/sys/lib/python/distutils/fancy_getopt.pyR"s  ,      X@ TcCs)t|ƒ}|i|ƒ|i||ƒS(N(RR)R>(toptionst negative_optRDRCtparser((s)/sys/lib/python/distutils/fancy_getopt.pyt fancy_getopt“s  RLcCs—|djogSnt|ƒ|jo |gSnti|ƒ}ti|tƒ}tid|ƒ}td|ƒ}g}x|o g}d}x{|ost|dƒ}|||jo&|i |dƒ|d=||}q”|o |dddjo |d=nPq”W|o_|djo.|i |dd|!ƒ|d||d [string] Split 'text' into multiple lines of no more than 'width' characters each, and return the list of strings that results. s( +|-+)iiÿÿÿÿRLR9N( R0R-Rt expandtabsRtWS_TRANStretsplittfilterRR=(RVtwidthtchunksRUtcur_linetcur_lenRP((s)/sys/lib/python/distutils/fancy_getopt.pyRM›s:      cCsti|tƒS(sXConvert a long option name to a valid Python identifier by changing "-" to "_". (RRR(R&((s)/sys/lib/python/distutils/fancy_getopt.pyttranslate_longoptØsR<cBseZdZgd„ZRS(s_Dummy class just used as a place to hold command-line option values as instance attributes.cCs%x|D]}t||dƒqWdS(skCreate a new OptionDummy instance. The attributes listed in 'options' will be initialized to None.N(RBR0(RRaR&((s)/sys/lib/python/distutils/fancy_getopt.pyRãs(R^R_R`R(((s)/sys/lib/python/distutils/fancy_getopt.pyR<ßst__main__s¢Tra-la-la, supercalifragilisticexpialidocious. How *do* you spell that odd word, anyways? (Someone ask Mary -- she'll know [or she'll say, "How should I know?"].)i iii(s width: %ds (R`t __revision__R:RRgttypesR>tdistutils.errorst longopt_pattcompileR2t neg_alias_ret maketransRRRdt whitespaceR-RfRMRnR<R^RVtwR=(((s)/sys/lib/python/distutils/fancy_getopt.pys s.$   ÿr " =