
    id,5                     r    d dl mZ d dlmZmZmZmZ d Zd Z G d d      Z	 G d de      Z
 G d	 d
      Zy)    )Action)ConfigParserParsingErrorErrorDuplicateOptionErrorc                 <    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                 p   d }t        ||      rt        ||      }t        | |      } ||      r ||      r|s|| j                  vrRt        |      sGt	        | ||       |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_defaultr!   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+   args       r   _merge_optszSoSOptions._merge_opts9   s8    #t$s)C>> 	2COOCj1	2r   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|	z  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,z'%s')r4   stripr#   r   joinr1   strr   )
r(   quotesepprefixsuffixargsarg_fmtr5   valsvs
             r   __strzSoSOptions.__str?   s     >> 	(CC'MC''D	(

3.2nn=sc"==>BC71:CHHQK14CDC FJJ*Q"4FQJ!;JDJuT{"))#.77 > D Ks    C%CCc                 "    | j                         S r0   _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?   rF   rH   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
   keysr4   setr$   r%   append)r(   rN   kwargsr5   s       r   __init__zSoSOptions.__init___   s     )l//125$$ 	7CD#t0056	7 ;;= 	,CNN!!#&D#vc{+	,r   c                 Z    t        di t        |      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
        rN   Tr    )r   r3   r6   )clsr@   rN   optss       r   	from_argszSoSOptions.from_argsw   s/     BDJB\Bt$r   c                     d}d}||v rd|z  gS ||v r&t        dt        |            D cg c]  }d|z  	 c}S d|z   dz   |z   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)verbosez--%sr   --=)rangeint)rU   r)   r   no_valuecountds         r   _opt_to_argszSoSOptions._opt_to_args   sf    

 (?SL>!%<*/3s8*<=QFSL==s
S 3&'' >s   Ac                    t        | j                  |   t        |            r|S t        | j                  |   t              r|j	                  d      D cg c]  }| c}S t        | j                  |   t
              r!t        |      }|t        d|d|d      |S t        | j                  |   t              r	 t        |      S |S c c}w # t        $ r t        d|d|d      w xY w)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
        r8   z
Value of 'z' in z# must be True or False or analagousz must be integer)
r1   rN   r	   r
   splitboolr   	Exceptionrd   
ValueError)r(   keyr   confrC   s        r   _convert_to_typezSoSOptions._convert_to_type   s     d'',d3i8Jd'',d3"yy~.!A..d'',d3c"C{D"# # 
d'',c2/3x 
 /  /#&!. / //s   	C
=
C C+c           	           fd}t               }	 	 t              5 }|j                  |       ddd        |d
|        |||       |j                  d      rit         d      r\|j                  d      D ]G  \  }}	|j!                  d      d    j"                  vs' j$                  j'                  |dz   |	z          I yyy# 1 sw Y   xY w# t        $ r-}t	        d|j
                  d|j                  d      d}~wt        t        f$ r t	        dz        w xY w# t        t        f$ 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 )Nr`   	verbositylabelplugoptsprofiles)nameplugin_optionprofile-_keywords r   zUnknown option '' in section '')has_sectionr2   itemsrO   rd   popr
   replacer1   r;   rN   printrp   r%   )sectionconfigodictrename_optsrn   r   config_filer(   s         r   _update_from_sectionz9SoSOptions.update_from_conf.<locals>._update_from_section   s>   !!'*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 !$g/ 0 //S+FCD#s+,' +r   NzDuplicate option 'r~   z
' in file z%Failed to parse configuration file %sz+WARNING: Unable to read configuration file z :    globalplugin_optionsru   .r   rb   )r   open	read_filer   exitoptionr   r   r   OSErrorIOErrorr   r@   r   r"   r   rj   skip_pluginsru   rQ   )
r(   r   	componentr   r   ferrern   r   s
   ``        r   update_from_confzSoSOptions.update_from_conf   sb   !	,F 	*+& 5!$$Q45 	Xv.Y/./GD*4M"LL)9: :Syy~a(D,=,==MM((sS9: 5N/!5 5' E!jj#++{D E E %( *B() * ** ! 	q	+ 	sE   C CC CC 	D&(D!D&&D) )E!8EE!c                     | j                   D ]1  }t        ||      st        ||      |r| j                  ||d       3 y)aN  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.
        NF)r4   r"   r#   r.   )r(   r*   skip_defaultr5   s       r   mergezSoSOptions.merge   sC     >> 	1C3$sC ,LS%0		1r   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)r4   r#   )r(   preset_filterr   r5   values        r   r2   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 ``sosreport`` 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)rN   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   rC   r{   r8   Tr}   r   ra   )
startswithrd   r   r   r:   len)rw   r   r5   r)   s       r   argifyz"SoSOptions.to_args.<locals>.argify9  s     {+CJ,,
<<S)D'.u~CHHUO5ED !%u- #C1$*CJ 36)CJr   c                     | d   S )Nr   r    )xs    r   <lambda>z$SoSOptions.to_args.<locals>.<lambda>M  s
    ad r   )rn   )sortedr2   r   )r(   r   r   	opt_itemsnrC   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   )T)__name__
__module____qualname__r.   r6   rG   rI   rL   rS   classmethodrW   rh   rp   r   r   r2   r   r    r   r   r   r      sl    80282& %' ,0 *, 
 
 ( ($<B:H1 6Jr   r   c                       e Zd ZdZddZy)SosListOptionz0Allow to specify comma delimited list of pluginsNc                     |j                  d      D cg c]  }| }}t        || j                        r|t        || j                        z  }t        || j                  |       y c c}w )Nr8   )rj   r#   destr%   )r(   parser	namespacevaluesoption_stringr)   r   s          r   __call__zSosListOption.__call__U  sV     &S 12229dii(WY		22E	499e, 3s   	A&r0   )r   r   r   __doc__r   r    r   r   r   r   Q  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 r0   )rw   r   opt_typeclusterdescription)r(   rw   r   r   r   r   s         r   rS   zClusterOption.__init___  s&    	
 &r   r0   )r   r   r   r   rS   r    r   r   r   r   \  s
    @'r   r   N)argparser   configparserr   r   r   r   r   r   r   r   r   r    r   r   <module>r      sC    0 01oJ oJd	-F -' 'r   