HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sos/__pycache__/options.cpython-38.pyc
U

-�_g�2�@sXddlmZddlmZdd�Zdd�ZGdd�d�ZGd	d
�d
e�ZGdd�d�Zd
S)�)�Action)�ConfigParsercCst|�}|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_seq
sr
cCs$|��}|dkrdS|dkr dSdS)N)�trueZonZyesT)ZfalseZoffZnoF)�lower)rZ_valrrr	�str_to_boolsr
c@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)rrrr	�_unset sz%SoSOptions._merge_opt.<locals>._unset)�hasattr�getattr�_nondefaultr
�setattr�discard�add)�self�opt�src�
is_defaultrZnewvalueZoldvaluerrr	�
_merge_opts"


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

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>Lsz$SoSOptions.__str.<locals>.<listcomp>cSs"g|]}t|�rd�|�n|�qS)�,)r
�join�r$�vrrr	r&OscSs&g|]}t|t�rd|�d�n|�qS)�')r�strr)rrr	r&Rs)r �stripr)	r�quote�sep�prefix�suffix�argsZarg_fmtr!Zvalsrr%r	Z__str=s	

zSoSOptions.__strcCs|��Sr��_SoSOptions__strr%rrr	�__str__VszSoSOptions.__str__cCs|jddddd�S)NTz, zSoSOptions(�))r.r/r0r1r3r%rrr	�__repr__Ys
�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�items�append)rr8�kwargsr!Zkwargrrr	�__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
        r8T)rrr")�clsr2r8Zoptsrrr	�	from_argsus	zSoSOptions.from_argscsRd}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�--csg|]}d����qS)rDr)r$�d�rrr	r&�sz+SoSOptions._opt_to_args.<locals>.<listcomp>r�=)�range�int)r?rrZno_value�countrrFr	�_opt_to_args�szSoSOptions._opt_to_argscCs�t|j|t|��r|St|j|t�r6t|�d��St|j|t�rpt|�}|dkrltd|�d|�d���|St|j|t�r�t|�S|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
        r'Nz
Value of 'z' in z# must be True or False or analagous)	rr8rr�split�boolr
�	ExceptionrI)r�keyr�confrrr	�_convert_to_type�s
�zSoSOptions._convert_to_typec	
s���fdd�}t�}z(t�dd��}|�|��W5QRXWn<tk
rx}ztd��d|jd���W5d}~XYnX|d	|�|||�|�d
�r�t�d�r�|�d
�D]0\}}|�	d�d
�j
kr��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]b\}}t|t	�r�|d	kr�|�d
d�}|�j
kr�td|�d
|�d��q���||��}t
�||�q�dS)NrC�	verbosityZlabel�plugoptsZprofiles)�nameZ
plugin_optionZprofile�-�_�keywordsr#rzUnknown option 'z' in section 'r+)�has_sectionrr;r9rI�popr�replacerr,r8�printrQr)Zsection�config�odictZrename_optsrOr��config_filerrr	�_update_from_section�s*
�
z9SoSOptions.update_from_conf.<locals>._update_from_sectionzutf-8)�encodingz+WARNING: Unable to read configuration file z : �N�globalZplugin_optionsrS�.rrG)
r�openZ	read_file�OSErrorr[r2rXrr;rLZskip_pluginsrSr<)	rr_Z	componentr`r\�f�erOrrr^r	�update_from_conf�s	"�

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_filterr]r!�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 ``sos report`` 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''�0FrST)r8r,)rTrlZnull_valuesr%rr	�	has_values
z%SoSOptions.to_args.<locals>.has_valuecs*|dkrdS|dkr |dkr dS�||�S)z8 Filter out preset and null-valued options.
            rkF)Zlog_sizeZplugin_timeoutZcmd_timeoutrTr)rTrl)rprr	�
filter_opt s�z&SoSOptions.to_args.<locals>.filter_optcSs||�d�rdt|�d}|S|�dd�}t|�r<d�|�n|}|dk	rX|�d|��}n|}t|�dkrpd	|nd|}|S)
zD Convert sos option notation to command line arguments.
            rRrUr*rVr'Tr#rbrD)�
startswithrIrZr
r(�len)rTrlr!rrrr	�argify+s
z"SoSOptions.to_args.<locals>.argifycSs|dS)Nrr)�xrrr	�<lambda>?�z$SoSOptions.to_args.<locals>.<lambda>)rOcs$g|]\}}�||�r�||��qSrr)r$�nr*)rtrqrr	r&@s
z&SoSOptions.to_args.<locals>.<listcomp>)�sortedrr;)rZ	opt_itemsr)rtrqrprr	�to_args
s
	
zSoSOptions.to_argsN)Fr#rr)T)T)�__name__�
__module__�__qualname__rr"r4r5r7r>�classmethodr@rKrQrirjrrzrrrr	rs

=

rc@seZdZdZddd�ZdS)�
SosListOptionz0Allow to specify comma delimited list of pluginsNcCs<t|�d��}t||j�r*|t||j�7}t||j|�dS)Nr')rrLr�destr)r�parser�	namespace�valuesZ
option_stringr;rrr	�__call__GszSosListOption.__call__)N)r{r|r}�__doc__r�rrrr	rCsrc@seZdZdZddd�ZdS)�
ClusterOptionz6Used to store/manipulate options for cluster profiles.NcCs"||_||_||_||_||_dSr)rTrl�opt_type�cluster�description)rrTrlr�r�r�rrr	r>Qs
zClusterOption.__init__)N)r{r|r}r�r>rrrr	r�Nsr�N)	�argparser�configparserrr
r
rrr�rrrr	�<module>	s	(