
    G%@i3                     f    d dl mZ d dlmZ d Zd Z G d d      Z G d de      Z G d	 d
      Zy)    )Action)ConfigParserc                 <    t        |       }|t        u xs |t        u S )z@Return true if val is an instance of a known sequence type.
    )typelisttuple)valval_types     -/usr/lib/python3/dist-packages/sos/options.py_is_seqr      s"     CyHt0x500    c                 8    | j                         }|dv ry|dv ryy )N)trueonyesT)falseoffnoF)lower)r	   _vals     r   str_to_boolr      s(    99;D$$%%r   c                   |    e Zd Zd Zd ZddZd Zd Zi fdZe	i fd       Z
e	d        Zd	 Zd
 ZddZddZd Zy)
SoSOptionsc                 t   d }t        ||      rt        ||      }t        | |      } ||      r ||      r|s|| j                  vrt        |      r|rGt	        | ||       |r| j                  j                  |       y | j                  j                  |       y t        |      rt	        | |||z          y y y )Nc                     | dk(  xs | d u S )N  )r	   s    r   _unsetz%SoSOptions._merge_opt.<locals>._unset    s    2I,-r   )hasattrgetattr_nondefaultr   setattrdiscardadd)selfoptsrc
is_default
prefer_newr   newvalueoldvalues           r   
_merge_optzSoSOptions._merge_opt   s    	. 3sC(HtS)H x )9D,,,wx7Hc8,$$,,S1$$((-"c8h#67 #% r   c                     t        |t              st        |      }| j                  D ]  }| j	                  ||||        y N)
isinstancedictvars	arg_namesr,   )r%   r'   r(   r)   args        r   _merge_optszSoSOptions._merge_opts9   s:    #t$s)C>> 	>COOCj*=	>r   c                    |}d}| j                   D ]  }|||z   |z   z  } |j                  |       | j                   D cg c]  }t        | |       }}|s,|D 	cg c]   }	t        |	      rdj	                  |	      n|	" }}	n%|D 	cg c]  }	t        |	t              rd|	 dn|	 }}	|t        |      z  j                  |      |z   S c c}w c c}	w c c}	w )aI  Format 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=%s,')r2   stripr    r   joinr/   strr   )
r%   quotesepprefixsuffixargsarg_fmtr3   valsvs
             r   __strzSoSOptions.__str?   s     >> 	(CC'MC''D	(

3.2nn=sc"==>BC71:CHHQK14CDC DHHa
1c 2as!H9HDHuT{"))#.77 > D Is    C%CCc                 "    | j                         S r.   _SoSOptions__strr%   s    r   __str__zSoSOptions.__str__X   s    zz|r   c                 ,    | j                  dddd      S )NTz, zSoSOptions())r;   r<   r=   r>   rE   rG   s    r   __repr__zSoSOptions.__repr__[   s!    zz$}!$  & 	&r   c                 B   || _         t        |j                               | _        t	               | _        | j                   D ]  }t        | || j                   |           |j                         D ]-  \  }}| j                  j                  |       t        | ||       / y)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   keysr2   setr!   r"   itemsappend)r%   rM   kwargsr3   kwargs        r   __init__zSoSOptions.__init___   s     )l//125$$ 	7CD#t0056	7 !,,. 	&JCNN!!#&D#u%	&r   c                 \    t        di t        |      d|i}|j                  |d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
        rM   TFr   )r   r1   r4   )clsr?   rM   optss       r   	from_argszSoSOptions.from_argsw   s1     BDJB\BtU+r   c                     d}d}||v rd| gS ||v r&t        dt        |            D cg c]  }d| 	 c}S d| d| gS c c}w )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).
        )
alloptionszallow-system-changeszall-logsbatchbuilddebugexperimentalzlist-pluginszlist-presetszlist-profilesz	no-reportzno-env-varsquietverify)verbose--r   =)rangeint)rV   r&   r	   no_valuecountds         r   _opt_to_argszSoSOptions._opt_to_args   si    

 (?J<%<(-aS(:;1bJ;;SE3% !! <s   Ac                    t        | j                  |   t        |            r|S t        | j                  |   t              rt        |j	                  d            S t        | j                  |   t
              r!t        |      }|t        d| d| d      |S t        | 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
        r6   z
Value of 'z' in z# must be True or False or analagous)	r/   rM   r   r   splitboolr   	Exceptionre   )r%   keyr	   confs       r   _convert_to_typezSoSOptions._convert_to_type   s     d'',d3i8Jd'',d3		#''d'',d3c"C{ U4& 1   ! ! Jd'',c2s8O
r   c                 ,     fd}t               }	 t        d      5 }|j                  |       ddd        |d|        |||       |j                  d	      rvt         d
      rit         d      r\|j                  d	      D ]G  \  }}|j                  d      d    j                  vs' j                  j                  |dz   |z          I yyyy# 1 sw Y   xY w# t        $ r(}t	        d d|j
                  d           Y d}~d}~ww xY w)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
        c                 r   |j                  |       r$t        |j                  |             }d|j                         v rt	        |j                  d            |d<   dddd}t        |      D ]F  }d|v r$|j                  |      ||j                  dd      <   ||v s0|j                  |      |||   <   H |j                         D ]m  \  }}t        |t              r|d	k7  r|j                  d
d      }|j                  vrt        d| d|  d       Nj                  ||      }t        ||       o y y )Nra   	verbositylabelplugoptsprofiles)nameplugin_optionprofile-_keywords r   zUnknown option 'z' in section 'r7   )has_sectionr0   rP   rN   re   popr   replacer/   r:   rM   printrp   r"   )sectionconfigodictrename_optsrn   r	   config_filer%   s         r   _update_from_sectionz9SoSOptions.update_from_conf.<locals>._update_from_section   sD   !!'*V\\'23

,),UYYy-A)BE+&
 $%/)
  ; ACcz7<yy~ckk#s34k)27))C.k#./	A !& ,HC "#s+z0A!kk#r2$"3"33  0^G9ANO //S+FCD#s+,' +r   zutf-8)encodingNz+WARNING: Unable to read configuration file z :    globalplugin_optionsru   skip_plugins.r   rc   )r   open	read_fileOSErrorr   r?   r~   r   rP   rk   r   ru   rQ   )	r%   r   	componentr   r   fern   r	   s	   ``       r   update_from_confzSoSOptions.update_from_conf   s    	,D 	kG4 1  K01 	Xv.Y/./GD*4MD.1"LL)9: :Syy~a(D,=,==MM((sS9: 2 5N/1 1 	=k]#66!9+ 	s-   C" CC" CC" "	D+DDc                     | j                   D ]3  }t        ||      st        ||      |r| j                  ||d|       5 y)a  Merge 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.
            :param prefer_new: ``False`` if new default is not preferred.
        NF)r)   )r2   r   r    r,   )r%   r'   skip_defaultr)   r3   s        r   mergezSoSOptions.merge   sI     >> 	HC3$sC ,LS%JG		Hr   c                 ^    i }| j                   D ]  }t        | |      }|r|dv rd}|||<    |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_presetdescnoteN)r2   r    )r%   preset_filterr   r3   values        r   r0   zSoSOptions.dict   sI     >> 	CD#&EFF EE#J	 r   c                       fdfd}d }t         j                         j                         d       }|D cg c]  \  }} |||      s |||       c}}S c c}}w )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"]``

        c                     d}|r||v ry| dk(  r|ry| j                   v r%t        |      t        j                   |          k(  ryy)z. Test for non-null option values.
            )FalseNonez[]z""z''0Fru   T)rM   r:   )rw   r   null_valuesr%   s      r   	has_valuez%SoSOptions.to_args.<locals>.has_value  sU     CKE[0z!et(((u:T%6%6t%<!== r   c                 4    | dv ry| dv r|dk(  ry | |      S )z8 Filter out preset and null-valued options.
            r   F)log_sizeplugin_timeoutcmd_timeoutr   Tr   )rw   r   r   s     r   
filter_optz&SoSOptions.to_args.<locals>.filter_opt$  s1     CCDDA:T5))r   c                     | j                  d      rdt        |      dz  z   }|S | j                  dd      } t        |      rdj	                  |      n|}|dur|  d| }n| }t        |      dkD  rd	|z   }|S d|z   }|S )
zD Convert sos option notation to command line arguments.
            rs   rz   rB   r{   r6   Tr}   r   rb   )
startswithre   r   r   r9   len)rw   r   r3   r&   s       r   argifyz"SoSOptions.to_args.<locals>.argify/  s     {+CJ,,
<<S)D'.u~CHHUO5ED aw' #C1$*CJ 36)CJr   c                     | d   S )Nr   r   )xs    r   <lambda>z$SoSOptions.to_args.<locals>.<lambda>C  s
    ad r   )rn   )sortedr0   rP   )r%   r   r   	opt_itemsnrB   r   s   `     @r   to_argszSoSOptions.to_args  sV    			*	( 499;,,.NC	+4I!Q
1a8Hq!IIIs   A A N)Fr}   r   r   )TF)T)__name__
__module____qualname__r,   r4   rF   rH   rK   rT   classmethodrX   ri   rp   r   r   r0   r   r   r   r   r   r      sl    84>82& %' &0 *, 
 
 " "$2<:|H  6Jr   r   c                       e Zd ZdZddZy)SosListOptionz0Allow to specify comma delimited list of pluginsNc                     t        |j                  d            }t        || j                        r|t        || j                        z  }t	        || j                  |       y )Nr6   )r   rk   r    destr"   )r%   parser	namespacevaluesoption_stringrP   s         r   __call__zSosListOption.__call__K  sH    V\\#&'9dii(WY		22E	499e,r   r.   )r   r   r   __doc__r   r   r   r   r   r   G  s
    :-r   r   c                       e Zd ZdZddZy)ClusterOptionz6Used to store/manipulate options for cluster profiles.Nc                 J    || _         || _        || _        || _        || _        y r.   )rw   r   opt_typeclusterdescription)r%   rw   r   r   r   r   s         r   rT   zClusterOption.__init__U  s&    	
 &r   r.   )r   r   r   r   rT   r   r   r   r   r   R  s
    @'r   r   N)	argparser   configparserr   r   r   r   r   r   r   r   r   <module>r      s<     %1gJ gJT	-F -' 'r   