î i fxEã@sKdZddlZddlZddlZddlZddlTdZejdeƒZejdeefƒZ e j ddƒZ Gd d „d ƒZ d d „Zd d„ejDƒZdd„Zdd„ZGdd„dƒZedkrGdZxKddddfD]7Zedeƒedjeeeƒƒƒeƒq WndS)a6distutils.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 éN)Ú*z[a-zA-Z](?:[a-zA-Z0-9-]*)z^%s$z ^(%s)=!(%s)$ú-Ú_c@sÖeZdZdZddd„Zdd„Zdd„Zddd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dddd„Zdd„Zddd„Zdddd„ZdS)Ú FancyGetoptaÕ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 NcCst||_i|_|jr(|jƒni|_i|_g|_g|_i|_i|_i|_ g|_ dS)N) Ú option_tableÚ option_indexÚ _build_indexÚaliasÚnegative_aliasÚ short_optsÚ long_optsÚ short2longÚ attr_nameÚ takes_argÚ option_order)Úselfr©rú;/opt/alt/python34/lib64/python3.4/distutils/fancy_getopt.pyÚ__init__)s           zFancyGetopt.__init__cCs6|jjƒx"|jD]}||j|d= 2Néz:invalid short option '%s': must a single character or Noneú=ú:z>invalid negative alias '%s': aliased option '%s' takes a valuezginvalid alias '%s': inconsistent with aliased option '%s' (one of them takes a value, the other doesn'tzEinvalid long option name '%s' (must be letters, numbers, hyphens onlyéÿÿÿÿr,r,)r r r rÚrepeatrÚlenÚ ValueErrorÚ isinstanceÚstrrrrr Úgetr Ú longopt_reÚmatchrr)rrÚlongÚshortÚhelpr-Zalias_torrrÚ_grok_option_table…s^     "  !        zFancyGetopt._grok_option_tablec Csø|dkr"tjdd…}n|dkr@tƒ}d}nd}|jƒdj|jƒ}y"tj|||jƒ\}}Wn4tjk rº}zt |ƒ‚WYdd}~XnXx"|D]\}}t |ƒdkr|ddkr|j |d}n|dd…}|j j |ƒ} | r5| }n|j|sr|jj |ƒ} | ri| }d}qrd}n|j|} |r¶|jj | ƒdk r¶t|| dƒd}nt|| |ƒ|jj||fƒqÂW|rð||fS|SdS) aParse 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. Nr)TFú r(rr)ÚsysÚargvÚ OptionDummyr8Újoinr Úgetoptr ÚerrorZDistutilsArgErrorr.r r r2rr rr-ÚgetattrÚsetattrrr) rÚargsÚobjectZcreated_objectr ZoptsÚmsgr"Úvalr Úattrrrrr>ÒsB     ""      zFancyGetopt.getoptcCs)|jdkrtdƒ‚n|jSdS)z«Returns the list of (option, value) tuples processed by the previous run of 'getopt()'. Raises RuntimeError if 'getopt()' hasn't been called yet. Nz!'getopt()' hasn't been called yet)rÚ RuntimeError)rrrrÚget_option_orderszFancyGetopt.get_option_ordercCsðd}x||jD]q}|d}|d}t|ƒ}|ddkrS|d}n|dk rl|d}n||kr|}qqW|ddd}d}||} d|} |rÃ|g} n d g} x|jD]}|dd …\}}} t| | ƒ} |ddkr'|dd…}n|dkrt| rZ| jd ||| dfƒq¼| jd ||fƒnHd ||f}| r«| jd ||| dfƒn| jd|ƒx)| dd…D]}| j| |ƒqÍWqÖW| S)zŒGenerate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object. rr)r*Nér(éNr9zOption summary:r&z --%-*s %sz --%-*s z%s (-%s)z --%-*sr,r,r,)rr.Ú wrap_textr)rÚheaderZmax_optrr5r6ÚlZ opt_widthZ line_widthZ text_widthZ big_indentÚlinesr7ÚtextZ opt_namesrrrÚ generate_helpsF             ! zFancyGetopt.generate_helpcCsG|dkrtj}nx(|j|ƒD]}|j|dƒq(WdS)NÚ )r:ÚstdoutrPÚwrite)rrLÚfileÚlinerrrÚ print_helphs  zFancyGetopt.print_help)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrr#r$r%r8r>rHrPrVrrrrrs (       M= OrcCs)t|ƒ}|j|ƒ|j||ƒS)N)rr%r>)ÚoptionsZ negative_optrCrBÚparserrrrÚ fancy_getoptos  r]cCsi|]}dt|ƒ“qS)r9)Úord)Ú.0Z_wscharrrrú us r`cCs‚|dkrgSt|ƒ|kr)|gS|jƒ}|jtƒ}tjd|ƒ}dd„|Dƒ}g}x |r}g}d}xt|rút|dƒ}|||krÒ|j|dƒ|d=||}q‡|rö|d ddkrö|d =nPq‡W|rd|dkrC|j|dd|…ƒ|d|d…|d [string] Split 'text' into multiple lines of no more than 'width' characters each, and return the list of strings that results. Nz( +|-+)cSsg|]}|r|‘qSrr)r_Zchrrrú …s zwrap_text..rr)r9Úr,r,)r.Ú expandtabsrÚWS_TRANSÚreÚsplitrr=)rOÚwidthZchunksrNZcur_lineZcur_lenrMrrrrKws:        rKcCs |jtƒS)zXConvert a long option name to a valid Python identifier by changing "-" to "_". )rr)r"rrrÚtranslate_longopt­srhc@s%eZdZdZgdd„ZdS)r<z_Dummy class just used as a place to hold command-line option values as instance attributes.cCs%x|D]}t||dƒqWdS)zkCreate a new OptionDummy instance. The attributes listed in 'options' will be initialized to None.N)rA)rr[r"rrrr¸s zOptionDummy.__init__N)rWrXrYrZrrrrrr<´s r<Ú__main__z¢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?"].)é ééé(z width: %drQ)rZr:Ústringrer>Zdistutils.errorsZ longopt_patÚcompiler3Z neg_alias_rer1Ú maketransrrr]Z whitespacerdrKrhr<rWrOÚwÚprintr=rrrrÚ s($  ÿS  6