7ec@sdZdZddlZddlZddlZddlZddlmZmZdZ ej de Z ej de e fZ ej dd Zd fd YZd Zej ejd eejZdZdZdfdYZdS(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 s$Id$iN(tDistutilsGetoptErrortDistutilsArgErrors[a-zA-Z](?:[a-zA-Z0-9-]*)s^%s$s ^(%s)=!(%s)$t-t_t FancyGetoptcBseZdZddZdZdZdddZdZdZ dZ dZ d Z d Z ddd Zd Zdd ZdddZRS(sWrapper 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 cCst||_i|_|jr(|jni|_i|_g|_g|_i|_i|_i|_ g|_ dS(N( t option_tablet option_indext _build_indextaliastnegative_aliast short_optst long_optst short2longt attr_namet takes_argt option_order(tselfR((s./usr/lib64/python2.7/distutils/fancy_getopt.pyt__init__-s           cCs6|jjx"|jD]}||j|d= 2is:invalid short option '%s': must a single character or Noneit=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 ValueErrort isinstancetstrRtNoneRRR tgetRt longopt_retmatchRR (RRtlongtshortthelpR(talias_to((s./usr/lib64/python2.7/distutils/fancy_getopt.pyt_grok_option_tablesd     "  !         c Cs|dkrtjd}n|dkr:t}d}nd}|jtj|j}y"tj|||j \}}Wntj k r}t |nXx|D]\}}t |dkr|ddkr|j |d}n |d}|jj|} | r| }n|j|sQ|jj|} | rH| }d}qQd}n|j|} |r|jj| dk rt|| dd}nt|| ||jj||fqW|r||fS|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. iiiRN(R-tsystargvt OptionDummyR5RtjoinR tgetoptR terrorRR)R RR.RR R R(tgetattrtsetattrRR( Rtargstobjecttcreated_objectR toptstmsgR"tvalRtattr((s./usr/lib64/python2.7/distutils/fancy_getopt.pyR:sB     " "       cCs&|jdkrtdn|jSdS(sReturns 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(RR-t RuntimeError(R((s./usr/lib64/python2.7/distutils/fancy_getopt.pytget_option_order*s cCsd}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]}|d \}}} t| | } |ddkr|dd!}n|dkrk| rQ| jd ||| dfq| jd ||fnHd ||f}| r| jd ||| dfn| jd|x#| dD]}| j| |qWqW| S(sGenerate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object. iiiR&iiiNt sOption summary:is --%-*s %ss --%-*s s%s (-%s)s --%-*sN(RR)R-t wrap_textR(Rtheadertmax_optRR1R2tlt opt_widtht line_widtht text_widtht big_indenttlinesR3ttextt opt_names((s./usr/lib64/python2.7/distutils/fancy_getopt.pyt generate_help5sF             ! cCsG|dkrtj}nx(|j|D]}|j|dq(WdS(Ns (R-R6tstdoutRStwrite(RRItfiletline((s./usr/lib64/python2.7/distutils/fancy_getopt.pyt print_helps  N(t__name__t __module__t__doc__R-RRRRRRR#R$R%R5R:RFRSRX(((s./usr/lib64/python2.7/distutils/fancy_getopt.pyR!s  ,      X@ TcCs)t|}|j||j||S(N(RR%R:(toptionst negative_optR?R>tparser((s./usr/lib64/python2.7/distutils/fancy_getopt.pyt fancy_getopts  RGcCs~|dkrgSt||kr)|gStj|}tj|t}tjd|}td|}g}x|ryg}d}xt|rt|d}|||kr|j |d|d=||}q|r|dddkr|d=nPqW|r]|dkr<|j |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( +|-+)iiRGtN( R-R)Rt expandtabsRtWS_TRANStretsplittfilterRR9(RQtwidthtchunksRPtcur_linetcur_lenRK((s./usr/lib64/python2.7/distutils/fancy_getopt.pyRHs:       cCstj|tS(sXConvert a long option name to a valid Python identifier by changing "-" to "_". (RRR(R"((s./usr/lib64/python2.7/distutils/fancy_getopt.pyttranslate_longoptsR8cBseZdZgdZRS(s_Dummy class just used as a place to hold command-line option values as instance attributes.cCs%x|D]}t||dqWdS(skCreate a new OptionDummy instance. The attributes listed in 'options' will be initialized to None.N(R=R-(RR\R"((s./usr/lib64/python2.7/distutils/fancy_getopt.pyRs (RYRZR[R(((s./usr/lib64/python2.7/distutils/fancy_getopt.pyR8s(R[t __revision__R6RRcR:tdistutils.errorsRRt longopt_pattcompileR/t neg_alias_ret maketransRRR_t whitespaceR)RbRHRjR8(((s./usr/lib64/python2.7/distutils/fancy_getopt.pyt s"    r " ;