o
    Û1j !  ã                   @   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.11.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   s6  || _ 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t!› �d� | 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Úextendz	--versionÚversionzsos version )r   r    Ú	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_argumentÚ__version__Úadd_subparsersÚ
subparsersÚrequiredÚ
add_parserr   Ú_add_common_optionsÚadd_parser_optionsÚset_defaultsÚ
parse_argsÚargsÚ_init_component)ÚselfrH   r   ÚerrÚ_com_stringÚcomÚvaluer$   Ú_comr<   Úusage_stringr   ÚcompÚ_com_subparserr
   r
   r   Ú__init__/   sv   

ü	ÿ€ö

þýý
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"   rU   r   z--debugÚdebugz6enable interactive debugging using the python debugger)r   r"   r   z-qz--quietÚquietzonly print fatal errors)r   r"   rU   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"   rU   rX   r   z-vz	--verboseÚcountÚ	verbosityr   zincrease verbosityz-zz--compression-typeÚcompression_type)ÚautoÚgzipÚxzÚnonez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_groupr>   r5   ÚintÚadd_mutually_exclusive_group)rJ   r&   Ú
global_grpÚencrypt_grpr
   r
   r   rD   |   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)rH   r!   r0   ÚprintÚroot_requiredÚosÚgetuidÚ	Exceptionr&   r'   Ú
_componentrY   ÚsysÚexit)rJ   rO   Ú_to_loadrK   r
   r
   r   rI   ¬   s   
€üzSoS._init_componentc                 C   s   | j  ¡  d S r   )rq   Úexecute)rJ   r
   r
   r   ru   ¿   s   zSoS.executeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rS   rD   rI   ru   r
   r
   r
   r   r   &   s    M0r   )ry   r?   rn   rr   r   Úargparser   Úsos.optionsr   Úgettext_dirr   Úbindtextdomainr   Ú_sosr   r
   r
   r
   r   Ú<module>   s   