o
    *b                     @   s   d Z dZddlZddlZddlmZ ddlmZ ddlZdZ	dZ
ee
e	 dd	 ZeZze W n ey;   eZY nw 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.3    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}|jjdgf|jjddgf|jj	g fd| _
zdd l}|jjdgf| j
d< W n5 tyj } z)dd l}d|jv rP|jjg f| j
d< nd	|jv r_|jjg f| j
d< n W Y d }~nd }~ww d
}| j
D ]%}| j
| d }|d| d|}| j
| d j}|dj||d7 }qpd}	|	| }	d}
t|	|
d| _| jddt | jjdddd| _d| j_| j
D ]4}| jj|| j
| d d| d}d| |_ |ddt | !| | j
| d j"|d |j#|d q| j$| j | _%| &  d S )Nr   Zrepcleanermask)reportZcleanhelp	collectorZcollectzsos.collectorZpexpect    z, z	{com:<30}{desc}
)comdescz6%(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 %s)aliasesprogzsos %s [options])parser)r   )'cmdlineZ
sos.reportZsos.cleanerZsos.helpr   Z	SoSReportr   Z
SoSCleanerr   Z	SoSHelper_componentsZsos.collectorr   ZSoSCollectorModuleNotFoundErrorZsos.missingr	   missingZMissingCollectZMissingPexpectinsertjoinr   formatr   r    registerr   add_subparsersZ
subparsersrequired
add_parserr   _add_common_optionsZadd_parser_optionsset_defaults
parse_argsargs_init_component)selfr/   r   errZ_com_stringr   r   _comr   Zusage_stringr   compZ_com_subparserr
   r
   r   __init__5   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d0d1d2 |jd3d4d2 dS )5z@Adds the options shared across components to the parser
        zGlobal Optionsz--batchF
store_truezDo not prompt interactively)defaultr   r   z--config-filestoreZconfig_filez/etc/sos/sos.confz$specify alternate configuration file)typer   r   r7   r   z--debugdebugz6enable interactive debugging using the python debugger)r   r   r   z-qz--quietquietzonly print fatal errors)r   r   r7   r   z-sz	--sysrootZsysrootNz!system rootdir path (default='/')z	--tmp-dirZtmp_dirz%specify alternate temporary directoryz-tz	--threadsZthreads   zNumber of threads to use)r   r   r7   r9   r   z-vz	--verbosecount	verbosityr   zincrease verbosityz-zz--compression-typeZcompression_type)autogzipxzzcompression technology to use)r   choicesr   z--encrypt-keyz(Encrypt the archive using a GPG key-pair)r   z--encrypt-passz$Encrypt the archive using a password)add_argument_groupadd_argumentstrintadd_mutually_exclusive_group)r1   r    Z
global_grpZencrypt_grpr
   r
   r   r,   ~   sX   









zSoS._add_common_optionsc              
   C   s   | j j}|| j vrtd|  z!| j| d }|jr&t dks&td|| j	| j | j
| _W dS  tyX } ztd||f  | j jrH|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 '%s' specifiedr   z*Component must be run with root privilegeszCould not initialize '%s': %sr   N)r/   r   r"   keysprintZroot_requiredosgetuid	Exceptionr    r!   
_componentr:   sysexit)r1   r3   Z_to_loadr2   r
   r
   r   r0      s   zSoS._init_componentc                 C   s   | j   d S r   )rM   execute)r1   r
   r
   r   rP      s   zSoS.executeN)__name__
__module____qualname____doc__r5   r,   r0   rP   r
   r
   r
   r   r   ,   s    I*r   )rT   __version__rJ   rN   argparser   Zsos.optionsr   r   Zgettext_dirr   bindtextdomainr   Z_sosr#   	NameErrorImportErrorr   r
   r
   r
   r   <module>   s$   