HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/sos/__pycache__/options.cpython-38.pyc
U

i��d,5�@sdddlmZddlmZmZmZmZdd�Zdd�ZGdd�d�Z	Gd	d
�d
e�Z
Gdd�d�Zd
S)�)�Action)�ConfigParser�ParsingError�Error�DuplicateOptionErrorcCst|�}|tkp|tkS)z@Return true if val is an instance of a known sequence type.
    )�type�list�tuple)�valZval_type�r�-/usr/lib/python3/dist-packages/sos/options.py�_is_seqsr
cCs(|��}|dkrdS|dkr dSdSdS)N)�trueZonZyesT)ZfalseZoffZnoF)�lower)r
Z_valrrr�str_to_boolsrc@s�eZdZdd�Zdd�Zd dd	�Zd
d�Zdd
�Zifdd�Ze	ifdd��Z
e	dd��Zdd�Zdd�Z
d!dd�Zd"dd�Zdd�ZdS)#�
SoSOptionscCs�dd�}t||�r�t||�}t||�}||�r6||�rL|sL||jkrxt|�sxt|||�|rj|j�|�q�|j�|�nt|�r�t||||�dS)NcSs|dkp|dkS)N�r)r
rrr�_unset"sz%SoSOptions._merge_opt.<locals>._unset)�hasattr�getattr�_nondefaultr
�setattr�discard�add)�self�opt�src�
is_defaultrZnewvalueZoldvaluerrr�
_merge_opt!s"


���zSoSOptions._merge_optcCs0t|t�st|�}|jD]}|�|||�qdS�N)�
isinstance�dict�vars�	arg_namesr)rrr�argrrr�_merge_opts9s

zSoSOptions._merge_optsF� rc	sz|}d}�jD]}||||7}q|�|��fdd��jD�}|sVdd�|D�}ndd�|D�}|t|��|�|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�
<listcomp>Nsz$SoSOptions.__str.<locals>.<listcomp>cSs"g|]}t|�rd�|�n|�qS)�,)r
�join�r'�vrrrr)QscSs"g|]}t|t�rd|n|�qS)z'%s')r �strr,rrrr)Ts)r#�stripr	)	r�quote�sep�prefix�suffix�argsZarg_fmtr$Zvalsrr(rZ__str?s	

zSoSOptions.__strcCs|��Sr��_SoSOptions__strr(rrr�__str__XszSoSOptions.__str__cCs|jddddd�S)NTz, zSoSOptions(�))r0r1r2r3r5r(rrr�__repr__[s
�zSoSOptions.__repr__cKsh||_t|���|_t�|_|jD]}t|||j|�q"|��D] }|j�|�t||||�qBdS)a�Initialise 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_defaultsr�keysr#�setrr�append)rr:�kwargsr$rrr�__init___s

zSoSOptions.__init__cCs&tft|�d|i��}|�|d�|S)aInitialise 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_argsws	zSoSOptions.from_argscsPd}d}�|krd�gS�|kr>�fdd�tdt|��D�Sd�d|gS)	z�Convert 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).
        )Z
alloptionszallow-system-changeszall-logsZbatchZbuild�debugZexperimentalzlist-pluginszlist-presetsz
list-profilesz	no-reportzno-env-vars�quietZverify)�verbose�--%scsg|]}d��qS)rEr)r'�d�rrrr)�sz+SoSOptions._opt_to_args.<locals>.<listcomp>r�--�=)�range�int)r@rr
Zno_value�countrrGr�_opt_to_args�s
zSoSOptions._opt_to_argscCs�t|j|t|��r|St|j|t�r<dd�|�d�D�St|j|t�rrt|�}|dkrntd||f��n|St|j|t�r�z
t|�WSt	k
r�td||f��YnX|S)a�Ensure 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
        cSsg|]}|�qSrrr,rrrr)�sz/SoSOptions._convert_to_type.<locals>.<listcomp>r*Nz6Value of '%s' in %s must be True or False or analagousz#Value of '%s' in %s must be integer)
r r:rr�split�boolr�	ExceptionrK�
ValueError)r�keyr
�confrrr�_convert_to_type�s*
��
�zSoSOptions._convert_to_typec

sF��fdd�}t�}z�z$t���}|�|��W5QRXWnZtk
rr}ztd|j|j�f��W5d}~XYn$ttfk
r�td���YnXWn<t	t
fk
r�}ztd�|jdf�W5d}~XYnX|d|�|||�|�
d	��rBt�d
��rB|�d	�D]4\}}	|�d�d�jk�r�j�|d
|	��qdS)z�Read 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�|�|�r�t|�|��}d|��kr6t|�d��|d<dddd�}t|�D]<}d|krl|�|�||�dd�<||krJ|�|�|||<qJ|��D]\\}}t|t	�r�|d	kr�|�d
d�}|�j
kr�td||f�q���||��}t
�||�q�dS)
NrD�	verbosityZlabel�plugoptsZprofiles)�nameZ
plugin_optionZprofile�-�_�keywordsr&rz#Unknown option '%s' in section '%s')�has_sectionr!�itemsr;rK�popr�replacer r.r:�printrTr)�section�config�odictZrename_optsrRr
��config_filerrr�_update_from_section�s.
�
�z9SoSOptions.update_from_conf.<locals>._update_from_sectionz0Duplicate option '%s' in section '%s' in file %sNz%Failed to parse configuration file %sz2WARNING: Unable to read configuration file %s : %s��globalZplugin_optionsrV�.rrI)r�openZ	read_filer�exitZoptionr`rr�OSError�IOErrorr_r4r[rr\rNZskip_pluginsrVr=)
rrdZ	componentrera�f�err�erRr
rrcr�update_from_conf�s4	#
����

zSoSOptions.update_from_confTcCs<|jD]0}t||�sqt||�dk	s(|s|�||d�qdS)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�merge�s
	

zSoSOptions.mergecCs6i}|jD]&}t||�}|r(|dkr(d}|||<q
|S)z�Return this ``SoSOptions`` option values as a dictionary of
            argument name to value mappings.

            :returns: a name:value dictionary of option values.
        �Z
add_presetZ
del_presetZdescZnoteN)r#r)rZ
preset_filterrbr$�valuerrrr!s


zSoSOptions.dictcsL�fdd���fdd��dd��t�����dd�d	�}��fd
d�|D�S)z�Return command arguments for this object.

            Return a list of the non-default options of this ``SoSOptions``
            object in ``sosreport`` command line argument notation:

                ``["--all-logs", "-vvv"]``

        csLd}|r||krdS|dkr$|r$dS|�jkrHt|�t�j|�krHdSdS)z. Test for non-null option values.
            )�False�Nonez[]z""z''�0FrVT)r:r.)rWrsZnull_valuesr(rr�	has_value!s
z%SoSOptions.to_args.<locals>.has_valuecs*|dkrdS|dkr |dkr dS�||�S)z8 Filter out preset and null-valued options.
            rrF)Zlog_sizeZplugin_timeoutZcmd_timeoutrTr)rWrs)rwrr�
filter_opt.s�z&SoSOptions.to_args.<locals>.filter_optcSsz|�d�rdt|�d}|S|�dd�}t|�r<d�|�n|}|dk	rVd||f}n|}t|�dkrnd	|nd|}|S)
zD Convert sos option notation to command line arguments.
            rUrXr-rYr*Tz%s %srfrH)�
startswithrKr^r
r+�len)rWrsr$rrrr�argify9s
z"SoSOptions.to_args.<locals>.argifycSs|dS)Nrr)�xrrr�<lambda>M�z$SoSOptions.to_args.<locals>.<lambda>)rRcs$g|]\}}�||�r�||��qSrr)r'�nr-)r{rxrrr)Ns
z&SoSOptions.to_args.<locals>.<listcomp>)�sortedr!r\)rZ	opt_itemsr)r{rxrwrr�to_argss
	
zSoSOptions.to_argsN)Fr&rr)T)T)�__name__�
__module__�__qualname__rr%r6r7r9r?�classmethodrArMrTrprqr!r�rrrrrs

D

rc@seZdZdZddd�ZdS)�
SosListOptionz0Allow to specify comma delimited list of pluginsNcCsBdd�|�d�D�}t||j�r0|t||j�7}t||j|�dS)NcSsg|]}|�qSrr)r'rrrrr)Vsz*SosListOption.__call__.<locals>.<listcomp>r*)rNr�destr)r�parser�	namespace�valuesZ
option_stringr\rrr�__call__UszSosListOption.__call__)N)r�r�r��__doc__r�rrrrr�Qsr�c@seZdZdZddd�ZdS)�
ClusterOptionz6Used to store/manipulate options for cluster profiles.NcCs"||_||_||_||_||_dSr)rWrs�opt_type�cluster�description)rrWrsr�r�r�rrrr?_s
zClusterOption.__init__)N)r�r�r�r�r?rrrrr�\sr�N)�argparser�configparserrrrrr
rrr�r�rrrr�<module>	s
4