ðÕYfxEã@sHdZddlZddlZddlZddlZddlTdZejdeƒZejdeefƒZ e j ddƒZ Gd d „d ƒZ d d „Zd d„ejDƒZdd„Zdd„ZGdd„dƒZedkrDdZxKddddfD]7Zedeƒedjeeeƒƒƒeƒq WdS)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 NcCsq||_i|_|jr%|jƒi|_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/python35/lib64/python3.5/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Ú ValueErrorr Ústrrrrr Úgetr Ú longopt_reÚmatchrr)rrÚlongÚshortÚhelpr0Zalias_torrrÚ_grok_option_table…s^     "  !         zFancyGetopt._grok_option_tablec Cs2|dkrtjdd…}|dkr=tƒ}d}nd}|jƒdj|jƒ}y"tj|||jƒ\}}Wn4tjk r·}zt |ƒ‚WYdd}~XnXx_|D]W\}}t |ƒdkr|ddkr|j |d}n>t |ƒdkr)|dd…d ks/t ‚|dd…}|j j|ƒ} | r]| }|j|s¯|d ks‚t d ƒ‚|jj|ƒ} | r©| }d}nd}|j|} |rð|jj| ƒdk rðt|| dƒd}t|| |ƒ|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+rrz--Úzboolean option can't have value)ÚsysÚargvÚ OptionDummyr:Újoinr Úgetoptr ÚerrorZDistutilsArgErrorr1r r"r r4rr rr0ÚgetattrÚsetattrrr) rÚargsÚobjectZcreated_objectr ZoptsÚmsgr%Úvalr ÚattrrrrrAÒsF     "".    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}xs|jD]h}|d}|d}t|ƒ}|ddkrP|d}|dk rf|d}||kr|}qW|ddd}d}||} d|} |rº|g} n d g} x|jD]}|dd …\}}} t| | ƒ} |ddkr|dd…}|dkrh| rN| 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+éNr;zOption summary:r)z --%-*s %sz --%-*s z%s (-%s)z --%-*sr/r/r/)rr1Ú wrap_textr)rÚheaderZmax_optrr7r8ÚlZ opt_widthZ line_widthZ text_widthZ big_indentÚlinesr9ÚtextZ opt_namesrrrÚ generate_helpsF             ! zFancyGetopt.generate_helpcCsD|dkrtj}x(|j|ƒD]}|j|dƒq%WdS)NÚ )r=ÚstdoutrSÚwrite)rrOÚfileÚlinerrrÚ print_helphs  zFancyGetopt.print_help)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrr&r'r(r:rArKrSrYrrrrrs (       M= OrcCs)t|ƒ}|j|ƒ|j||ƒS)N)rr(rA)ÚoptionsZ negative_optrFrEÚparserrrrÚ fancy_getoptos  r`cCsi|]}dt|ƒ“qS)r;)Úord)Ú.0Z_wscharrrrú us rccCsv|dkrgSt|ƒ|kr)|gS|jƒ}|jtƒ}tjd|ƒ}dd„|Dƒ}g}x|rqg}d}xq|r÷t|dƒ}|||krÒ|j|dƒ|d=||}q‡|ró|d ddkró|d =Pq‡W|rX|dkr=|j|dd|…ƒ|d|d…|d<|dddkrX|d=|jdj|ƒƒqrW|S) z¶wrap_text(text : string, width : int) -> [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)rbZchrrrú …s zwrap_text..rr,r;r<r/r/)r1Ú expandtabsrÚWS_TRANSÚreÚsplitrr@)rRÚwidthZchunksrQZcur_lineZcur_lenrPrrrrNws:      rNcCs |jtƒS)zXConvert a long option name to a valid Python identifier by changing "-" to "_". )rr)r%rrrÚtranslate_longopt­srjc@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)rD)rr^r%rrrr¸s zOptionDummy.__init__N)rZr[r\r]rrrrrr?´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: %drT)r]r=ÚstringrgrAZdistutils.errorsZ longopt_patÚcompiler5Z neg_alias_rer3Ú maketransrrr`Z whitespacerfrNrjr?rZrRÚwÚprintr@rrrrÚ s($  ÿS  6