dbfdg 3 ([Qh2@sXddlmZddlmZddZddZGdddZGd d d eZGd d d Zd S))Action) ConfigParsercCst|}|tkp|tkS)z@Return true if val is an instance of a known sequence type. )typelisttuple)valZval_typer/usr/lib/python3.6/options.py_is_seq sr cCs$|j}|d krdS|d kr dSdS) NtrueonyesTfalseoffnoF)r r r )rrr)lower)rZ_valrrr str_to_bools rc@seZdZddZddZd dd Zd d Zd d ZifddZe ifddZ e ddZ ddZ ddZ d!ddZd"ddZddZdS)# SoSOptionscCsdd}t||rt||}t||}||r8|| sP|sP||jkr|t| r|t||||rn|jj|q|jj|nt|rt||||dS)NcSs|dkp|dkS)Nr)rrrr _unset sz%SoSOptions._merge_opt.._unset)hasattrgetattr _nondefaultr setattrdiscardadd)selfoptsrc is_defaultrZnewvalueZoldvaluerrr _merge_opts    zSoSOptions._merge_optcCs4t|tst|}x|jD]}|j|||qWdS)N) isinstancedictvars arg_namesr )rrrargrrr _merge_opts7s  zSoSOptions._merge_optsF rc s~|}d}xjD]}||||7}qW|j|fddjD}|sZdd|D}ndd|D}|t|j||S)aIFormat a SoSOptions object as a human or machine readable string. :param quote: quote option values :param sep: list separator string :param prefix: arbitrary prefix string :param suffix: arbitrary suffix string :param literal: print values as Python literals z=%scsg|]}t|qSr)r).0r%)rrr Lsz$SoSOptions.__str..cSs"g|]}t|rdj|n|qS),)r join)r(vrrr r)OscSs&g|]}t|trd|dn|qS)')r!str)r(r,rrr r)Rs)r$stripr) rquotesepprefixsuffixargsZarg_fmtr%valsr)rr Z__str=s   zSoSOptions.__strcCs|jS)N)_SoSOptions__str)rrrr __str__VszSoSOptions.__str__cCs|jdddddS)NTz, z SoSOptions())r0r1r2r3)r6)rrrr __repr__Ys zSoSOptions.__repr__cKsp||_t|j|_t|_x |jD]}t|||j|q$Wx,|jD] \}}|jj|t|||qHWdS)aInitialise a new ``SoSOptions`` object from keyword arguments. Initialises the new object with values taken from keyword arguments matching the names of ``SoSOptions`` attributes. A ``ValueError`` is raised is any of the supplied keyword arguments does not correspond to a known ``SoSOptions` attribute name. :param *kwargs: a list of ``SoSOptions`` keyword args. :returns: the new ``SoSOptions`` object. N) arg_defaultsrkeysr$setrritemsappend)rr:kwargsr%Zkwargrrr __init__]s   zSoSOptions.__init__cCs&tft|d|i}|j|d|S)a Initialise a new SoSOptions object from a ``Namespace`` obtained by parsing command line arguments. :param args: parsed command line arguments :returns: an initialised SoSOptions object :returntype: SoSOptions r:T)rr#r&)clsr4r:Zoptsrrr from_argsus  zSoSOptions.from_argscsRd}d}|krdgS|kr@fddtdt|DSdd|gS)zConvert a named option and optional value to command line argument notation, correctly handling options that take no value or that have special representations (e.g. verify and verbose). alloptionsallow-system-changesall-logsbatchbuilddebug experimental list-plugins list-presets list-profiles no-report no-env-varsquietverifyverbosez--csg|]}dqS)z--r)r(d)rrr r)sz+SoSOptions._opt_to_args..r=)rCrDrErFrGrHrIrJrKrLrMrNrOrP)rQ)rangeint)rArrZno_valuecountr)rr _opt_to_argss zSoSOptions._opt_to_argscCst|j|t|r|St|j|tr6t|jdSt|j|trpt|}|dkrltd|d|d|St|j|trt|S|S)aEnsure that the value read from a config file is the proper type for consumption by the component, as defined by arg_defaults. Params: :param key: The key in arg_defaults we need to match the type of :param val: The value to be converted to a particular type :param conf: File values are being loaded from r*Nz Value of 'z' in z# must be True or False or analagous) r!r:rrsplitboolr ExceptionrU)rkeyrZconfrrr _convert_to_types zSoSOptions._convert_to_typec sfdd}t}y(tdd}|j|WdQRXWn<tk rx}z tdd|jdWYdd}~XnX|d |||||jd rtd rtd rx>|jd D]0\}}|j d dj krj j |d|qWdS)zRead the provided config_file and update options from that. Positional arguments: :param config_file: Filepath to the config file :param component: Which component (section) to load cs|j|rt|j|}d|jkr6t|jd|d<dddd}xHt|D]<}d|krn|j|||jdd<||krL|j||||<qLWxn|jD]b\}}t|t r|d kr|jd d }|j krt d |d |dqj ||}t ||qWdS)NrQ verbosityZlabelplugoptsZprofiles)nameZ plugin_optionZprofile-_keywordsr'rzUnknown option 'z' in section 'r-) has_sectionr"r=r;rUpoprreplacer!r.r:printr\r)ZsectionconfigodictZ rename_optsr[r) config_filerrr _update_from_sections(    z9SoSOptions.update_from_conf.._update_from_sectionzutf-8)encodingNz+WARNING: Unable to read configuration file z : globalZplugin_optionsr^ skip_plugins.rrS) ropenZ read_fileOSErrorrfr4rcrr=rXrnr^r>) rriZ componentrjrgfer[rr)rirr update_from_confs "*   zSoSOptions.update_from_confTcCsBx<|jD]2}t||sqt||dk s,| r|j||dqWdS)aNMerge another set of ``SoSOptions`` into this object. Merge two ``SoSOptions`` objects by setting unset or default values to their value in the ``src`` object. :param src: the ``SoSOptions`` object to copy from :param is_default: ``True`` if new default values are to be set. NF)r$rrr )rrZ skip_defaultr%rrr merges  zSoSOptions.mergecCs:i}x0|jD]&}t||}|r*|dkr*d}|||<q W|S)zReturn this ``SoSOptions`` option values as a dictionary of argument name to value mappings. :returns: a name:value dictionary of option values. add_preset del_presetdescnoteN)rvrwrxry)r$r)rZ preset_filterrhr%valuerrr r"s   zSoSOptions.dictcsLfddfddddtjjddd }fd d |DS) zReturn command arguments for this object. Return a list of the non-default options of this ``SoSOptions`` object in ``sos report`` command line argument notation: ``["--all-logs", "-vvv"]`` csNd }| s||krdS|dkr&|r&d S|jkrJt|tj|krJdSd S) z. Test for non-null option values. FalseNone[]""''0Fr^T)r{r|r}r~rr)r:r.)r_rzZ null_values)rrr has_values  z%SoSOptions.to_args..has_valuecs*|d kr dS|d kr |d kr d S||S) z8 Filter out preset and null-valued options. rvrwrxryFlog_sizeplugin_timeout cmd_timeoutrT)rvrwrxry)rrrr)r_rz)rrr filter_opt!s z&SoSOptions.to_args..filter_optcSs||jdrdt|d}|S|jdd}t|r.argifycSs|dS)Nrr)xrrr @sz$SoSOptions.to_args..)r[cs$g|]\}}||r||qSrr)r(nr,)rrrr r)Asz&SoSOptions.to_args..)sortedr"r=)rZ opt_itemsr)rrrrr to_args s zSoSOptions.to_argsN)Fr'rr)T)T)__name__ __module__ __qualname__r r&r6r7r9r@ classmethodrBrWr\rtrur"rrrrr rs   >  rc@seZdZdZdddZdS) SosListOptionz0Allow to specify comma delimited list of pluginsNcCs<t|jd}t||jr*|t||j7}t||j|dS)Nr*)rrXrdestr)rparser namespacevaluesZ option_stringr=rrr __call__Hs zSosListOption.__call__)N)rrr__doc__rrrrr rDsrc@seZdZdZdddZdS) ClusterOptionz6Used to store/manipulate options for cluster profiles.NcCs"||_||_||_||_||_dS)N)r_rzopt_typecluster description)rr_rzrrrrrr r@Rs zClusterOption.__init__)N)rrrrr@rrrr rOsrN) argparserZ configparserrr rrrrrrrr  s   )