o
    G%@ig                      @   sj   d Z dZddlZddlZddlZddlmZ ddlmZ dZ	dZ
ee
e	 dd	 ZeZG d
d dZdS )zu
This module houses the i18n setup and message function. The default is to use
gettext to internationalize messages.
z4.10.2    N)ArgumentParser)SosListOptionz/usr/share/localesosc                 C   s   t t| S N)gettextdgettextgettext_app)msg r
   ./usr/lib/python3/dist-packages/sos/__init__.py_default   s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )SoSaR  Main entrypoint for sos from the command line

    Upon intialization, this class loads the basic option parser which will
    include the options shared by support components/subcommands. This is also
    where all subcommands present in the local installation are discovered,
    loaded, and if a matching one is found, intialized.
    c              
   C   s  || _ dd l}dd l}dd l}dd l}|jjdgf|jjddgf|j	j
g f|jjg fd| _zdd l}|jjdgf| jd< W n9 tyw } z-dd l}dt|jv r[|jjg f| jd< nd	t|jv rl|jjg f| jd< n W Y d }~nd }~ww d
}| j D ]#\}}|d }|d| d|}|d j}	|d|d|	 d7 }qd}
|
| }
d}t|
|d| _| jddt | jj dddd| _!d| j!_"| j D ]3\}}| j!j#||d d| d}d| d|_$|ddt | %| |d j&|d |j'|d q| j(| j | _)| *  d S )Nr   repcleanermask)reportcleanhelpupload	collectorcollectzsos.collectorpexpect    z, 	z<30
z6%(prog)s <component> [options]

Available components:
z1See `sos <component> --help` for more information)usageepilogactionextend	componentzsos component to run)destmetavarr   Tzsos )aliasesprogz
 [options])parser)r    )+cmdline
sos.reportsos.cleanersos.help
sos.uploadr   	SoSReportr   
SoSCleanerr   	SoSHelperr   	SoSUpload_componentssos.collectorr   SoSCollectorModuleNotFoundErrorsos.missingstrr	   missingMissingCollectMissingPexpectitemsinsertjoindescr   r%   registerr   add_subparsers
subparsersrequired
add_parserr   _add_common_optionsadd_parser_optionsset_defaults
parse_argsargs_init_component)selfrE   r   err_com_stringcomvaluer#   _comr;   usage_stringr   comp_com_subparserr
   r
   r   __init__/   sn   

	


zSoS.__init__c              	   C   s  | d}|jddddd |jdtdd	d
dd |jddddd |jddddddd |jddddddd |jdddddd |jdddd d!td"d# |jd$d%d&d'd(d)d |jd*d+d,g d-d.d/ | }|jd0ddd1d |jd2d3d4 |jd5d6d4 dS )7z@Adds the options shared across components to the parser
        zGlobal Optionsz--batchF
store_truezDo not prompt interactively)defaultr   r   z--config-filestoreconfig_filez/etc/sos/sos.confz$specify alternate configuration file)typer   r!   rR   r   z--debugdebugz6enable interactive debugging using the python debugger)r   r!   r   z-qz--quietquietzonly print fatal errors)r   r!   rR   r   z-sz	--sysrootsysrootNz!system rootdir path (default='/')z	--tmp-dirtmp_dirz%specify alternate temporary directoryz-tz	--threadsthreads   zNumber of threads to use)r   r!   rR   rU   r   z-vz	--verbosecount	verbosityr   zincrease verbosityz-zz--compression-typecompression_type)autogzipxzzcompression technology to use)r!   choicesr   z	--encryptz_Encrypt the archive, either prompting for a password/key or referencing an environment variablez--encrypt-keyz(Encrypt the archive using a GPG key-pair)r   z--encrypt-passz$Encrypt the archive using a password)add_argument_groupadd_argumentr4   intadd_mutually_exclusive_group)rG   r%   
global_grpencrypt_grpr
   r
   r   rA   x   s`   









zSoS._add_common_optionsc              
   C   s   | j j}|| jvrtd| d z!| j| d }|jr&t dks&td|| j| j | j	| _
W dS  tyZ } ztd| d|  | j jrJ|td W Y d}~dS d}~ww )	znDetermine which component has been requested by the user, and then
        initialize that component.
        zUnknown subcommand 'z' specifiedr   z*Component must be run with root privilegeszCould not initialize 'z': r   N)rE   r    r/   printroot_requiredosgetuid	Exceptionr%   r&   
_componentrV   sysexit)rG   rL   _to_loadrH   r
   r
   r   rF      s   
zSoS._init_componentc                 C   s   | j   d S r   )rn   execute)rG   r
   r
   r   rr      s   zSoS.executeN)__name__
__module____qualname____doc__rP   rA   rF   rr   r
   r
   r
   r   r   &   s    I/r   )rv   __version__rk   ro   r   argparser   sos.optionsr   gettext_dirr   bindtextdomainr   _sosr   r
   r
   r
   r   <module>   s   