%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/__pycache__/component.cpython-312.pyc

�

i��d�F����ddlZddlZddlZddlZddlZddlZddlmZddlmZddl	m	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZmZGd�d�ZGd
�d�Zy)�N)�SUPPRESS)�datetime)�getpass)�rmtree)�Path)�__version__)�TarFileArchive)�
SoSOptions)�TempFileUtil�	shell_outc
��eZdZdZdZiZdZdZdZdZ	dddddddddd	dd
d�Z
d�Zd
�Zd�Z
d�Zdd�Zd�Zd�Zed��Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zy) �SoSComponenta�Any sub-command that sos supports needs to subclass SoSComponent in
    order to be properly supported by the sos binary.

    This class contains the standardized entrypoint for subcommands, as well as
    building out supported options from both globally shared option lists, and
    options supported by that specific subcommand.

    When sos initializes, it will load an unintialized instance of each class
    found within one recursion of the module root directory that subclasses
    SoSComponent.

    If sos is able to match the user-specified subcommand to one that exists
    locally, then that SoSComponent is initialized, logging is setup, and a
    policy is loaded. From there, the component's execute() method takes over.

    Added in 4.0
    �unsetTF�autoz/etc/sos/sos.confN��r)�batch�compression_type�config_file�debug�encrypt�encrypt_key�encrypt_pass�quiet�threads�tmp_dir�sysroot�	verbosityc��||_||_||_d|_d|_d|_d|_d|_	ddl}|j|j|j��|jj|j�|j�|_|j"r�|j%�}t'�|_t(j*j-|�r$t)j.|t(j0�s:d|z}|dz
}t2j4j7|�|j9d�||_t=j>d|j:��|_tA|j
�|_|jC�|jDr|jG�|j��o|jjIdtJ�|jjId	d
jM|j��|jjIdtOjP��|jjIdd
�|jjIdd
�|jjIdd
�|jjId|j
�|jjId|jR�|jjId|jTjV�|jjYd�yy#t$rY���wxYw)NFrztemporary directory %s z"does not exist or is not writable
�zsos.)�prefix�dir�version�cmdline� �
start_time�end_timer�run_time�compression�tmpdir�tmpdir_fs_type�policy�
components)-�parser�argsr$�exit_process�archiver*�
tempfile_util�manifest�signal�SIGTERM�get_exit_handler�	Exception�
_arg_defaults�update�arg_defaults�load_options�opts�configure_logging�get_tmpdir_default�SoSMetadata�os�path�isdir�access�W_OK�sys�stderr�write�_exit�sys_tmp�tempfile�mkdtempr�_setup_logging�load_policy�load_local_policy�	add_fieldr�joinr�now�	tmpfstyper,�distro�add_section)�selfr.�parsed_args�cmdline_argsr4r*�msgs       �//usr/lib/python3/dist-packages/sos/component.py�__init__zSoSComponent.__init__Hs_�������	�#���!���������!�����
�	���M�M�&�.�.�$�*?�*?�*A�B�
	
���!�!�$�"3�"3�4��%�%�'��	��!�!��,�,�.�F�'�M�D�M��7�7�=�=��(��9�9�V�R�W�W�5�/�&�8���<�<���
�
� � ��%��
�
�1�
�!�D�L�"�*�*�&�d�l�l�K�D�K�!-�d�k�k�!:�D�����!�����"�"�$��=�=�$��M�M�#�#�I�{�;��M�M�#�#�I�s�x�x����/E�F��M�M�#�#�L�(�,�,�.�A��M�M�#�#�J��3��M�M�#�#�J��3��M�M�#�#�M�2�6��M�M�#�#�H�d�k�k�:��M�M�#�#�$4�d�n�n�E��M�M�#�#�H�d�k�k�.@�.@�A��M�M�%�%�l�3�%��;�	��	�s�.L:�:	M�Mc�B�	ddl}|jj|jj|j
��|_|jj|_|jj�|_
y#t$r|jd�Y�<wxYw)Nr)r�
probe_runtime)�sos.policies�policies�loadr<r�
load_prober,�KeyboardInterruptrH�is_root�_is_root)rU�soss  rYrNzSoSComponent.load_local_policys|��	���,�,�+�+�D�I�I�4E�4E�:>�/�/�,�K�D�K��;�;�.�.�D�L����+�+�-��
��!�	��J�J�q�M�	�s�AB�B�Bc��t��N)�NotImplementedError�rUs rY�executezSoSComponent.execute�s��!�!�c����fd�}|S)Nc�4��d�_�j�y)NT)r0rH)�signum�framerUs  �rY�exit_handlerz3SoSComponent.get_exit_handler.<locals>.exit_handler�s��� $�D���J�J�Lrj�)rUros` rYr6zSoSComponent.get_exit_handler�s���	��rjc��|r6|jjd�|jj|�t|��)Nr)�ui_log�error�
SystemExit)rUrsrXs   rYrHzSoSComponent._exit�s4����K�K���b�!��K�K���c�"����rjc�P�|jjr4tjj	|jj�}ntj
dd�xsd}tj
dd�rXtj
dd�rBtjj
tj
d�|jd��}tdd�d	|���j�|_
|jd
k(r td�tjd�|S)
z�If --tmp-dir is not specified, provide a default location.
        Normally this is /var/tmp, but if we detect we are in a container, then
        use a standardized env var to redirect to the host's filesystem instead
        �TMPDIRNz/var/tmp�HOST�	container�/zstat --file-system --format=z%Tr%�tmpfsz�WARNING: tmp-dir is set to a tmpfs filesystem. This may increase memory pressure and cause instability on low memory systems, or when using --all-logs.�)r<rr@rA�abspath�getenvrP�lstripr�striprR�print�time�sleep)rUr*s  rYr>zSoSComponent.get_tmpdir_default�s���
�9�9����W�W�_�_�T�Y�Y�%6�%6�7�F��Y�Y�x��.�<�*�F�
�9�9�V�T�"�r�y�y��d�'C��W�W�\�\�"�)�)�F�"3�V�]�]�3�5G�H�F�#�37��@�
�
�%�'�	
���>�>�W�$�
�>�
?�
�J�J�q�M��
rjc	��|jj�j�D�cgc]}|jd�s�|��}}|r-t	|D�cgc]}t|j|���c}�Sycc}wcc}w)N�list)r<�dict�keys�
startswith�any�getattr)rU�or<�opts    rY�check_listing_optionsz"SoSComponent.check_listing_options�sf���9�9�>�>�+�0�0�2�K�a�a�l�l�6�6J��K��K���4�@�C���	�	�3�/�@�A�A���L��@s�A8�A8�A=c��y)ziThis should be overridden by each subcommand to add its own unique
        options to the parser
        Nrp)�clsr.s  rY�add_parser_optionszSoSComponent.add_parser_options�s��
	
rjc�8�t�j|jj|j�|jd����}|jd��}|j
�D]�\}}||jj�vs|dgdfvr�*|dvrTdD]O}t|�tt||��z}|s�'t||t||�D�cgc]}||vr|��
c}��Q||j|k7s��t|||���|Scc}w)a.(Re-)apply options specified via the cmdline to an options instance

        There are several cases where we may need to re-apply the options from
        the cmdline over previously loaded options - for instance when an
        option is specified in both a config file and cmdline, or a preset and
        the cmdline, or all three.

        Use this to re-apply cmdline option overrides to anything that may
        change the default values of options

        Positional arguments:

            :param opts:        SoSOptions object to update

        F)�
preset_filter�r:Nr)�enable_plugins�skip_plugins�only_plugins)r
�	from_argsr.�
parse_argsr$r��itemsr:r��setr��setattr)	rUr<�cmdopts�codictr��val�oopt�common�xs	         rY�apply_options_from_cmdlinez'SoSComponent.apply_options_from_cmdline�s%��&�,�(�(��K�K�"�"�4�<�<�0������7�)�
�����E��2������	(�H�C���'�.�.�3�3�5�5���r�2��9N���H�H�N�5�D� ��X��G�D�$�,?�(@�@�F����d���d�8K�-4�1�#$�F�?�./�-4�5�
5��d�'�'��,�,���c�3�'�!	(�$���
-4s�
Dc���t|j��}|jjD]}|jt
k7s�d|_�|j
|jj|jj�d|jvsd|jvr&|j
|jjd�tj�dk7rwtjjtj �d�}tjj#|�r&|j
||jj�|j%|�}|S)zxCompile arguments loaded from defaults, config files, and the
        command line into a usable set of options
        r�Nz--cleanz--mask�cleanrz.config/sos/sos.conf)r
r8r.�_actions�defaultr�update_from_confr/r�	componentr$r@�getuidrArPr�home�existsr�)rUr<�option�userconfs    rYr;zSoSComponent.load_options�s��
�t�'9�'9�:���k�k�*�*�	&�F��~�~��)�!%���	&�	
���d�i�i�3�3�T�Y�Y�5H�5H�I�����$��D�L�L�(@��!�!�$�)�)�"7�"7��A�
�9�9�;�!���w�w�|�|�D�I�I�K�1G�H�H��w�w�~�~�h�'��%�%�h��	�	�0C�0C�D��.�.�t�4���rjc�D�	|jr|jj�|jr|jj�|jrt|j�yy#t$r%}td|�d|j���Yd}~yd}~wwxYw)NzFailed to finish cleanup: z
Contents may remain in )r1�cleanupr2r�r*rr7r�)rU�errs  rYr�zSoSComponent.cleanup
s|��		(��|�|����$�$�&��!�!��"�"�(�(�*��{�{��t�{�{�#����	(���$�+�+�'�
(�
(��	(�s�A-A1�1	B�:B�Bc��d}tjjd�r1tjjd�|j_d}nOtjjd�r0tjjd�|j_d}|jj|�|jj|�y)NzFNo encryption environment variables set, archive will not be encrypted�
SOSENCRYPTKEYz+Encryption key set via environment variable�SOSENCRYPTPASSz2Encryption passphrase set via environment variable)	r@�environ�getr<rr�soslog�inforr)rUrXs  rY�_set_encrypt_from_env_varsz'SoSComponent._set_encrypt_from_env_varss�����
�:�:�>�>�/�*�$&�J�J�N�N�?�$C�D�I�I�!�?�C�
�Z�Z�^�^�,�
-�%'�Z�Z�^�^�4D�%E�D�I�I�"�F�C��������������rjc��|jjs�d}|dvrtd�j�}|dvr�|dk(rt	d�|j_y|dk(rtd�|j_y|dk(r|j�yd|j_d|j_|jjd�|jjd	�y|j�y)
N)�P�K�E�NzLSpecify encryption method [P]assphrase, [K]ey, [E]nv vars, [N]o encryption: r�zSpecify encryption passphrase: r�zSpecify encryption key: r�z@User specified --encrypt, but chose no encryption when prompted.zArchive will not be encrypted)r<r�input�upperrrrr�r�r�rr�warning)rU�_encs  rY�_get_encryption_methodz#SoSComponent._get_encryption_method's����y�y����D��2�2��.���5�7���2�2�
�s�{�)0�2@�*A��	�	�&����(-�.H�(I��	�	�%�����/�/�1�(,��	�	�%�)-��	�	�&���� � �"=�>����#�#�$C�D��+�+�-rjc	��|jjr|j�|jjs|jjrdnd|jj|jjd�}|s|j
j
�}tjj|j|�}|jjdk(rj|j
j�}|||j|j
|jj||j|j�|_nRt#||j|j
|jj||j|j�|_|j j%|jj&dkD�y)NTF)r�key�passwordrr{)r<rr�rrr,�get_archive_namer@rArPr*r�get_preferred_archiverrr3r1r	�	set_debugr)rU�name�enc_opts�archive_name�auto_archives     rY�
setup_archivezSoSComponent.setup_archive?sD���9�9����'�'�)� $�	�	� 6� 6� $�	�	� 5� 5��<A��9�9�(�(��	�	�.�.�	
����;�;�/�/�1�D��w�w�|�|�D�K�K��6���9�9�%�%��/��;�;�<�<�>�L�'��d�k�k�(,���T�Y�Y�5F�5F�(0�$�,�,�(,�
�
�7�D�L�*�,����*.�+�+�t�y�y�7H�7H�*2�D�L�L�*.�-�-�9�D�L�
	
�����t�y�y�2�2�Q�6�7rjc�X�tjtj�}|j	tj
d��|j
|jjdkDrtjntj�|jj|�y)N�%(message)sr )
�logging�
StreamHandlerrE�stdout�setFormatter�	Formatter�setLevelr<r�DEBUG�INFOrr�
addHandler)rU�
ui_consoles  rY�add_ui_log_to_stdoutz!SoSComponent.add_ui_log_to_stdoutZso���*�*�3�:�:�6�
����� 1� 1�-� @�A����!�Y�Y�0�0�1�4�G�M�M�'�,�,�	
�	
�����z�*rjc��|r�|jr)|jjtj�|jj
dkDr*|jjtj�y|jjtj�y|jjtj�y�Nr )�flogr�r�r�r<r�console�WARNING)rUrs  rY�set_loggers_verbosityz"SoSComponent.set_loggers_verbositybsv����y�y��	�	�"�"�7�=�=�1��y�y�"�"�Q�&����%�%�g�m�m�4����%�%�g�o�o�6��L�L�!�!�'�/�/�2rjc��tjd�|_|jjtj�d|_|j
�s�|j�|_tj|j�|_|j
jtjd��|j
jtj�|jj|j
�|jjs�tjt j"�|_|j$jtjd��|j'|jj(�|jj|j$�n�tjt j*�}|jtjd��|jtj,�|jj|�tjd�|_|j.j|jj(dkDrtjntj�|j
�ss|j�|_tj|j0�}|jtjd��|j.j|�|jjs|j3�yy)z�Creates the log handler that shall be used by all components and any
        and all related bits to those components that need to log either to the
        console or to the log file for that run of sos.
        rdNz&%(asctime)s %(levelname)s: %(message)sr��sos_uir )r��	getLoggerr�r�r�r�r��
get_temp_file�sos_log_filer�r�r�r�r�r<rrEr�r�r�rrF�ERRORrr�sos_ui_log_filer�)rU�console_err�ui_fhandlers   rYrLzSoSComponent._setup_loggingms<���'�'��.��������W�]�]�+���	��)�)�+� $� 2� 2� 4�D���-�-�d�.?�.?�@�D�I��I�I�"�"�7�#4�#4�8�$:�
;��I�I���w�|�|�,��K�K�"�"�4�9�9�-��y�y���"�0�0����<�D�L��L�L�%�%�g�&7�&7�
�&F�G��&�&�t�y�y�':�':�;��K�K�"�"�4�<�<�0�"�/�/��
�
�;�K��$�$�W�%6�%6�}�%E�F�� � ����/��K�K�"�"�;�/��'�'��1��������!�Y�Y�0�0�1�4�G�M�M�'�,�,�	
��)�)�+�#'�#5�#5�#7�D� �!�/�/��0D�0D�E�K��$�$�W�%6�%6�8�&:�
;�
�K�K�"�"�;�/��y�y����%�%�'�rjc�6�|jj�Srf)r2�newrhs rYr�zSoSComponent.get_temp_file�s���!�!�%�%�'�'rj)rN)r)�__name__�
__module__�__qualname__�__doc__�descr:r=rMr`�
root_requiredr8rZrNrir6rHr>r��classmethodr�r�r;r�r�r�r�r�r�rLr�rprjrYrrs����$�D��L����K��J��M��"�*����������
�M�54�n.�"�� ��:B�
�
��
�-�^�:(�
�.�08�6+�	3�,(�\(rjrc�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	gfd�Z
dd
�Zy	)r?a8This class is used to record metadata from a sos execution that will
    then be stored as a JSON-formatted manifest within the final tarball.

    It can be extended by adding further instances of SoSMetadata to represent
    dict-like structures throughout the various sos bits that record to
    metadata
    c��i|_yrf��_valuesrhs rYrZzSoSMetadata.__init__�s	����rjc#�XK�|jj�D]	}|d���y�wr�)r�r��rU�items  rY�__iter__zSoSMetadata.__iter__�s+�����L�L�&�&�(�	�D��q�'�M�	�s�(*c� �|j|Srfr�r�s  rY�__getitem__zSoSMetadata.__getitem__�s���|�|�D�!�!rjc�R�	|j|S#t$rt|��wxYwrf)r�r7�AttributeError)rU�attrs  rY�__getattr__zSoSMetadata.__getattr__�s0��	'��<�<��%�%���	'� ��&�&�	'�s��&c�"�||j|<y)z@Add a key, value entry to the current metadata instance
        Nr�)rU�
field_name�contents   rYrOzSoSMetadata.add_field�s��$+����Z� rjc�N�t�|j|<|j|S)zCAdds a new instance of SoSMetadata to the current instance
        )r?r�)rU�section_names  rYrTzSoSMetadata.add_section�s#��&1�]����\�"��|�|�L�)�)rjc�X�t|t�std��||j|<y)z�Add a named list element to the current instance. If content is not
        supplied, then add an empty list that can alter be appended to
        zcontent added must be listN)�
isinstancer��	TypeErrorr�)rU�	list_namers   rY�add_listzSoSMetadata.add_list�s(���'�4�(��8�9�9�")����Y�rjNc�4�tj|d�|��S)z�Convert contents of this SoSMetdata instance, and all other nested
        instances (sections), into a json-formatted output.

        Used to write manifest.json to the final archives.
        c�.�t|dt|��S)Nr�)r��str)r�s rY�<lambda>z&SoSMetadata.get_json.<locals>.<lambda>�s��G�A�y�#�a�&�,I�rj)r��indent)�json�dumps)rUrs  rY�get_jsonzSoSMetadata.get_json�s���z�z�$�"I�!'�)�	)rjrf)r�r�r�r�rZr�r�r�rOrTr	rrprjrYr?r?�s4�����"�'�+�
*�+-�*�)rjr?)rr�r@rJrEr��argparserrr�shutilr�pathlibrrdr�sos.archiver	�sos.optionsr
�
sos.utilitiesrrrr?rprjrY�<module>rsK����	��
��������&�"�1�~(�~(�B4)�4)rj

Zerion Mini Shell 1.0