Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/distutils/fancy_getopt.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c@sSdZdZddkZddkZddkZddkTddkZddkTdZei	de�Z
ei	deef�Zei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_tFancyGetoptcBs�eZdZdd�Zd�Zd�Zddd�Zd�Zd�Z	d�Z
d�Zd	�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<qWdS(Ni(RtclearR(Rtoption((s)/sys/lib/python/distutils/fancy_getopt.pyRZs

cCs||_|i�dS(N(RR(RR((s)/sys/lib/python/distutils/fancy_getopt.pytset_option_table_s	cCsT|ii|�otd|�n-|||f}|ii|�||i|<dS(Ns'option conflict: already an option '%s'(Rthas_keytDistutilsGetoptErrorRtappend(Rtlong_optiontshort_optionthelp_stringR((s)/sys/lib/python/distutils/fancy_getopt.pyt
add_optioncscCs|ii|�S(scReturn true if the option table for this parser has an
        option with long name 'long_option'.(RR(RR((s)/sys/lib/python/distutils/fancy_getopt.pyt
has_optionmscCsti|t�S(s�Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores.(tstringt	translatet
longopt_xlate(RR((s)/sys/lib/python/distutils/fancy_getopt.pyt
get_attr_namerscCs�t|�tjpt�xt|i�D]f\}}|ii|�ptd|||f�n|ii|�ptd|||f�q'q'WdS(Ns(invalid %s '%s': option '%s' not defineds0invalid %s '%s': aliased option '%s' not defined(ttypetDictionaryTypetAssertionErrortitemsRRR(RtaliasestwhatRtopt((s)/sys/lib/python/distutils/fancy_getopt.pyt_check_alias_dictys
cCs|i|d�||_dS(s'Set the aliases for this option parser.RN(R'R(RR((s)/sys/lib/python/distutils/fancy_getopt.pytset_aliases�scCs|i|d�||_dS(s�Set the negative aliases for this option parser.
        'negative_alias' should be a dictionary mapping option names to
        option names, both the key and value must already be defined
        in the option table.snegative aliasN(R'R(RR((s)/sys/lib/python/distutils/fancy_getopt.pytset_negative_aliases�scCs�g|_g|_|ii�h|_x}|iD]r}t|�djo|\}}}d}n:t|�djo|\}}}}ntd|f�t|�t	j	pt|�djot
d|�n|djp#t|�t	jot|�djpt
d|�n||i|<|ii|�|d	d
jo3|o|d}n|dd	!}d|i
|<np|ii|�}|dj	oC|i
|ot
d||f�n||id	<d|i
|<nd|i
|<|ii|�}|dj	o6|i
||i
|jot
d
||f�q=nti|�pt
dd|�n|i|�|i|<|o%|ii|�||i|d<q2q2WdS(s�Populate the various data structures that keep tabs on the
        option table.  Called by 'getopt()' before it can do anything
        worthwhile.
        iiisinvalid option tuple: %ris9invalid long option '%s': must be a string of length >= 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	RRtrepeatRtlent
ValueErrorR t
StringTypeRtNoneRR
RtgetRt
longopt_retmatchRR(RRtlongtshortthelpR,talias_to((s)/sys/lib/python/distutils/fancy_getopt.pyt_grok_option_table�sd		
	

&
&





cCs0|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(R0tsystargvtOptionDummyR8RtjoinR	tgetoptR
terrortDistutilsArgErrorR-RR"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
cCs�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<n|dddjo|d=qun|i	ti
|d��q~W|S(s�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.
    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.errorstlongopt_pattcompileR2tneg_alias_ret	maketransRRRdt
whitespaceR-RfRMRnR<R^RVtwR=(((s)/sys/lib/python/distutils/fancy_getopt.pys<module>	s.$

�"	=	

	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].