U
    id                      @   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k
rx   eZY nX 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.5.6    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 nh tk
r } zJdd l}d|jkr|jjg f| j
d< n d	|jkr|jjg f| j
d< n W 5 d }~X Y nX d
}| j
D ]J}| j
| d }|d| d|}| j
| d j}|dj||d7 }qd}	|	| }	d}
t|	|
d| _| jddt | jjdddd| _d| j_| j
D ]j}| jj|| j
| d d| d}d| |_ |ddt | !| | j
| d j"|d |j#|d qz| 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	   ZmissingZMissingCollectZMissingPexpectinsertjoinr   formatr   r    registerr   Zadd_subparsersZ
subparsersZrequiredZ
add_parserr   _add_common_optionsZadd_parser_optionsZset_defaults
parse_argsargs_init_component)selfr*   r   errZ_com_stringr   r   _comr   Zusage_stringr   compZ_com_subparserr
   r
   r   __init__5   sj    







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,d-d.d/gd0d1 | }|jd2ddd3d |jd4d5d6 |jd7d8d6 dS )9z@Adds the options shared across components to the parser
        zGlobal Optionsz--batchF
store_truezDo not prompt interactively)defaultr   r   z--config-fileZstoreZconfig_filez/etc/sos/sos.confz$specify alternate configuration file)typer   r   r2   r   z--debugdebugz6enable interactive debugging using the python debugger)r   r   r   z-qz--quietquietzonly print fatal errors)r   r   r2   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   r2   r3   r   z-vz	--verbosecount	verbosityr   zincrease verbosityz-zz--compression-typeZcompression_typeautoZgzipZ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)Zadd_argument_groupadd_argumentstrintZadd_mutually_exclusive_group)r,   r    Z
global_grpZencrypt_grpr
   r
   r   r(   ~   sj    




 
 

  
 zSoS._add_common_optionsc              
   C   s   | j j}|| j kr"td|  z@| j| d }|jrLt dksLtd|| j	| j | j
| _W nH tk
r } z*td||f  | j jr|td W 5 d}~X Y nX dS )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!   
_componentr4   sysexit)r,   r.   Z_to_loadr-   r
   r
   r   r+      s    zSoS._init_componentc                 C   s   | j   d S r   )rC   execute)r,   r
   r
   r   rF      s    zSoS.executeN)__name__
__module____qualname____doc__r0   r(   r+   rF   r
   r
   r
   r   r   ,   s
   I/r   )rJ   __version__r@   rD   argparser   Zsos.optionsr   r   Zgettext_dirr   bindtextdomainr   Z_sosr#   	NameErrorImportErrorr   r
   r
   r
   r   <module>   s    
