%PDF- %PDF-
Mini Shell

Mini Shell

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

�

i��d�%��F�dZddlmZmZmZmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZddlmZmZddlZddlZddlZddlZddlZddlmZddlZddlZddlZddlZddlmZd�Z d�Z!d	�Z"ejFd
ejH�Z%dZ&Gd�d
e'�Z(Gd�de'�Z)Gd�d�Z*Gd�d�Z+Gd�d�Z,Gd�de,�Z-Gd�de,�Z.Gd�de,�Z/Gd�de,�Z0Gd�de,�Z1Gd �d!e,�Z2Gd"�d#e,�Z3Gd$�d%e,�Z4Gd&�d'e-�Z5d)d(�Z6y)*z; This exports methods available for use by plugins for sos �)�sos_get_command_output�
import_module�grep�fileobj�tail�
is_executable�TIMEOUT_DEFAULT�path_exists�
path_isdir�path_isfile�path_islink�listdir�	path_join�bold�file_is_binary�recursive_dict_values_by_key)�P_FILE�P_LINKN)�time)�datetimec���	t|�5}tj||j�tj�cddd�S#1swYyxYw#t
$rgcYSwxYw)z=Return a list of all non overlapping matches in the string(s)N)r�re�findall�read�	MULTILINE�AttributeError)�regex�fname�fs   �=/usr/lib/python3/dist-packages/sos/report/plugins/__init__.py�
regex_findallr!"sR���
�U�^�	=�q��:�:�e�Q�V�V�X�r�|�|�<�	=�	=�	=�����	��s.�A�3A
�	A�
A�A�A�A$�#A$c��tjdd|�}tjdd|�}tjdd|�jd�}|d|}|S)	Nz^/(usr/|)(bin|sbin)/�z[^\w\-\.\/]+�_�/�.z ._-r)r�sub�strip)�command�name_max�manglednames   r �_mangle_commandr,+sV���&�&�0�"�g�>�K��&�&��#�{�;�K��&�&��s�K�0�6�6�v�>�K��a��)�K���c���tjdftjdftjdftjdfg}|D]}|d|j
�s�|dcSy)z� return a string indicating the type of special node represented by
    the stat buffer st (block, character, fifo, socket).
    zblock devicezcharacter devicez
named pipe�socketr�N)�stat�S_ISBLK�S_ISCHR�S_ISFIFO�S_ISSOCK�st_mode)�st�_types�ts   r �
_node_typer:3sh��

���~�&�	
���)�*�	
����%�	
����!�	�F�����1�Q�4��
�
���Q�4�K�r-z-*BEGIN.*?-*ENDz
-----SCRUBBEDc��eZdZdZdZdZgZgZgZgZ	gZ
dd�Zd�Zd�Z
d�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zdgggggifd�Zy)�SoSPredicatea�A class to implement collection predicates.

    A predicate gates the collection of data by an sos plugin. For any
    `add_cmd_output()`, `add_copy_spec()` or `add_journal()` call, the
    passed predicate will be evaulated and collection will proceed if
    the result is `True`, and not otherwise.

    Predicates may be used to control conditional data collection
    without the need for explicit conditional blocks in plugins.

    :param owner:       The ``Plugin`` object creating the predicate
    :type owner:        ``Plugin``

    :param dry_run:     Is sos running in dry_run mode?
    :type dry_run:      ``bool``

    :param kmods:       Kernel module name(s) to check presence of
    :type kmods:        ``list``, or ``str`` of single name

    :param services:    Service name(s) to check if running
    :type services:     ``list``, or ``str`` of single name

    :param packages:    Package name(s) to check presence of
    :type packages:     ``list``, or ``str`` of single name

    :param cmd_outputs: Command to run, with output string to check
    :type cmd_outputs:  ``list`` of ``dict``s, or single ``dict`` taking form
                        {'cmd': <command to run>,
                        'output': <string that output should contain>}
    :param arch:        Architecture(s) that the local system is matched
                        against
    :type arch:         ``list``, or ``str`` of single architecture

    :param required:    For each parameter provided, should the checks
                        require all items, no items, or any items provided
    :type required:     ``dict``, with keys matching parameter names and values
                        being either 'any', 'all', or 'none. Default 'any'.

    NFc
���d}d|jz}|j}|r|D�cgc]}||z��	c}n|}|ddj|�zz
}|j}|r|D�	cgc]}	||	z��	c}	n|}|ddj|�zz
}|j}
|r|
D�cgc]}||z��	c}n|
}
|ddj|
�zz
}|j
D�cgc]#}d|dz�d	||dz�d
|dz�d	||dz�d�	��%}
}|d
dj|
�zz
}|j}|r|D�cgc]}||z��	c}n|}|ddj|�zz
}||z|zScc}wcc}	wcc}wcc}wcc}w)zxReturn a string representation of this SoSPredicate with
            optional prefix, suffix and value quoting.
        z"%s"zdry_run=%s, zkmods=[%s], �,zservices=[%s], zpackages=[%s], z{ �cmd�: �, �outputz }zcmdoutputs=[%s], zarches=[%s])�dry_run�kmods�join�services�packages�cmd_outputs�arch)�self�quote�prefix�suffix�quotes�pstrrD�krF�s�pkgs�p�	cmdoutput�
cmdoutputs�arches�as                r �__strzSoSPredicate.__str�s���������,���
�
��/4�U�+���!��+�%����#�(�(�5�/�2�2���=�=��5:��1�1�F�Q�J�1����!�S�X�X�h�%7�8�8���}�}��-2�D�)�q���
�)����!�S�X�X�d�^�4�4��"�-�-�
�
�	%+�U�N�$*�Y�u�-=�$=�$*�X�$5�$*�Y�x�-@�$@�
B�
�
�
�	
�#�s�x�x�
�';�<�<������16�f�-��&�1�*�-�F���
����&�!1�2�2����}�v�%�%��1,��2��*��
��.s�E�E�E�(E �!E%c�"�|j�S)z�Return a string representation of this SoSPredicate.

            "dry_run=False, kmods=[], services=[], cmdoutputs=[]"
        ��_SoSPredicate__str�rJs r �__str__zSoSPredicate.__str__�s��
�z�z�|�r-c�*�|jddd��S)z�Return a machine readable string representation of this
            SoSPredicate.

            "SoSPredicate(dry_run=False, kmods=[], services=[], cmdoutputs=[])"
        Tz
SoSPredicate(�))rKrLrMrZr\s r �__repr__zSoSPredicate.__repr__�s���z�z��_�S�z�I�Ir-c�f�|dk(rt|�S|dk(rt|�S|dk(rt|�Sy)z�Helper to simplify checking the state of the predicate's evaluations
        against the setting of the required state of that evaluation
        �any�all�noneN)rbrc)rJ�items�requireds   r �_check_required_statez"SoSPredicate._check_required_state�sA���u���u�:��
��
��u�:��
��
��5�z�>�!� r-c��|j|}|dk7r|j|j|�y|j|j|�y)z�Helper to direct failed predicates to provide the proper messaging
        based on the required check type

            :param test:      The type of check we're doing, e.g. kmods, arch
            :param item:      The string of what failed
        rdN)rf�_failed�append�
_forbidden)rJ�test�item�_reqs    r �_failed_or_forbiddenz!SoSPredicate._failed_or_forbidden�sG���}�}�T�"���6�>��L�L���%�%�d�+��O�O�D�!�(�(��.r-c�8�|jr|jjd�ryg}|jD]C}|jj|�}|j	|�|r�2|jd|��E|j
||jd�S)N�allow_system_changesTrD)rD�_owner�
get_option�is_module_loadedrjrorgrf)rJ�_kmods�kmod�ress    r �_eval_kmodszSoSPredicate._eval_kmods�s����z�z�T�[�[�3�3�4J�K�����J�J�	9�D��+�+�.�.�t�4�C��M�M�#����)�)�'�4�8�		9��)�)�&�$�-�-��2H�I�Ir-c��|jsyg}|jD]C}|jj|�}|j|�|r�2|j	d|��E|j||jd�S)NTrF)rFrr�is_service_runningrjrorgrf)rJ�_svcs�svcrws    r �_eval_serviceszSoSPredicate._eval_services�su���}�}�����=�=�	;�C��+�+�0�0��5�C��L�L�����)�)�*�c�:�		;��)�)�%����z�1J�K�Kr-c��|jsyg}|jD]C}|jj|�}|j|�|r�2|j	d|��E|j||jd�S)NTrG)rGrr�is_installedrjrorgrf)rJ�_pkgs�pkgrws    r �_eval_packageszSoSPredicate._eval_packages�su���}�}�����=�=�	;�C��+�+�*�*�3�/�C��L�L�����)�)�*�c�:�		;��)�)�%����z�1J�K�Kr-c��d|vsd|vryt|d�}|ddk7ry|dj�D]}|d|vs�yy)z*Does 'cmd' output contain string 'output'?r?rBF�statusrT)r�
splitlines)rJ�
cmd_output�result�lines    r �_eval_cmd_outputzSoSPredicate._eval_cmd_output�se���
�"�h�j�&@��'�
�5�(9�:���(��q� ���8�$�/�/�1�	�D��(�#�t�+��	�r-c��|jsyg}|jD]D}|j|�}|j|�|r�(|jd|d�d|d����F|j	||j
d�S)NTrHr?r@rB)rHr�rjrorgrf)rJ�_cmdsr?rws    r �_eval_cmd_outputszSoSPredicate._eval_cmd_outputss����������#�#�	�C��'�'��,�C��L�L�����)�)�!� #�E�
�C��M�:��		��)�)�%����}�1M�N�Nr-c��|jsy|jjj�}ddj	|j�z}|j
ddk(r6t
j||�r|jdj|�yyt
j||�ry|jdj|�y)NT�(?:%s)�|rIrd�architectureF)rIrr�policy�get_archrErfr�matchrkrjri)rJ�_archrs   r �
_eval_archzSoSPredicate._eval_archs����y�y��
���"�"�+�+�-���3�8�8�D�I�I�.�.���=�=�� �F�*��x�x��u�%�����/�6�6�u�=���
�8�8�E�5�!�����^�$�+�+�E�2�r-c��d}d}|jj�D]3\}}|s�	t|�}|||djd�|D��fzz
}�5|S)z\Return a string informing user what caused the predicate to fail
        evaluation
        r#zrequired %s missing: %s.rAc3� K�|]}|���y�w�N���.0�vs  r �	<genexpr>z.SoSPredicate._report_failed.<locals>.<genexpr>,�����,<�1�Q�,<���)rire�setrE�rJ�msg�_substr�key�vals     r �_report_failedzSoSPredicate._report_failed"sg����,�����*�*�,�	>�H�C�����c�(�C��7�c�4�9�9�,<��,<�#<�=�=�=�C�		>�
�
r-c��d}d}|jj�D]3\}}|s�	t|�}|||djd�|D��fzz
}�5|S)zxReturn a string informing the user that a forbidden condition exists
        which caused the predicate to fail
        r#zforbidden %s '%s' found.rAc3� K�|]}|���y�wr�r�r�s  r r�z1SoSPredicate._report_forbidden.<locals>.<genexpr>9r�r�)rkrer�rEr�s     r �_report_forbiddenzSoSPredicate._report_forbidden/sg����,�����-�-�/�	>�H�C�����c�(�C��7�c�4�9�9�,<��,<�#<�=�=�=�C�		>�
�
r-c��|j�|j�|jrdndg}dj|�j	�S)z}Used by `Plugin()` to obtain the error string based on if the reason
        was a failed check or a forbidden check
        z	(dry run)r#� )r�r�rCrE�lstrip�rJr�s  r �report_failurezSoSPredicate.report_failure<sG��

���!��"�"�$��<�<�K�R�
��
�x�x��}�#�#�%�%r-c�l�t|j|j|j|j|j
|jg�sy|j�xrF|j�xr4|j�xr"|j�xr|j�xr
|jS)z#Predicate evaluation hook.
        T)rbrDrFrGrHrIrCrxr}r�r�r�r\s r �__bool__zSoSPredicate.__bool__Gs���
�D�J�J��
�
�t�}�}�d�>N�>N��I�I�t�|�|�-�.���!�!�#�#��(;�(;�(=�#��$�$�&�#�+/�+A�+A�+C�#����"�%����$�	&r-c		��||_t|�|_t|�|_t|�|_t|�|_t
|t�s|g}||_||jjdjz|_	dddddd�|_
|jj|j�D�	�
cic]\}	}
||	|j|	k7r|	|
��c}
}	�gggggd�|_
gggggd�|_ycc}
}	w)z-Initialise a new SoSPredicate object
        �cmdlineoptsrb)rDrFrGrHrI)rDrFrGrHr�N)rr�listrDrFrGrI�
isinstancerH�commonsrCrf�updatererirk)rJ�ownerrCrDrFrGrHrIrfrPr�s           r �__init__zSoSPredicate.__init__Us������%�[��
��X���
��X���
���J��	��+�t�,�&�-�K�&�������!4�!4�]�!C�!K�!K�K���"'�U��(-�u�>��
��
�
���%�^�^�-�
��Q���Q�K�4�=�=��+�+�
�q�D�
�	��R�R���
���
�R�R���
����
s�"D
)Fr#r#)�__name__�
__module__�__qualname__�__doc__rrrCrDrFrGrHrIr[r]r`rgrorxr}r�r�r�r�r�r�r�r�r�r�r-r r<r<Fs���&�P�F��G�
�E��H��H��K��D� &�D�J�	"�/�J�L�L�
�
O��&��	&�&�',�2���"�2��
r-r<c��eZdZdZd�Zd�Zy)�
SoSCommanda�A class to represent a command to be collected.

    A SoSCommand() object is instantiated for each command handed to an
    _add_cmd_output() call, so that we no longer need to pass around a very
    long tuple to handle the parameters.

    Any option supported by _add_cmd_output() is passed to the SoSCommand
    object and converted to an attribute. SoSCommand.__dict__ is then passed to
    _get_command_output_now() for each command to be collected.
    c�:�|jj|�yr�)�__dict__r�)rJ�kwargss  r r�zSoSCommand.__init__s���
�
���V�$r-c�t�djd�t|jj��D��S)zIReturn a human readable string representation of this SoSCommand
        rAc3�0K�|]\}}|�d|�����y�w)�=Nr�)r��paramr�s   r r�z%SoSCommand.__str__.<locals>.<genexpr>�s����8�L�U�C�E�3�/�8�s�)rE�sortedr�rer\s r r]zSoSCommand.__str__�s4���y�y�8���
�
� 3� 3� 5�6�8�8�	8r-N)r�r�r�r�r�r]r�r-r r�r�ss��	�%�8r-r�c�P�eZdZdZdZdZdZdZdZdZ	dgZ
dZ		d	d�Zd�Z
d�Zd�Zy)
�	PluginOptaVThis is used to define options available to plugins. Plugins will need
    to define options alongside their distro-specific classes in order to add
    support for user-controlled changes in Plugin behavior.

    :param name:        The name of the plugin option
    :type name:         ``str``

    :param default:     The default value of the option
    :type default:      Any

    :param desc:        A short description of the effect of the option
    :type desc:         ``str``

    :param long_desc:   A detailed description of the option. Will be used by
                        `sos info`
    :type long_desc:    ``str``

    :param val_type:    The type of object the option accepts for values. If
                        not provided, auto-detect from the type of ``default``
    :type val_type:     A single type or a ``list`` of types
    r#NFc��||_||_||_||_|j|_|�t|t�s|g}||_y|jg}||_yr�)	�name�default�desc�	long_desc�valuer�r��	__class__�val_type)rJr�r�r�r�r�s      r r�zPluginOpt.__init__�s`����	������	�"����\�\��
����h��-�$�:��!��
� �)�)�*�H� ��
r-c��d|jzd|jzd|jzd|jzg}ddj	|�zdzS)Nzname=%sz	desc='%s'zvalue=%sz
default=%s�(rAr_)r�r�r�r�rE)rJres  r r]zPluginOpt.__str__�sT����	�	�!��D�I�I�%�����#��4�<�<�'�	
���T�Y�Y�u�%�%��+�+r-c�"�|j�Sr�)r]r\s r r`zPluginOpt.__repr__�s���|�|�~�r-c�V�td�|jvrt|�|_yt	|jD�cgc]}t|�|k(��c}�s�g}|jD]h}|��|j
dk(r|j
d��'|j
dk(r|j
d��H|j
dk(s�X|j
d��jtd|j�d	|j�d
dj|��dt|�j
����||_ycc}w)
Nr#�boolz boolean true/false (on/off, etc)�strzstring (no spaces)�intzinteger valueszPlugin option 'r&z' takes rAz, not )�typer�r�r�rbr�rj�	Exception�pluginr�rE)rJr��_t�validr9s     r �	set_valuezPluginOpt.set_value�s�����8�t�}�}�$��S��D�J���d�m�m�<��D��I��O�<�=��E��]�]�
3���9���:�:��'��L�L�!C�D��Z�Z�5�(��L�L�!5�6��Z�Z�5�(��L�L�!1�2�
3���K�K����D�I�I�e�,<���I�&�&���
���
��#=s�D&)�	undefinedNr#r#N)r�r�r�r�r�r��enabledr�r�r�r�r�r�r]r`r�r�r-r r�r��sM���,�D��G��G�
�D��I��E��v�H�
�F�JL��!�,��r-r�c�`�eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZeZeZdZiZiZgZdZdZd�Zd�Zd�Zd	�Zd
�Zd}d�Zd�Zed
��Z ed��Z!d�Z"d�Z#e$d��Z%e$d��Z&e$d��Z'e$d��Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d�Z0d�Z1d�Z2d�Z3d �Z4d!�Z5d"�Z6d#�Z7d$�Z8d%�Z9d~d&�Z:d~d'�Z;dd(�Z<d�d)�Z=d*�Z>d�d+�Z?d,�Z@d-�ZAd.�ZBd/�ZCd0�ZDd1�ZEd2�ZFd3�ZGd4�ZHd5�ZId�d6�ZJd7�ZKd8�ZLd�d9�ZMd:�ZNd;�ZOd<�ZPd=�ZQddd>dgdfd?�ZRddd>ddddgggd@dfdA�ZSddd>ddddgd@df
dB�ZTdC�ZUdddd>d>ddddddddgd@dddfdD�ZVdE�ZWdF�ZXd�dG�ZYdH�ZZdI�Z[d}dJ�Z\dK�Z]ddgfdL�Z^dddd>d>dddddddgd@dddfdM�Z_dddd>d>ddddddddgfdN�Z`			d�dO�ZadP�ZbdQ�Zcd}dR�ZddS�ZeddT�ZfdU�Zgd�dV�Zhd}dW�Zid}dX�ZjddY�ZkddZ�Zld[�Zmd\�Znd]�Zod^�Zp				d�d_�Zqd`�Zrda�Zsdb�Ztdc�Zudd�Zvde�Zwdf�Zxdg�Zyezj�dgfdh��Z|di�Z}dj�Z~dk�Zdl�Z�dm�Z�dn�Z�do�Z�dp�Z�dq�Z�dr�Z�ds�Z�dt�Z�du�Z�dv�Z�dw�Z�dx�Z�dy�Z�dz�Z�d�d{�Z�d�d|�Z�y)��Plugina\This is the base class for sosreport plugins. Plugins should subclass
    this and set the class variables where applicable.

    :param commons:     A set of information that is shared internally so that
                        plugins may access the same dataset. This is provided
                        automatically by sos
    :type commons:      ``dict``

    Each `Plugin()` subclass should also subclass at least one tagging class,
    e.g. ``RedHatPlugin``, to support that distribution. If different
    distributions require different collections, each distribution should have
    its own subclass of the Plugin that also subclasses the tagging class for
    their respective distributions.

    :cvar plugin_name:  The name of the plugin, will be returned by `name()`
    :vartype plugin_name: ``str``

    :cvar packages:     Package name(s) that, if installed, enable this plugin
    :vartype packages:  ``tuple``

    :cvar files:        File path(s) that, if present, enable this plugin
    :vartype files:     ``tuple``

    :cvar commands:     Executables that, if present, enable this plugin
    :vartype commands:  ``tuple``

    :cvar kernel_mods:  Kernel module(s) that, if loaded, enable this plugin
    :vartype kernel_mods: ``tuple``

    :cvar services:     Service name(s) that, if running, enable this plugin
    :vartype services:  ``tuple``

    :cvar architectures: Architecture(s) this plugin is enabled for. Defaults
                         to 'none' to enable on all arches.
    :vartype architectures: ``tuple``, or ``None``

    :cvar profiles:     Name(s) of profile(s) this plugin belongs to
    :vartype profiles:  ``tuple``

    :cvar plugin_timeout: Timeout in seconds for this plugin as a whole
    :vartype plugin_timeout: ``int``

    :cvar cmd_timeout:  Timeout in seconds for individual commands
    :vartype cmd_timeout:   ``int``
    Nr�r%Fc�Z�g|_g|_t�|_g|_d|_||_g|_t�|_g|_	g|_
g|_i|_|d|_
|d|_|d|_d|_|dj"|_|dj$|_i|_g|_d|jvr|jdnt+j,d�|_|jj1|j3��|jD]$}|j5�|j|_�&|j8D]0}|j5�|_||j|j4<�2|j;t=|��y)Nr#�sysrootr��devicesr��soslog�sos)�copied_files�executed_commandsr��	_env_vars�alerts�custom_textr��forbidden_paths�
copy_paths�container_copy_paths�copy_strings�collect_cmds�optionsr�r�r��manifest�
skip_files�
skip_commands�default_environment�_tail_files_list�logging�	getLoggerr�r��get_default_plugin_optsr�r��option_list�
set_predicater<)rJr��popt�opts    r r�zPlugin.__init__!s}�����!#����������������!����%���$&��!�����������y�)����h�'����y�)�����
�!�-�0�;�;���$�]�3�A�A���#%�� � "���08�D�L�L�0H�d�l�l�8�,��"�"�5�)�	
��	
�����D�8�8�:�;��L�L�	4�D�(,�	�	��D�L�L���%�	4��#�#�	)�C�����C�J�%(�D�L�L����"�	)�
	
���<��-�.r-c�t�tddtd��tddtd��tddtd	��d
�S)N�timeout���z7Timeout in seconds for plugin to finish all collections)r�r�r��cmd-timeoutz4Timeout in seconds for individual commands to finish�postprocTz(Enable post-processing of collected data)r�rr)r�r�r�r\s r r�zPlugin.get_default_plugin_optsFsF�� ��2��N��%��r�C�K��"��D�4�?��

�
	
r-c�J�||_|jjdd�|jjdd�|jjdd�|jjdd�|jjdd�|jjdd�|jjd|j�|jjd	d
�|jjd|j�|jj	dg�|jj	d
g�|jjdi�|jjdi�|jj	dg�y)z�Pass in a manifest object to the plugin to write to

        :param manifest: The manifest that the plugin will add metadata to
        :type manifest: ``SoSManifest``
        �
start_timer#�end_time�run_time�setup_start�	setup_end�
setup_timer��timeout_hitF�command_timeout�commands�files�strings�
containers�collectionsN)r��	add_fieldr��
cmdtimeout�add_list)rJr�s  r �set_plugin_manifestzPlugin.set_plugin_manifestVs,��!��
��
�
����b�1��
�
���
�B�/��
�
���
�B�/��
�
���
�r�2��
�
����R�0��
�
����b�1��
�
���	�4�<�<�8��
�
���
�u�5��
�
��� 1�4�?�?�C��
�
���z�2�.��
�
���w��+��
�
���	�2�.��
�
����b�1��
�
���}�b�1r-c��t|t�std��||_|j	d|jz�y)a 
        Specify a collection of environment variables that should always be
        passed to commands being executed by this plugin.

        :param env_vars:    The environment variables and their values to set
        :type env_vars:     ``dict{ENV_VAR_NAME: ENV_VAR_VALUE}``
        z:Environment variables for Plugin must be specified by dictz2Default environment for all commands now set to %sN)r��dict�	TypeErrorr��
_log_debug�rJ�env_varss  r �set_default_cmd_environmentz"Plugin.set_default_cmd_environmentmsE���(�D�)��L��
�$,�� ����L��2�2�3�	4r-c��t|t�std��|jd|z�|jj|�y)a-
        Add or modify a specific environment variable in the set of default
        environment variables used by this Plugin.

        :param env_vars:    The environment variables to add to the current
                            set of env vars in use
        :type env_vars:     ``dict``
        z,Environment variables must be added via dictz Adding %s to default environmentN)r�rrrr�r�rs  r �add_default_cmd_environmentz"Plugin.add_default_cmd_environment}s@���(�D�)��J�K�K����:�X�E�F�� � �'�'��1r-c��|�|jSt|t�std��|jj	�}|j|�|S)z�
        Get the merged set of environment variables for a command about to be
        executed by this plugin.

        :returns: The set of env vars to use for a command
        :rtype: ``dict``
        z'Command env vars must be passed as dict)r�r�rr�copyr�)rJ�env�_envs   r �_get_cmd_environmentzPlugin._get_cmd_environment�sP���;��+�+�+��#�t�$��E�F�F��'�'�,�,�.�����C���r-c���d}	|j|�}t|j|��}|�|}n*|�|dk(r|tk(r|}nt|�}n|�|dkDr|}ny|�|dkDr|S|S#t$r|cYSwxYw)a�
        Get the timeout value for either the plugin or a command, as
        determined by either the value provided via the
        plugin.timeout or plugin.cmd-timeout option, the global timeout or
        cmd-timeout options, or the default value set by the plugin or the
        collection, in that order of precendence.

        :param optname: The name of the cmdline option being checked, either
                        'plugin_timeout' or 'timeout'
        :type optname:  ``str``

        :param plugoptname: The name of the plugin option name being checked,
                            either 'timeout' or 'cmd-timeout'
        :type plugoptname: ``str``

        :param default_timeout: The timeout to default to if determination is
                                inconclusive or hits an error
        :type default_timeout:  ``int``

        :returns: The timeout value in seconds
        :rtype:   ``int``
        Nr)rsr�r	�
ValueError)rJ�optname�plugoptname�default_timeout�_timeout�opt_timeout�own_timeouts       r �timeout_from_optionszPlugin.timeout_from_options�s���.��	#��/�/�'�2�K��d�o�o�k�:�;�K��"�&���(�[�B�->��/�1�.�H�"�;�/�H��(�[�2�-=�&�����H�r�M��O����	�	#�"�"�	#�s�AA)�)A7�6A7c�@�|jdd|j�}|S)z�Returns either the default plugin timeout value, the value as
        provided on the commandline via -k plugin.timeout=value, or the value
        of the global --plugin-timeout option.
        �plugin_timeoutr�)r+r-)rJr(s  r r�zPlugin.timeout�s(���,�,�-=�y�-1�-@�-@�B���r-c�@�|jdd|j�}|S)z�Returns either the default command timeout value, the value as
        provided on the commandline via -k plugin.cmd-timeout=value, or the
        value of the global --cmd-timeout option.
        �cmd_timeoutr)r+r/)rJ�_cmdtimeouts  r rzPlugin.cmdtimeout�s(���/�/�
�}�04�0@�0@�B���r-c��d|_|jjdtj��|jjdd�y)NTrr
)�_timeout_hitr�rr�nowr\s r �set_timeout_hitzPlugin.set_timeout_hit�s8�� ����
�
���
�H�L�L�N�;��
�
���
�t�4r-c��|jS)ax
        Checks to see if the plugin has hit its timeout.

        This is set when the sos.collect_plugin() method hits a timeout and
        terminates the thread. From there, a Popen() call can still continue to
        run, and we need to manually terminate it. Thus, check_timeout() should
        only be called in sos_get_command_output().

        Since sos_get_command_output() is not plugin aware, this method is
        handed to that call to use as a polling method, to avoid passing the
        entire plugin object.

        :returns: ``True`` if timeout has been hit, else ``False``
        :rtype: ``bool``

        )r2r\s r �
check_timeoutzPlugin.check_timeout�s��"� � � r-c�f�|jr|jS|jj�S)zsGet the name of the plugin

        :returns: The name of the plugin, in lowercase
        :rtype: ``str``
        )�plugin_namer��lower)�clss r r�zPlugin.name�s(���?�?��?�?�"��|�|�!�!�#�#r-c�b�|j�|j|�y|j|�yr�)r8�display_self_help�display_plugin_help)r:�sections  r �display_helpzPlugin.display_help�s(���?�?�"��!�!�'�*��#�#�G�,r-c�j�ddlm}|j|jj	��d|j
���d}	d}|jd}|tk7r|jr|j}|jr||jz
}|j|rd|zn|�t|j|j|j|j|j |j"g�s|jd�n�d	D]B}t%||d�s�|jd
|�ddj't%||����d
���Dt%|d�r6|jddj'd�|j"D��zd
��|j(r6|jddj'd�|j(D��zd
��t+|d�r6|jddj'd�|j,D��zd
��|j.tj.ur|jd�|j0sy|j3d�}|jdt5d|jz�z�|jt5dj7dddd��d
��d }|j0D]�}	|	j8}
|
�|
dk(rd!}
t;|	j8t<�r|	j8rd"}
nd#}
d$j7d|	j>|
|	j@�}|jtCjD|||�%�d
��|	jFs��|d&z
}d'}
|jtCjD|	jF||
|
�(�d
����y#t$rd}Y��"wxYw))Nr)�TERMSIZEz Plugin Information - z8
Detailed information is not available for this plugin.
r#r0z
    %sz)This plugin is always enabled by default.)rGrr
�kernel_modsrFzEnabled by r@rAF��newlinerz-Enabled by containers with names matching: %sc3� K�|]}|���y�wr�r�)r��cs  r r�z-Plugin.display_plugin_help.<locals>.<genexpr>)s����:�a��:�r�z'Enabled with the following profiles: %sc3� K�|]}|���y�wr�r�)r�rSs  r r�z-Plugin.display_plugin_help.<locals>.<genexpr>0s����4�!�A�4�r��verify_packagesz+
Verfies packages (when using --verify): %sc3� K�|]}|���y�wr�r�)r�r�s  r r�z-Plugin.display_plugin_help.<locals>.<genexpr>7s����?�C�C�?�r�z�This plugin performs post-processing on potentially sensitive collections. Disabling post-processing may leave sensitive data in plaintext.zPlugin Optionsz2These options may be toggled or changed using '%s'z-k %s.option_name=$valuez
{:<4}{:<20}{:<30}{:<20}
r�zOption Name�Default�Descriptionz6                                                      z
None/UnsetzTrue/Onz	False/Offz{:<4}{:<20}{:<30}{:<20})�width�subsequent_indent�
z        )rL�initial_indentrM)$�sos.helprA�	set_titler8�title�
short_desc�__mro__r�r�r��add_textrbrGrr
rBrFr�getattrrE�profiles�hasattrrHrr��add_sectionr�formatr�r�r�r�r��textwrap�fillr�)r:r>rA�missing�_doc�_sc�trig�optsec�
opt_indentr��_def�_ln�_size�spaces              r r=zPlugin.display_plugin_helpsw��%���� �_�_�2�2�4�c�n�n�F�	G�N��	��D��+�+�a�.�C��f�}�����{�{���{�{�����#��	���d��d�*��@��C�L�L�#�,�,��	�	�3�?�?��L�L�#�.�.�2�3����H�I�%�
���3��d�+��$�$�����7�3��+=�!>�@� %�%��
��s�L�)�� � �C��i�i�:�3�>�>�:�:�;�!�!���<�<����9��)�)�4�s�|�|�4�4�5��
�
��3�)�*����>��)�)�?�3�+>�+>�?�?�@��
�
��<�<�v���.����6�
������$�$�%5�6�����@��-����?�@�
A�	
�	����)�0�0��]�I�}�
>���	�	
��
��?�?�	�C��;�;�D��|�t�r�z�#���#�+�+�t�,��;�;�$�D�&�D�+�2�2�3����$�36�8�8�=�C��O�O��
�
�c��0:�<��
�
�
�}�}� �2�
��������M�M�#�-�-�u�16�49�;�"�	 ��)	��y�	��D�	�s�A
N#�#N2�1N2c�H�|jd�|jdtd�z�|jd�}|jd�|jdtd��dtd	��d
��|jdtd�z�|jd
�}|jdtd��dtd��d��|jd�}ddd�}|jddj	d�|j�D��zd��y)NzSoS Plugin Detailed Helpa[Plugins are what define what collections occur for a given %s execution. Plugins are generally representative of a single system component (e.g. kernel), package (e.g. podman), or similar construct. Plugins will typically specify multiple files or directories to copy, as well as commands to execute and collect the output of for further analysis.z
sos reportzPlugin Enablementz�Plugins will be automatically enabled based on one of several triggers - a certain package being installed, a command or file existing, a kernel module being loaded, etc...z:Plugins may also be enabled or disabled by name using the z-e $namez or z-n $namez options respectively.a(Certain plugins may only be available for specific distributions or may behave differently on different distributions based on how the component for that plugin is installed or how it operates. When using %s, help will be displayed for the version of the plugin appropriate for your distribution.zsos help report.plugins.$pluginzUsing Plugin Optionsz�Many plugins support additional options to enable/disable or in some other way modify the collections it makes. Plugin options are set using the z#-k $plugin_name.$option_name=$valuez� syntax. Options that are on/off toggles may exclude setting a value, which will be interpreted as enabling that option.

See specific plugin help sections or z
sos report -lz& for more information on these optionszSee AlsozHelp for a specific $pluginz$Information on distribution policies)zreport.plugins.$plugin�policieszLAdditional relevant information may be available in these help sections:

%s�
c3�HK�|]\}}djd||����y�w)z{:>8}{:<30}{:<30}r�N)rZ)r��secr�s   r r�z+Plugin.display_self_help.<locals>.<genexpr>�s+����/��C��$�*�*�3��T�:�/�s� "FrC)rQrUrrYrEre)r:r>�subsecra�seealso�_alsos      r r<zPlugin.display_self_helpls7�����4�5����
2��<� �

!�	
��$�$�%8�9�����
=�	
�
	����J���j�!1�
3�	
�	���
8�
�4�5�
6�	
��$�$�%;�<������9�:��O�$�
&�		
��%�%�j�1��&C�>�
��	���
#�%)�Y�Y�/�!&����/�&�
��	�	
r-c�j�d|j��d|jdd�j���S)Nz[plugin:z] zutf-8�replace)r��encode�decoder�s  r �_format_msgzPlugin._format_msg�s0��#'�9�9�;�$'�:�:�g�y�#A�#H�#H�#J�L�	Lr-c�X�|jj|j|��yr�)r��errorrsr�s  r �
_log_errorzPlugin._log_error���������$�*�*�3�/�0r-c�X�|jj|j|��yr�)r��warningrsr�s  r �	_log_warnzPlugin._log_warn�s�������D�,�,�S�1�2r-c�X�|jj|j|��yr�)r��inforsr�s  r �	_log_infozPlugin._log_info�s��������)�)�#�.�/r-c�X�|jj|j|��yr�)r��debugrsr�s  r rzPlugin._log_debug�rwr-c��|j�s|S|jr3|j|j�r|t|j�dS|S)z�Remove the configured sysroot from a filesystem path

        :param path:    The filesystem path to strip sysroot from
        :type path: ``str``

        :returns: The stripped filesystem path
        :rtype: ``str``
        N)�use_sysrootr��
startswith�len�rJ�paths  r �
strip_sysrootzPlugin.strip_sysroot�sG�����!��K��<�<�D�O�O�D�L�L�9���D�L�L�)�*�+�+��r-c�v�|jtjjtj�k7S)z�Determine if the configured sysroot needs to be used

        :returns: ``True`` if sysroot is not `/`, else ``False``
        :rtype: ``bool``
        )r��osr��abspath�sepr\s r r�zPlugin.use_sysroot�s$���|�|�r�w�w���r�v�v�6�6�6r-c��|jxsd}||jj�g}tjj|�|k(S)z�Check if sysroot is within the archive's temp directory

        :returns: ``True`` if sysroot is in the archive's temp directory, else
                  ``False``
        :rtype: ``bool``
        r%)r��archive�get_tmp_dirr�r��commonprefix)rJ�_sysroot�pathss   r �tmp_in_sysrootzPlugin.tmp_in_sysroot�sC���<�<�&�3���4�<�<�3�3�5�6���w�w�#�#�E�*�h�6�6r-c�d�t|jjj|��dkDS)z�Is the package $package_name installed?

        :param package_name:    The name of the package to check
        :type package_name:     ``str``

        :returns: ``True`` id the package is installed, else ``False``
        :rtype: ``bool``
        r)r�r��package_manager�all_pkgs_by_name)rJ�package_names  r rzPlugin.is_installed�s+��
����+�+�<�<�\�J�K�a�O�	
r-c�L�|jjj|�S)z�Does the service $name exist on the system?

        :param name:    The name of the service to check
        :type name:     ``str``

        :returns: ``True`` if service is present on the system, else ``False``
        :rtype: ``bool``
        )r��init_system�
is_service�rJr�s  r r�zPlugin.is_service�����{�{�&�&�1�1�$�7�7r-c�L�|jjj|�S)z�Is the service $name enabled?

        :param name:    The name of the service to check
        :type name:     ``str``

        :returns: ``True if service is enabled on the system, else ``False``
        :rtype: ``bool``
        )r�r��
is_enabledr�s  r �is_service_enabledzPlugin.is_service_enabled�r�r-c�L�|jjj|�S)z�Is the service $name disabled?

        :param name:    The name of the service to check
        :type name:     ``str``

        :returns: ``True`` if service is disabled on the system, else ``False``
        :rtype: ``bool``
        )r�r��is_disabledr�s  r �is_service_disabledzPlugin.is_service_disabled�s���{�{�&�&�2�2�4�8�8r-c�L�|jjj|�S)a	Is the service $name currently running?

        :param name:    The name of the service to check
        :type name:     ``str``

        :returns: ``True`` if the service is running on the system, else
                  ``False``
        :rtype: ``bool``
        )r�r��
is_runningr�s  r rzzPlugin.is_service_running
s���{�{�&�&�1�1�$�7�7r-c�R�|jjj|�dS)z�Return the reported status for service $name

        :param name:    The name of the service to check
        :type name:     ``str``

        :returns: The state of the service according to the init system
        :rtype: ``str``
        r�)r�r��get_service_statusr�s  r r�zPlugin.get_service_statuss$���{�{�&�&�9�9�$�?��I�Ir-c�L�|jjj|�S)z�Get all service names matching regex

        :param regex:    A regex to match service names against
        :type regex:    ``str``

        :returns: All service name(s) matching the given `regex`
        :rtype: ``list``
        )r�r��get_service_names�rJrs  r r�zPlugin.get_service_names!s���{�{�&�&�8�8��?�?r-c��||_y)z�Set or clear the default predicate for this plugin.

        :param pred:    The predicate to use as the default for this plugin
        :type pred:     ``SoSPredicate``
        N)�	predicate�rJ�preds  r r�zPlugin.set_predicate,s����r-c��||_y)aPSet or clear the default predicate for command collection for this
        plugin. If set, this predecate takes precedence over the `Plugin`
        default predicate for command and journal data collection.

        :param pred:    The predicate to use as the default command predicate
        :type pred:     ``SoSPredicate``
        N)�
cmd_predicater�s  r �set_cmd_predicatezPlugin.set_cmd_predicate4s��"��r-c�V�|�|S|r|j�|jS|jS)a�Get the current default `Plugin` or command predicate.

        :param cmd:     If a command predicate is set, should it be used.
        :type cmd:      ``bool``

        :param pred:    An optional predicate to pass if no command or plugin
                        predicate is set
        :type pred:     ``SoSPredicate``

        :returns:   `pred` if neither a command predicate or plugin predicate
                    is set. The command predicate if one is set and `cmd` is
                    ``True``, else the plugin default predicate (which may be
                    ``None``).
        :rtype:     ``SoSPredicate`` or ``None``
        )r�r��rJr?r�s   r �
get_predicatezPlugin.get_predicate>s3�� ���K��4�%�%�1��%�%�%��~�~�r-c�D�|j||��}|�t|�Sy)a�Test the current predicate and return its value.

        :param cmd: ``True`` if the predicate is gating a command or
                    ``False`` otherwise.
        :param pred: An optional predicate to override the current
                     ``Plugin`` or command predicate.

        :returns: ``True`` or ``False`` based on predicate evaluation, or
                  ``False`` if no predicate
        :rtype: ``bool``
        �r?r�F)r�r�r�s   r �test_predicatezPlugin.test_predicateTs,���!�!�c��!�5������:��r-c�z�|�t|�}d|�d|j���}|r|dz
}|j|�y)a*Log that a command was skipped due to predicate evaluation.

        Emit a warning message indicating that a command was skipped due
        to predicate evaluation. If ``kmods`` or ``services`` are ``True``
        then the list of expected kernel modules or services will be
        included in the log message. If ``allow_changes`` is ``True`` a
        message indicating that the missing data can be collected by using
        the "--allow-system-changes" command line option will be included.

        :param cmd:     The command that was skipped
        :type cmd:      ``str``

        :param pred:    The predicate that caused the command to be skipped
        :type pred:     ``SoSPredicate``

        :param changes: Is the `--allow-system-changes` enabled
        :type changes:  ``bool``
        Nzskipped command '�': z3 Use '--allow-system-changes' to enable collection.)r<r�rz)rJr?r��changesr�s     r �log_skipped_cmdzPlugin.log_skipped_cmdesA��&�<���%�D��,/��1D�1D�1F�G����H�H�C����s�r-c��|jsy|jd|z�|rt�d|��nt}|j|t|�S)a�Remove certificate and key output archived by sos report.
        Any matching instances are replaced with: '-----SCRUBBED' and this
        function does not take a regexp or substituting string.

        :param cmd: The name of the binary to scrub certificate output from
        :type cmd:  ``str``

        :param desc: An identifier to add to the `SCRUBBED` header line
        :type desc: ``str``

        :returns: Number of replacements made
        :rtype: ``int``
        rz1Scrubbing certs and keys for commands matching %sr�)r�r�
_cert_replace�do_cmd_output_sub�
_certmatch)rJr?r�rps    r �do_cmd_private_subzPlugin.do_cmd_private_sub�sL���%�%�����K�� �	!�6:�]�D�1�}���%�%�c�:�w�?�?r-c	��d|zdz}t|d�r|jn|}|jd|�d|�d|�d��|jsyd}	|jD]�}|d	��	|d
dk(r|j	d|d
z��)tj
|d|�s�Ctjj|jd|d	�}|jd|z�|jj|�}	tj|||	j��\}
}|s��|jj|
|���	|S#t $r(}d}|j#|d
|fz�d}Yd}~|Sd}~wwxYw)a
Apply a regexp substitution to command output archived by sosreport.

        This is used to obfuscate sensitive information captured by command
        output collection via plugins.

        :param cmd: The command name/binary name for collected output that
                    needs to be obfuscated. Internally globbed with a leading
                    and trailing `*`
        :type cmd:  ``str``

        :param regexp: A regex to match the contents of the command output
                       against
        :type regexp: ``str`` or compile ``re`` object

        :param subst: The substitution string used to replace matches from
                      `regexp`
        :type subst: ``str``

        :returns: Number of replacements made
        :rtype: ``int``
        �*�pattern�substituting '�' for 'z' in commands matching '�'rN�file�binary�yesz6Cannot apply regex substitution to binary output: '%s'�exer?�cmddirzapplying substitution to '%s'�-regex substitution failed for '%s' with: '%s')rXr�rr�rz�fnmatchr�r�rEr�r��	open_filer�subnr�
add_stringr�rv)
rJr?�regexp�subst�globstrr��replacements�calledr��readabler��er�s
             r r�zPlugin.do_cmd_output_sub�sz��,��)�c�/��$+�F�I�$>�&�.�.�F����� �'�7�4�	5��%�%����	 ��0�0�
>���&�>�)���(�#�u�,��N�N�$3�5;�E�]�$C�D���?�?�6�%�=�'�:��7�7�<�<����X�(>��v��O�D��O�O�$C�d�$J�K�#�|�|�5�5�d�;�H�+-�7�7���x�}�}��,8�(�F�L�#����/�/���=�
>�*���	�	 �A�C��O�O�C�6�%�=�!�"4�4�5��L����		 �s&�AE�B	E�'E�	E9�E4�4E9c�0�|jd|z�tj|�j}|rt�d|��nt}|j
D�cgc]}||d�s�|��}}|D]!}|d}|s�|j
|t|��#ycc}w)a�Scrub certificate/key/etc information from files collected by sos.

        Files matching the provided pathregex are searched for content that
        resembles certificate, ssh keys, or similar information. Any matches
        are replaced with "-----SCRUBBED $desc" where `desc` is a description
        of the specific type of content being replaced, e.g.
        "-----SCRUBBED RSA PRIVATE KEY" so that support representatives can
        at least be informed of what type of content it was originally.

        :param pathregex: A string or regex of a filename to match against
        :type pathregex: ``str``

        :param desc: A description of the replaced content
        :type desc: ``str``
        z.Scrubbing certs and keys for paths matching %sr��srcpath�dstpathN)rr�compiler�r�r��do_file_subr�)	rJ�	pathregexr�r�rpr�	file_list�ir�s	         r �do_file_private_subzPlugin.do_file_private_sub�s��� 	
���H�#�$�	%��
�
�9�%�+�+��59�]�D�1�}�� $� 1� 1�I�1�U�1�Y�<�5H�Q�I�	�I��	8�A��Y�<�D������T�:�w�7�		8��Js�B�&Bc	�4�	|j|�}tjtjz}t	|d�r|j
}|j|z}n|}|}|jd|z�|jd|�d|�d|�d��|sy|jj|�}|j�}	t|	t�s|	jdd	�}	tj|||	|�
�\}
}|r-|jj|
|j!|��|Sd}	|S#t"t$f$rY}|j&t&j(k(rd}
|j|
z�nd}
|j+|
|fz�d}Yd
}~|Sd
}~wwxYw)a�Apply a regexp substitution to a file archived by sosreport.

        :param srcpath: Path in the archive where the file can be found
        :type srcpath: ``str``

        :param regexp:  A regex to match the contents of the file
        :type regexp: ``str`` or compiled ``re`` object

        :param subst: The substitution string to be used to replace matches
                      within the file
        :type subst: ``str``

        :returns: Number of replacements made
        :rtype: ``int``
        r�zsubstituting scrpath '%s'r�r�z' in 'r�r�utf8�ignore)�flagsz-file '%s' not collected, substitution skippedr�N)�_get_dest_for_srcpathr�
IGNORECASErrXr�r�rr�r�rr�r�rrr�r�r��OSError�IOError�errno�ENOENTrv)rJr�r�r�r��common_flagsr�r�r��contentr�r�r�r�s              r r�zPlugin.do_file_sub�st�� !	��-�-�g�6�D��=�=�2�<�<�7�L��v�y�)� �.�.�����|�3�� ��$���O�O�7�'�A�B��O�O�$�g�t�5�
6����|�|�-�-�d�3�H��m�m�o�G��g�s�+�!�.�.���:��#%�7�7�7�E�7�16�$8� �F�L�����'�'���0B�0B�7�0K�L��� !�������!�		��w�w�%�,�,�&�E������d�
�+�E������t�Q�i��0��L����		�s&�BD/�BD/�*D/�/F�>AF�Fc���t|d�stj|�}|j}|jD�cgc]}||d�s�|��}}|D]}|j|d||��ycc}w)a,Apply a regexp substituation to a set of files archived by
        sos. The set of files to be substituted is generated by matching
        collected file pathnames against `pathexp`.

        :param pathexp: A regex to match filenames within the archive
        :type pathexp: ``str`` or compiled ``re`` object

        :param regexp: A regex to match against the contents of each file
        :type regexp: ``str`` or compiled ``re`` object

        :param subst: The substituion string to be used to replace matches
        :type subst: ``str``
        r�r�N)rXrr�r�r�r�)rJ�pathexpr�r�r�rr�r�s        r �do_path_regex_subzPlugin.do_path_regex_subst���w��(��j�j��)�G��
�
�� $� 1� 1�I�1�U�1�Y�<�5H�Q�I�	�I��	=�D����T�)�_�f�e�<�	=��Js�A1�
A1c��t||�Sr�)r!)rJrrs   r �do_regex_find_allzPlugin.do_regex_find_all4s���U�E�*�*r-c
�^�tj|�}tjjtjj	|�|�}tjj|�}tjj
|�r�tjjtjj	|��}tjj||��}|j�r-|ttjtjz�d}|jd|�d|�d��n|}|jd|�d|�d|j|����|j|�}|j j#||�|j|�r|jd|z�y|j$j'||d	|d
��	tj(|�|jd
|�d|�d��||k7rG|j/|j0�xr|j2j4}	|j7||	��y|jd|z�y#t*$r2}|j,dk(r|jd|z�Yd}~yYd}~��d}~wwxYw)N)�startzmade link target 'z' relative as 'r�zcopying link 'z' pointing to 'z
' with isdir=z%link '%s' is a directory, skipping...r�)r�r��symlink�pointsto�(z;link '%s' is part of a file system loop, skipping target...znormalized link target 'z' as '��forcez.link '%s' points to itself, skipping target...)r��readlinkr�rE�dirname�normpath�isabs�realpath�relpathr�r�r��pardirrrr�r��add_linkr�rjr1r�r�r�r�r��
_in_container�
_do_copy_path)
rJr��linkdest�dest�absdest�realdir�reldestr�r�r�s
          r �
_copy_symlinkzPlugin._copy_symlink7s.���;�;�w�'���w�w�|�|�B�G�G�O�O�G�4�h�?���'�'�"�"�4�(��
�7�7�=�=��"��g�g�&�&�r�w�w���w�'?�@�G��g�g�o�o�h�g�o�>�G����!�!�#�b�f�f�r�y�y�&8�"9�":�;���O�O�'��2�
3��G����"�H�d�o�o�g�.F�H�	I��$�$�W�-�������g�w�/��?�?�7�#��O�O�C�h�N�O����� � �W�-4�-2�.6�"8�	9�	��G�G�G��	
���#�W�.�	/�
�w���'�'����5�/��[�[�.�.�
����w�e��4��O�O�L�&�'�
(��'�	��w�w�"�}����!;�=D�!E�F����	�s�#I1�1	J,�:#J'�'J,c��	|j|�D]K}|jd|�d|�d��tjj	||�}|j|��My#t$r�}|jtjk(stjrd}|jd|�d|���Yd}~y|jtjk(rd}|jd|�d	|�d��Yd}~y�d}~wwxYw)
Nzrecursively adding 'z' from 'r�zPermission deniedz_copy_dir: 'z' z)Too many levels of symbolic links copyingz_copy_dir: z ')
rrr�r�rEr�r�r��EPERM�EACCESrz�ELOOPrv)rJr�r�r�r�r�s      r �	_copy_dirzPlugin._copy_dirvs���	����W�-�
)�����#'��!2�3��w�w�|�|�G�T�2���"�"�4�(�	
)��
�		��w�w�%�+�+�%����)�����w��D�E���w�w�%�+�+�%�A������W� E�F����		�s%�AA"�"	C8�+AC3�67C3�2C3�3C8c��|j�r|j|�}|jD]}||dk(s�|dcSy)Nr�r�)r�rr�)rJr��copieds   r r�zPlugin._get_dest_for_srcpath�sN�������n�n�W�-�G��'�'�	)�F��&��+�+��i�(�(�	)�r-c�@��t�fd�|jD��S)Nc3�J�K�|]}tj|�����y�wr��rr�)r��forbidr�s  �r r�z,Plugin._is_forbidden_path.<locals>.<genexpr>�s!�����
�'-�B�H�H�V�T�"�
��� #)rbr�r�s `r �_is_forbidden_pathzPlugin._is_forbidden_path�s#����
�15�1E�1E�
�
�	
r-c	��t|jjD�cgc]}tj||���c}�Scc}wr�)rbr�r�r�)rJr��fps   r �_is_policy_forbidden_pathz Plugin._is_policy_forbidden_path�s<���04���0K�0K�
�*,�G�O�O�D�"�%�
��	��
s�Ac�V�|jD]}tj||�s�yy)aCheck if the given path matches a user-provided specification to
        ignore collection of via the ``--skip-files`` option

        :param path:    The filepath being collected
        :type path: ``str``

        :returns: ``True`` if file should be skipped, else ``False``
        TF)r�r�)rJr��
_skip_paths   r �_is_skipped_pathzPlugin._is_skipped_path�s-���/�/�	�J����t�Z�0��	�r-c��tj|j�}tj|j�}|j}|j
j
||tj||��yr�)r��major�st_rdev�minorr6r��add_node�makedev)rJr�r7�dev_maj�dev_min�modes      r �
_copy_nodezPlugin._copy_node�sP���(�(�2�:�:�&���(�(�2�:�:�&���z�z�������d�D�"�*�*�W�g�*F�Gr-c��|jry|j|�r|jd|z�y|s|}|j�r|j	|�}	tj|�}tj|j�r|j|�ytj|j�rctj|t
j �r?|j#|�s|j$j'|�y|j)|�ytj*|j�sUtj|j�s6t-|�}|jd|�d|�d��|j/||�y|jd|�d	|�d��|jd
zs|j$j1d|�n|j$j3|||��|j4j7||dd
��y#ttf$r|jd|z�YywxYw)z�Copy file or directory to the destination tree. If a directory, then
        everything below it is recursively copied. A list of copied files are
        saved for use later in preparing a report.
        N�skipping forbidden path '%s'r#zfailed to stat '%s'z	creating z node at archive:'r�zcopying path 'z' to archive:'i$r��no)r�r�r�)r2rrr�r�r��lstatr�r�r}r1�S_ISLNKr6r�S_ISDIR�access�R_OKrr��add_dirr
�S_ISREGr:r"r��add_filer�rj)rJr�rr�r7�ntypes      r r�zPlugin._do_copy_path�s���
�����"�"�7�+��O�O�:�W�D�E����D������%�%�d�+�D�	����'�"�B�
�<�<��
�
�#����w�'���|�|�B�J�J�'�B�I�I�g�r�w�w�,G��|�|�G�,��L�L�(�(��.�����w�'�����R�Z�Z�(�D�L�L����,D��r�N�E��O�O�$�d�,�
-��O�O�D�"�%��	
���w��M�N��z�z�E�!��L�L�#�#�B��-��L�L�!�!�'�4�u�!�=���� � ����"
�	�	��Q��!�	��N�N�0�7�:�;��	�s�H�#H>�=H>c�.�t|t�r|g}|j�r|D�cgc]}|j|���}}|D]J}|j	d|z�d|vrtj|�}|jj|��Lycc}w)z�Specify a path, or list of paths, to not copy, even if it's part of
        an ``add_copy_spec()`` call

        :param forbidden: A filepath to forbid collection from
        :type forbidden: ``str`` or a ``list`` of strings
        zadding forbidden path '%s'r�N)	r�r�r�rr}r��	translater�rj)rJ�	forbiddenrrs    r �add_forbidden_pathzPlugin.add_forbidden_path�s����i��%�"��I�����4=�>�q�����*�>�I�>��	0�F��N�N�7�&�@�A��f�}�!�*�*�6�2��� � �'�'��/�
	0��?s�Bc��||jvr 	|j|j|�yy#t$r}|j|��d}~wwxYw)a`Set the named option to value. Ensure the original type of the
        option value is preserved

        :param optioname: The name of the option to set
        :type optioname: ``str``

        :param value: The value to set the option to

        :returns: ``True`` if the option is successfully set, else ``False``
        :rtype: ``bool``
        TNF)r�r�r�rv)rJ�
optionnamer��errs    r �
set_optionzPlugin.set_optionsU������%�
����Z�(�2�2�5�9�����
�����$���
�s�0�	A�A�Ac��d}||vrt|jd|�S||jvr+|j|}|r|j�|jS|S|S)amRetrieve the value of the requested option, searching in order:
        parameters passed from the command line, set via `set_option()`, or the
        global_plugin_options dict.

        `optionname` may be iterable, in which case this function will return
        the first match.

        :param optionname: The name of the option to retrieve the value of
        :type optionname: ``str``

        :param default: Optionally provide a default value to return if no
                        option matching `optionname` is found. Default 0

        :returns: The value of `optionname` if found, else `default`
        )�all_logsrqr/�journal_size�log_sizer-�since�verifyr�)rVr�r�r�)rJr4r��global_optionsr�s     r rszPlugin.get_optionsc��"
��
��'��4�<�<�
�6�
�C�C�����%��,�,�z�*�C��c�i�i�3��y�y� ��N��r-c�:�|jj|�yr�)r�r�)rJr�s  r �_add_copy_pathszPlugin._add_copy_paths7s�������z�*r-c��|D]}t||t�s�||g||<�!|jj|�y)a�Apply a tag to a file matching a given regex, for use when a file
        is copied by a more generic copyspec.

        :param tagdict: A dict containing the filepatterns to match and the
                        tag(s) to apply to those files
        :type tagdict: ``dict``

        `tagdict` takes the form `{file_pattern: tag}`, E.G. to match all bond
        devices from /proc/net/bonding with the tag `bond`, use
        `{'/proc/net/bonding/bond.*': ['bond']}`
        N)r�r��filetagsr�)rJ�tagdictrs   r �
add_file_tagszPlugin.add_file_tags:sE���	2�E��'�%�.�#�.�")�%�.�!1����	2�	
�
�
���W�%r-c��g}|jj�D]-\}}tj||�s�|j	|��/|S)aGet the tags that should be associated with a file matching a given
        regex

        :param fname:   A regex for filenames to be matched against
        :type fname: ``str``

        :returns:   The tag(s) associated with `fname`
        :rtype: ``list`` of strings
        )rArerr��extend)rJr�tagsr�r�s     r �get_tags_for_filezPlugin.get_tags_for_fileKsJ�����
�
�+�+�-�	!�H�C���x�x��U�#����C� �	!��r-c�F�|jD]�}|g|j|d�}g}|jD]?}tj||d�s�|j	|djd���A|s�i||d<|jjj	|���y)z�After file collections have completed, retroactively generate
        manifest entries to apply tags to files copied by generic copyspecs
        ��
specification�files_copiedrFr�r�r%rKN)rAr�rr�rjr�r�r
)rJ�
file_regex�
manifest_data�
matched_files�cfiles     r �generate_copyspec_tagszPlugin.generate_copyspec_tags[s����-�-�	:�J�!+� "��
�
�j�1��M�
�M��*�*�
G���8�8�J��i�(8�9�!�(�(��y�)9�)@�)@��)E�F�
G��0=�
�n�-��
�
�#�#�*�*�=�9�	:r-Tc�(
�������d�|jd�r|jd��tjd��tjd|jd�z��|j	|��s)|jd|�d|j
|���d	��y|�|jd
�}|jd�rd}|r|dz}|sy
t|t�r|g}t|t�r|g}d�}|D�]�}	|	rt|	�sy
|sA|j�r|j|	�}	|j|	�}
t|
�dk(r�V|	g}
g}t|
�dk(rA||
d�}|r|j|�|j|j|
d��|j|�tt!|��}|r�t|t�r|g}|D]�}
|j#|
�s�d
}|rUd|	z}|j%||
��}|ddk(r	t'|d�}||kDrd}n|j+d|	�d|
�d|d����n|j,j|
|	|||f�|jd|	�d|
�d�������d�������fd���s�rtt/�fd �|
��}
|
j1�d�!�d}d
}g}|
D�]�}||j2vr|j+d"|z��'|j5|�r|j+d#|z��M|j7|�r|j+d$|z��s|j9|�r|j+d%|z���|r|jd&|z���	t;j<|�t<j>}||z
}|r�||kDr�d}|s��tE|�r|jd(|z���	|jd)|z�||z|z
}|jFj||f�|j|jId*����d|j|jId*��|jK|g�|xr||k(}���|r��y|jLs���|jLjNj|	||d+�����y#t($r|jd|	�d|
�d��Y���wxYw#t@$r/|jC|�rd}n|jd'|z�Y��=Y��iwxYw),aAdd a file, directory, or globs matching filepaths to the archive

        :param copyspecs: Files, directories, or globs matching filepaths
        :type copyspecs: ``str`` or a ``list`` of strings

        :param sizelimit: Limit the total size of collections from `copyspecs`
                          to this size in MB
        :type sizelimit: ``int``

        :param maxage: Collect files with `mtime` not older than this many
                       hours
        :type maxage: ``int``

        :param tailit: Should a file that exceeds `sizelimit` be tail'ed to fit
                       the remaining space to meet `sizelimit`
        :type tailit: ``bool``

        :param pred: A predicate to gate if `copyspecs` should be collected
        :type pred: ``SoSPredicate``

        :param tags: A tag or set of tags to add to the metadata information
                     for this collection
        :type tags: ``str`` or a ``list`` of strings

        :param container: Container(s) from which this file should be copied
        :type container: ``str`` or a ``list`` of strings

        `copyspecs` will be expanded and/or globbed as appropriate. Specifying
        a directory here will cause the plugin to attempt to collect the entire
        directory, recursively.

        If `container` is specified, `copyspecs` may only be explicit paths,
        not globs as currently container runtimes do not support glob expansion
        as part of the copy operation.

        Note that `sizelimit` is applied to each `copyspec`, not each file
        individually. For example, a copyspec of
        ``['/etc/foo', '/etc/bar.conf']`` and a `sizelimit` of 25 means that
        sos will collect up to 25MB worth of files within `/etc/foo`, and will
        collect the last 25MB of `/etc/bar.conf`.
        Nr;z".*((\.(zip|gz|bz2|xz))|[-.][\d]+)$z^%s/*�etc�r�zskipped copy spec 'z' due to predicate (r_r:r8iFc��|jd�ry|jd�d}|jdd�}|jd�r|jdd�Sy)	z�Generate a tag to add for a single file copyspec

            This tag will be set to the filename, minus any extensions
            except for special extensions like .conf or .log, which will be
            mangled to _conf or similar.
            )z/procz/sysNr%r�-r$)z.confz.logz.txtr&)r��splitrp�endswith)r�_fnames  r �get_filename_tagz.Plugin.add_copy_spec.<locals>.get_filename_tag�s\����� 1�2���[�[��%�b�)�F��^�^�C��-�F����8�9��~�~�c�3�/�/�:r-rr0zstat -c %s )�	containerr�rBTzunable to determine size of 'z' in container 'z'. Skipping collection.z	stat of 'z' failed, skipping collection: zadded collection of '�' from container 'r�c�`�	tjj|�S#t$rYywxYw)Nr)r�r��getmtimer�)r�s r r]z&Plugin.add_copy_spec.<locals>.getmtimes.����7�7�+�+�D�1�1������s�!�	-�-c����j|���j|��ytj�|��}�r|�ks�rt�|z
�dzkryy)zp When --since is passed, or maxage is coming from the
                plugin, we need to filter out older files TiF)�searchr�
fromtimestampr)r��filetime�configfile_patternr]�logarchive_pattern�maxager;s  �����r �time_filterz)Plugin.add_copy_spec.<locals>.time_filtersb���
(�.�.�t�4�<�&�-�-�d�3�?��#�1�1�(�4�.�A���x�%�/����x��&��+� =� �r-c����|�Sr�r�)rres �r �<lambda>z&Plugin.add_copy_spec.<locals>.<lambda>s���k�!�n�r-)r��reversezskipping redundant file '%s'r$z#skipping policy forbidden path '%s'zskipping excluded path '%s'zskipping '%s' over size limitzfailed to stat '%s', skippingz@File '%s' is over size limit and is binary. Skipping collection.zQFile '%s' is over size limit, will instead tail the file during collection phase.r%rI)(rsrr�rr�r}r�r�r�r�r��_expand_copy_specrjrErGr�r��container_exists�exec_cmdr�r$rr��filter�sortr�rrrr�r1�ST_SIZEr�r
rr�r�r?r�r
)rJ�	copyspecs�	sizelimitrd�tailitr�rFrZrY�copyspecr
�
_spec_tags�_spec�con�_tailr?�ret�consize�current_size�
limit_reached�_manifest_files�_file�	file_size�add_sizerbr]rcr;res   `                    @@@@@r �
add_copy_speczPlugin.add_copy_specms9���V���?�?�7�#��O�O�G�,�E��Z�Z�(M�N���Z�Z��4�>�>�%�3H�(H�I���"�"��"�-��N�N�%�t�'9�'9�t�'9�'D�F�
G�������
�3�I��?�?�:�&��I����$�I����i��%�"��I��d�C� ��6�D�	0�"�`	�H���X�����#�#�%�#�~�~�h�7�H��.�.�x�8���u�:��?��!�
���J��5�z�Q��(��q��2����%�%�e�,��!�!�$�"8�"8��q��"B�C����d�#��c�*�o�.�J���i��-�!*��I�$�"�C��0�0��5� �!�E� �,�h�6��"�m�m�C�3�m�?���x�=�A�-�
)�*-�c�(�m�*<��#*�Y�#6�,0�E��!�O�O�$,�S�#�h�-�!A��
%��-�-�4�4��h�	�5�*�E���N�N�#�S�*��?"�L�
�
�
����V�$<�e�D�E���J�J�8�T�J�2��L�!�M� �O��6
N���D�O�O�+��O�O�$B�U�$J�K���*�*�5�1��O�O�$B�U�$J�K���1�1�%�8��O�O�$I�&+�%,�-���(�(��/��O�O�$A�E�$I�J�� ��N�N�#B�U�#J�K��	!� "�����t�|�|� <�I��	�)����	�!9�$(�M��)�%�0� �N�N�!7�9>�!?��%����@�BG�H��$-�y�#8�<�#G���-�-�4�4�e�X�5F�G�'�.�.�u�|�|�C�/@�A�$�*�*�5�<�<��+<�=��(�(�%��1�&/�%L�<�9�3L�M�m6
N�p��=�=��M�M�'�'�.�.�)1�(7� *�0��y`	��P$.�)� $���(0��%6�!"�
!)�
)��Z�!��'�'��.�$%�	����'F��'N�O� �"�	!�s$�R1�&S�1!S�S�1T�TrNc����g}t|t�r|g}t|t�r|g}t|j|�}|
r7t|
t�r|
g}
|D��cgc]�t	�fd�|
D��r���}}|r7t|t�r|g}|D��cgc]�t	�fd�|D��s���}}|j|�|j
|||||||||	||
|��ycc}wcc}w)a�Run a command or list of commands against devices discovered during
        sos initialization.

        Any commands specified by cmd will be iterated over the list of the
        specified devices. Commands passed to this should include a '%(dev)s'
        variable for substitution.

        :param cmds:    The command(s) to run against the list of devices
        :type cmds:     ``str`` or a ``list`` of strings

        :param devices: The device paths to run `cmd` against. This should be
                        either a list of devices/device paths or a key in the
                        devices dict discovered by sos during initialization.
        :type devices:  ``str`` or a ``list`` of devices or device paths.

        :param timeout: Timeout in seconds to allow each `cmd` to run
        :type timeout: ``int``

        :param sizelimit: Maximum amount of output to collect, in MB
        :type sizelimit: ``int``

        :param chroot: Should sos chroot the command(s) being run
        :type chroot: ``bool``

        :param runat: Set the filesystem location to execute the command from
        :type runat: ``str``

        :param env: Set environment variables for the command(s) being run
        :type env: ``dict``

        :param binary: Is the output collected going to be binary data
        :type binary: ``bool``

        :param prepend_path: The leading path for block device names
        :type prepend_path: ``str`` or ``None``

        :param whitelist: Limit the devices the `cmds` will be run against to
                          devices matching these item(s)
        :type whitelist: ``list`` of ``str``

        :param blacklist: Do not run `cmds` against devices matching these
                          item(s)
        :type blacklist: ``list`` of ``str``

        :param subdir:  Write the command output to this subdir within the
                        Plugin directory
        :type subdir:   ``str``
        c3�P�K�|]}tjd|z�����y�w�z(.*)?%sNr)r��wl�ds  �r r�z(Plugin.add_device_cmd.<locals>.<genexpr>�� �����I�����)�b�.�!�4�I���#&c3�P�K�|]}tjd|z�����y�wr�r)r��blr�s  �r r�z(Plugin.add_device_cmd.<locals>.<genexpr>�r�r�)
r�rp�chroot�runatr r��prepend_pathrF�priority�subdirN)r�r�rr�rbrE�_add_device_cmd)rJ�cmdsr�r�rpr�r�r r�r��	whitelist�	blacklistrFr�r��	_dev_tags�_devsr�s                 `r �add_device_cmdzPlugin.add_device_cmdfs���j�	��d�C� ��6�D��g�s�#��i�G�,�T�\�\�7�C����)�S�)�&�K�	� %�K�1��I�y�I�I��K�E�K���)�S�)�&�K�	� %�K�1��I�y�I�I��K�E�K�	��������T�5�'�'0��u�!$�V�,�"+�h�v�	�	O��K��Ks�C!�C&c
�*�t|t�r|g}t|t�r|g}|xs|jd�}|D]S}
|D]L}|g}|j|
�|	r|j	|	|�}|
d|iz}|j||||||||||��
�N�Uy)zCRun a command against all specified devices on the system.
        r:�dev)
r?r�rpr�r�r r�rFr�r�N)r�r�rsrEr�_add_cmd_output)rJr�r�r�rpr�r�r r�r�rFr�r�r?�devicer��_cmds                 r r�zPlugin._add_device_cmd�s���
�d�C� ��6�D��g�s�#��i�G��<�����!<�	��	4�C�!�

4��#�H�	�� � ��&��!�^�^�L�&�A�F��e�V�_�,���$�$��w�/8��+0�c�&�*3�h�,2�	%�4�

4�	4r-c��d|vr|jd�n
t|�}d|vrd|d<d|vrd|d<|jd�s|ddk(rd	|d
<tdi|��}|j	d|j�z�|jD]B}tj|j|�s�$|j	d|jz�y
|jd	|��r:|jj|�|jd|jz�y
|j|j||j��y
)z?Internal helper to add a single command to the collection list.r�r�rNr�Fr8rprT�to_filezpacked command: zskipping excluded command '%s'Nr�zadded cmd output '%s'�r�r�)�popr<rsr�rr]r�r�r?r�r�rjr}r�r�)rJr�r��soscmd�	_skip_cmds     r r�zPlugin._add_cmd_output�s(��%+�v�%5�v�z�z�&�!�<��;M���V�#�!#�F�:���F�"� %�F�9���?�?�:�&�&��*=��*B� $�F�9���%�f�%�����*�V�^�^�-=�=�>��+�+�	�I�
���v�z�z�9�5���� @�6�:�:� M�N��	����4�d��3����$�$�V�,��N�N�2�V�Z�Z�?�@�� � ����T�6�>�>� �Jr-c��t|t�r|g}t|�dkDr|s|r|jd�|
�|j	d�}
|�|jd��}|D]]}d}|r3|}||f}|j
||�}|s|jd|�d|�d	���:|j|||||||||	|
||||
|||||�
��_y)a-Run a program or a list of programs and collect the output

        Output will be limited to `sizelimit`, collecting the last X amount
        of command output matching `sizelimit`. Unless `suggest_filename` is
        set, the file that the output is saved to will match the command as
        it was executed, and will be saved under `sos_commands/$plugin`

        :param cmds: The command(s) to execute
        :type cmds: ``str`` or a ``list`` of strings

        :param suggest_filename: Override the name of the file output is saved
                                 to within the archive
        :type suggest_filename: ``str``

        :param root_symlink: If set, create a symlink with this name in the
                             archive root
        :type root_symlink: ``str``

        :param timeout: Timeout in seconds to allow each `cmd` to run for
        :type timeout: ``int``

        :param stderr: Should stderr output be collected
        :type stderr: ``bool``

        :param chroot: Should sos chroot the `cmds` being run
        :type chroot: ``bool``

        :param runat: Run the `cmds` from this location in the filesystem
        :type runat: ``str``

        :param env: Set environment variables for the `cmds` being run
        :type env: ``dict``

        :param binary: Is the command expected to produce binary output
        :type binary: ``bool``

        :param sizelimit: Maximum amount of output in MB to save
        :type sizelimit: ``int``

        :param pred: A predicate to gate if `cmds` should be collected or not
        :type pred: ``SoSPredicate``

        :param subdir: Save output to this subdirectory, within the plugin's
                       directory under sos_commands
        :type subdir: ``str``

        :param changes: Do `cmds` have the potential to change system state
        :type changes: ``int``

        :param foreground: Should the `cmds` be run in the foreground, with an
                           attached TTY
        :type foreground: ``bool``

        :param tags: A tag or set of tags to add to the metadata entries for
                     the `cmds` being run
        :type tags: ``str`` or a ``list`` of strings

        :param priority:  The priority with which this command should be run,
                          lower values will run before higher values
        :type priority: ``int``

        :param cmd_as_tag: Should the command string be automatically formatted
                           to a tag?
        :type cmd_as_tag: ``bool``

        :param container: Run the specified `cmds` inside a container with this
                          ID or name
        :type container:  ``str``

        :param to_file: Should command output be written directly to a new
                        file rather than stored in memory?
        :type to_file:  ``bool``
        r0z.ambiguous filename or symlink for command listNr:T)r?zSkipping command 'z' as the requested container 'z' does not exist.)r?�suggest_filename�root_symlinkr��stderrr�r�r r�rpr�r�rFr��
foregroundr��
cmd_as_tagr��
container_cmd)	r�r�r�rzrsr��fmt_container_cmdrr�)rJr�r�r�r�r�r�r�r r�rpr�r�r�r�rFr�r�rZr�r?r��ocmds                       r �add_cmd_outputzPlugin.add_cmd_output�s���`�d�C� ��6�D��t�9�q�=�.�,��N�N�K�L������
�3�I��<��%�%�$�%�/�D��	O�C� �M����!%�y� 1�
��,�,�Y��<����O�O�'+�Y�%8�9��� � �S�;K�.:�G�(.�v�U�%(��9�&*�6��)0�Z�*2�z�)0�
�
!�
O�	Or-c��|D]}t||t�s�||g||<�!|jj|�y)a�Retroactively add tags to any commands that have been run by this
        plugin that match a given regex

        :param tagdict: A dict containing the command regex and associated tags
        :type tagdict: ``dict``

        `tagdict` takes the form of {cmd_regex: tags}, for example to tag all
        commands starting with `foo` with the tag `bar`, use
        {'foo.*': ['bar']}
        N)r�r��cmdtagsr�)rJrBr?s   r �add_cmd_tagszPlugin.add_cmd_tagsSsD���	.�C��'�#�,��,� '���~����	.�	
�����G�$r-c�~�|jj�D]\}}tj||�s�|cSgS)z�Get the tag(s) that should be associated with the given command

        :param cmd: The command that tags should be applied to
        :type cmd: ``str``

        :returns: Any tags associated with the command
        :rtype: ``list``
        )r�rerr�)rJr?r�r�s    r �get_tags_for_cmdzPlugin.get_tags_for_cmdcs>�����*�*�,�	�H�C���x�x��S�!��
�	��	r-c�
�tjj|jj	�d|j��}|r tjj||�}|rtj|d��|S)a�Get the path where this plugin will save command output

        :param name: Optionally specify a filename to use as part of the
                     command output path
        :type name: ``str`` or ``None``

        :param make: Attempt to create the command output path
        :type make: ``bool``

        :returns: The path where the plugin will write command output data
                  within the archive
        :rtype: ``str``
        �sos_commandsT)�exist_ok)r�r�rEr�r�r��makedirs)rJr��make�cmd_output_paths    r �get_cmd_output_pathzPlugin.get_cmd_output_pathqs_���'�'�,�,�t�|�|�'?�'?�'A�'5�t�y�y�{�D��� �g�g�l�l�?�D�A�O���K�K��$�7��r-c��t|g|���S)aMGrep through file(s) for a specific string or regex

        :param regexp: The string or regex to search for
        :type regexp: ``str``

        :param fnames: Paths to grep through
        :type fnames: ``str``, ``list`` of string, or open file objects

        :returns: Lines matching `regexp`
        :rtype: ``str``
        )r)rJr��fnamess   r �	file_grepzPlugin.file_grep�s���F�$�V�$�$r-c�N�|jj�}t||�Sr�)r�r*r,)rJr�r*s   r r,zPlugin._mangle_command�s!���<�<�(�(�*���s�H�-�-r-c��|j�}|r|d|zz
}tjj|jd|�}|j|�}tjj
tjj|jj�||��r�d}|jj�}	d|z}|}	|t|	�t|�zkr|	d|t|	�z
t|�z
}	|	|z}	tjj
tjj|jj�||	��s|	}n|dz
}��tjj||�S)z@The internal function to build up a filename based on a command.z/%sr�r0z.%dN)r�r�r�rEr�r,�existsr�r�r*r�)
rJr�r��
plugin_dir�outdir�outfn�incr*rM�newfns
          r �_make_command_filenamezPlugin._make_command_filename�sI���Y�Y�[�
���%�&�.�(�J������d�l�l�8�4�j�A���$�$�S�)���7�7�>�>�"�'�'�,�,�t�|�|�'?�'?�'A�'-�u�6�7��C��|�|�,�,�.�H���������c�%�j��V��4�4�!�"D�H�S��Z�$7��F��$C�E�E������w�w�~�~�b�g�g�l�l�4�<�<�3K�3K�3M�39�5�'B�C�!�E���q�����w�w�|�|�F�E�*�*r-c��t|t�s|g}|D]<}|jj||j	�|j�g��>y)a�Add an environment variable to the list of to-be-collected env vars.

        Collected environment variables will be saved to an `environment` file
        in the archive root, and any variable specified for collection will be
        collected in lowercase, uppercase, and the form provided

        :param name: The name of the environment variable to collect
        :type name: ``str``
        N)r�r�r�r��upperr9)rJr�r s   r �add_env_varzPlugin.add_env_var�sM���$��%��6�D��	C�C�
�N�N�!�!�3��	�	��S�Y�Y�[�"A�B�		Cr-c�h�|jd|��s%|jd|j|��z�y|rdnd}tjj||j
�|�}t|t�r|g}|jj|||f�|jd|z�y)	a�Add a string to the archive as a file

        :param content: The string to write to the archive
        :type content: ``str``

        :param filename: The name of the file to write `content` to
        :type filename: ``str``

        :param pred: A predicate to gate if the string should be added to the
                     archive or not
        :type pred: ``SoSPredicate``

        :param plug_dir: Should the string be saved under the plugin's dir in
                         sos_commands/? If false, save to sos_strings/
        :type plug_dir: ``bool``

        :param tags: A tag or set of tags to add to the manifest entry for this
                     collection
        :type tags: ``str`` or a ``list`` of strings
        Fr�z$skipped string due to predicate (%s)rSNr��sos_stringszadded string as '%s')r�r}r�r�r�rEr�r�r�r�rjr)rJr��filenamer��plug_dirrF�sos_dirs       r �add_string_as_filezPlugin.add_string_as_file�s���.�"�"�u�4�"�8��N�N�A� �.�.�D�.�9�;�
<��$,�.�-���7�7�<�<������h�?���d�C� ��6�D���� � �'�8�T�!:�;����.��9�:r-c
��
�|jry|�|j}g}t|t�r|g}|j	|�|j	|j|��|r&|j
tjdd|��tt|��}|j|�}|s|jdjdk(r
|j}nd}|r|j||�}n|j||�}|t!|jd�dzd}|rm|j#d|z�|j$j'|t(�t*j,j/|j$j1�|�}nd	}t3�}t5|||||||	|
|j6|
|�
�}t3�}||z
}|ddk(r4d
||fz}|j9|�|rd|z}|j#|�|���|j;d�d|j;d�dd||r|nd|d|d|||||d�}|ddk(s|ddk(r�|ru|dk7rp|jdjdk7rT|j=d|j;�d�d|�d��t5||d	|||	|
|j6|��	}t3�|z
}|j#d|z�|ddvr3|j>r'|j>j@j
|�|S|j#d|j;�d�d|�d|�d��|dr<|j=d |j;�dz�|} |jCd!d"�d#z}|sA|	r |j$jE|d$|�n|j$jG|d$|�|dr�t*j,j/|j$j1�|�}!t*j,j/|j$j1� �}"t*j,jI|!|"�}#|#jCd%d&d�}#|j$jK|#| �|r|j$jK||�|jLj
|||	rd'nd(d)��|r8t*j,j/|j$j1�|�nd&|d*<|j>rQ||d+<||d,<|j>j@j
|�|r |jO|jQ�|�|S)-a�Execute a command and save the output to a file for inclusion in the
        report.

        Positional Arguments:
            :param cmd:                 The command to run

        Keyword Arguments:
            :param suggest_filename:    Filename to use when writing to the
                                        archive
            :param root_symlink:        Create a symlink in the archive root
            :param timeout:             Time in seconds to allow a cmd to run
            :param stderr:              Write stderr to stdout?
            :param chroot:              Perform chroot before running cmd?
            :param runat:               Run the command from this location,
                                        overriding chroot
            :param env:                 Dict of env vars to set for the cmd
            :param binary:              Is the output in binary?
            :param sizelimit:           Maximum size in MB of output to save
            :param subdir:              Subdir in plugin directory to save to
            :param changes:             Does this cmd potentially make a change
                                        on the system?
            :param foreground:          Run the `cmd` in the foreground with a
                                        TTY
            :param tags:                Add tags in the archive manifest
            :param cmd_as_tag:          Format command string to tag
            :param to_file:             Write output directly to file instead
                                        of saving in memory

        :returns:       dict containing status, output, and filename in the
                        archive for the executed cmd

        Nz[^\w\.]+r$r��alwaysr�r0z'collecting '%s' output directly to diskF)
r�r�r��chdirr r�rp�pollerr�r�r��|z command '%s' timed out after %dsz5 - output up until the timeout may be available at %sr�r�	truncated)r)�
parameters�exec�filepathr��return_coder�rrrrF�~�r%z	command 'z' not found in z - re-trying in host root)r�r�r�r r�rpr�r�z%could not run '%s': command not found)r�r�zcollected output of 'z' in z
 (changes=r_z&collected output of '%s' was truncatedr�r��.tailedrBz../r#r�r%)r?r�r�r�r�r))r2rr�r�rEr�rjrr'r�r�r"r�r�r�r�r�rr��
check_pathrr�r�rE�get_archive_pathrrr6rzrVr}r�rrp�
add_binaryr�r�r�r��_add_container_cmd_to_manifestr)$rJr?r�r�r�r�r�r�r r�rpr�r�r�rFr�r�r�r��_tagsr!�rootr��outfn_strip�out_filer�r��endr�warnr��manifest_cmd�linkfn�_outfn_path�
_link_path�rpaths$                                    r �_collect_cmd_outputzPlugin._collect_cmd_output�s���N�����?��o�o�G����d�C� ��6�D�
���T��
���T�*�*�3�/�0���L�L�����S�#�6�7��S��Z� ���(�(��-���T�\�\�-�0�7�7�8�C��<�<�D��D���/�/�0@�&�I�E��/�/��V�<�E��C����X� 6�7��9�:�;����O�O�E�!�"�
#��L�L�#�#�E�6�2��w�w�|�|�D�L�L�$A�$A�$C�U�K�H��H����'������T�&�I��%�%�*��	
���f����;���(��s�"�5��g��F�D��N�N�4� ���#�$�����$�� 4�5��y�y��~�a�(��)�)�C�.���,��!(��d���,�!�(�+� ��� ��
���(��s�"�f�X�&6�#�&=������<�<�
�.�5�5��A��N�N�&)�i�i�k�!�n�d�$<�=�4��W�U�%���)�#�1�1�8��F�
 $�v��~�H��O�O�C�c�I�J��h��:�-��=�=��M�M�*�*�1�1�,�?�!�M�����9�9�;�q�>�8�W�>�	?��+���N�N�C� �Y�Y�[��^�,�
-��F��M�M�.�-�@�9�L�E������'�'��x�(8�%�@����'�'��x�(8�%�@��+���'�'�,�,�t�|�|�'D�'D�'F��N�K������d�l�l�&C�&C�&E�v�N�J��G�G�O�O�K��<�E��M�M�%��Q�/�E��L�L�!�!�%��0���L�L�!�!�%��6�	
���%�%�c�;�:@��d�'L�	M�EJ�B�G�G�L�L����6�6�8�%�@��	�z��
�=�=�',�L��$�'/�L��$��M�M�"�"�)�)�,�7���3�3�L�4E�4E�4G�4A�C��
r-c��|jd|��s|j|||��dddd�S|j|||||||||	|
|
||��
S)a}Execute a command and save the output to a file for inclusion in the
        report, then return the results for further use by the plugin

        :param cmd:                 The command to run
        :type cmd: ``str``

        :param suggest_filename:    Filename to use when writing to the
                                    archive
        :param suggest_filename: ``str``

        :param root_symlink:        Create a symlink in the archive root
        :type root_symlink: ``bool``

        :param timeout:             Time in seconds to allow a cmd to run
        :type timeout: ``int``

        :param stderr:              Write stderr to stdout?
        :type stderr: ``bool``

        :param chroot:              Perform chroot before running cmd?
        :type chroot: ``bool``

        :param runat:               Run the command from this location,
                                    overriding chroot
        :type runat: ``str``

        :param env:                 Environment vars to set for the cmd
        :type env: ``dict``

        :param binary:              Is the output in binary?
        :type binary: ``bool``

        :param sizelimit:           Maximum size in MB of output to save
        :type sizelimit: ``int``

        :param subdir:              Subdir in plugin directory to save to
        :type subdir: ``str``

        :param changes:             Does this cmd potentially make a change
                                    on the system?
        :type changes: ``bool``

        :param foreground:          Run the `cmd` in the foreground with a TTY
        :type foreground: ``bool``

        :param tags:                Add tags in the archive manifest
        :type tags: ``str`` or a ``list`` of strings

        :returns:       `cmd` exit status, output, and the filepath within the
                        archive output was saved to
        :rtype: ``dict``
        Tr�r�Nr#)r�rBr�)r�r�r�r�r�r�r r�rpr�r�rF)r�r�r�)rJr?r�r�r�r�r�r�r r�rpr�r�r�r�rFs                r �collect_cmd_outputzPlugin.collect_cmd_output�	sy��t�"�"�t�$�"�7�� � ��d�G� �<�����
��'�'��"2���F�6���F�i�J���	(�
�	
r-c
���ddd�}|jd|��s|S|�|j}|s|jdjdk(r
|j}
nd}
|j|�}|
rg|j
��|jd|�d	|
�d
��|S|j|
�r|j|
||�}n|jd|�d	|
�d��t|||
||||	|��S)
a=Execute a command right now and return the output and status, but
        do not save the output within the archive.

        Use this method in a plugin's setup() if command output is needed to
        build subsequent commands added to a report via add_cmd_output().

        :param cmd:                 The command to run
        :type cmd: ``str``

        :param timeout:             Time in seconds to allow a cmd to run
        :type timeout: ``int``

        :param stderr:              Write stderr to stdout?
        :type stderr: ``bool``

        :param chroot:              Perform chroot before running cmd?
        :type chroot: ``bool``

        :param runat:               Run the command from this location,
                                    overriding chroot
        :type runat: ``str``

        :param env:                 Environment vars to set for the cmd
        :type env: ``dict``

        :param binary:              Is the output in binary?
        :type binary: ``bool``

        :param pred:                A predicate to gate execution of the `cmd`
        :type pred: ``SoSPredicate``

        :param foreground:          Run the `cmd` in the foreground with a TTY
        :type foreground: ``bool``

        :param container:           Execute this command in a container with
                                    this name
        :type container: ``str``

        :param quotecmd:            Whether the cmd should be quoted.
        :type quotecmd: ``bool``

        :returns:                   Command exit status and output
        :rtype: ``dict``
        Nr#)r�rBTr�r�r�zCannot run cmd 'z' in container z: no runtime detected on host.z: no such container is running.)r�r�r�r�r r�r�)r�rr�r�r�r"�_get_container_runtimer}rjr�r)rJr?r�r�r�r�r r�r�r�rZ�quotecmd�_defaultr�r!s               r rkzPlugin.exec_cmd�	s���^#�b�1���"�"�t�$�"�7��O��?��o�o�G��T�\�\�-�0�7�7�8�C��<�<�D��D��(�(��-����*�*�,�4����>A�9� N�O����$�$�Y�/��,�,�Y��X�F�����:=�y� J�K�&�c�7�4�,1�&�d�1;�F�L�	Lr-c���||jjvrggd�|jj|<|jj|dj|||d��y)aAdds a file collection to the manifest for a particular container
        and file path.

        :param container:   The name of the container
        :type container:    ``str``

        :param path:        The filename from the container filesystem
        :type path:         ``str``

        :param arcpath:     Where in the archive the file is written to
        :type arcpath:      ``str``

        :param tags:        Metadata tags for this collection
        :type tags:         ``str`` or ``list`` of strings
        �r
rr
rIN)r�rrj)rJrZr��arcpathrFs     r �_add_container_file_to_manifestz&Plugin._add_container_file_to_manifest5
s_�� �D�M�M�4�4�4�<>�B�2O�D�M�M�$�$�Y�/��
�
� � ��+�G�4�;�;�!�#��=
�	r-c�F�|\}}||jjvrggd�|jj|<||d<|jd�d|d<|jd�dd|d<d	|�d
|j���}d|dz}|j	|�}|�d
|��}|j
j
|t�r/tj||j
j|��||d<|jj|dj|�y)a�Adds a command collection to the manifest for a particular container
        and creates a symlink to that collection from the relevant
        sos_containers/ location

        :param manifest:    The manifest entry for the command
        :type manifest:     ``dict``

        :param contup:      A tuple of (original_cmd, container_name)
        :type contup:       ``tuple``
        r�r�r�rr)r0Nr��sos_containers/z/sos_commands/z../../../../%sr�r%r)r�rrVr�r,r�r�rr�r��	dest_pathrj)	rJr��contupr?rZ�_cdir�_outloc�cmdfn�conlnks	         r r�z%Plugin._add_container_cmd_to_manifestM
s
�� ���Y��D�M�M�4�4�4�<>�B�2O�D�M�M�$�$�Y�/�����!�i�i��n�Q�/����!$���3����!3����7@�$�)�)�+�N��"�X�j�%9�9���$�$�S�)��!�5�)��
�<�<�"�"�6�6�2��J�J�w���� 6� 6�v� >�?�%�����
�
� � ��+�J�7�>�>�x�Hr-c�,�|�@d|jjj�vr|jjdSyt|jjj��D]"}||k(s�	|jj|cSy)zjBased on policy and request by the plugin, return a usable
        ContainerRuntime if one exists
        Nr�)r��runtimes�keysr�)rJ�runtime�pol_runtimes   r r�zPlugin._get_container_runtimen
s����?��D�K�K�0�0�5�5�7�7��{�{�+�+�I�6�6�
� $�D�K�K�$8�$8�$=�$=�$?�@�
=���k�)��;�;�/�/��<�<�
=�r-c�t�|j�}|�&|j|�xs|j|�duSy)a6If a container runtime is present, check to see if a container with
        a given name is currently running

        :param name:    The name or ID of the container to check presence of
        :type name: ``str``

        :returns: ``True`` if `name` exists, else ``False``
        :rtype: ``bool``
        NF)r�rj�get_container_by_name�rJr��_runtimes   r rjzPlugin.container_exists{
sH���.�.�0�����-�-�d�3�E��2�2�4�8��D�
F�r-c��|j�}|�<|j|��}|D�cgc]}tj||d�s�|�� c}SgScc}w)a�Get a list of all container names and ID matching a regex

        :param regex:   The regular expression to match
        :type regex:    ``str``

        :param get_all: Return all containers found, even terminated ones
        :type get_all:  ``bool``

        :returns:   All container IDs and names matching ``regex``
        :rtype:     ``list`` of ``tuples`` as (id, name)
        ��get_allr0)r��get_containersrr�)rJrrr�_containersrFs      r �get_all_containers_by_regexz"Plugin.get_all_containers_by_regex�
sX���.�.�0����"�1�1�'�1�B�K�*�D�!�b�h�h�u�a��d�.C�A�D�D��	��Es�A�Ac�J�|j�}|�|j|�Sy)z�Get the container ID for a specific container

        :param name:    The name of the container
        :type name: ``str``

        :returns: The ID of the container if it exists
        :rtype: ``str`` or ``None``
        N)r�rrs   r rzPlugin.get_container_by_name�
s,���.�.�0�����1�1�$�7�7�r-c�n�|j|��}|� |r|jd��S|jSgS)a\Return a list of all container IDs from the ``Policy``
        ``ContainerRuntime``

        If `runtime` is not provided, use the ``Policy`` default

        :param runtime:     The container runtime to use, if not the default
                            runtime detected and loaded by the ``Policy``
        :type runtime: ``str``

        :param get_all:     Return all containers known to the `runtime`, even
                            those that have terminated
        :type get_all: ``bool``

        :returns: All container IDs found by the ``ContainerRuntime``
        :rtype: ``list``
        �r�Tr)r�rr)rJr�rrs    r rzPlugin.get_containers�
sE��"�.�.�w�.�?������.�.�t�.�<�<��*�*�*��	r-c�F�|j|��}|�|jSgS)a�Return a list of all image names from the Policy's
        ContainerRuntime

        If `runtime` is not provided, use the Policy default. If the specified
        `runtime` is not loaded, return empty.

        :param runtime:     The container runtime to use, if not using the
                            default runtime detected by the ``Policy``
        :type runtime: ``str``

        :returns: A list of container images known to the `runtime`
        :rtype: ``list``
        r)r��images�rJr�rs   r �get_container_imageszPlugin.get_container_images�
s,���.�.�w�.�?�����?�?�"��	r-c�F�|j|��}|�|jSgS)a�Return a list of all volume names from the Policy's
        ContainerRuntime

        If `runtime` is not provided, use the Policy default. If the specified
        `runtime` is not loaded, return empty.

        :param runtime:     The container runtime to use, if not using the
                            default runtime detected by the ``Policy``
        :type runtime: ``str``

        :returns: A list of container volumes known to the `runtime`
        :rtype: ``list``
        r)r��volumesrs   r �get_container_volumeszPlugin.get_container_volumes�
s.���.�.�w�.�?�����#�#�#��	r-c���|j�}|�[t|t�r|g}|D]B}|j||�}|D])}|j	|d�}|j
|fi|���+�Dyy)a�Helper to get the ``logs`` output for a given container or list
        of container names and/or regexes.

        Supports passthru of add_cmd_output() options

        :param containers:   The name of the container to retrieve logs from,
                             may be a single name or a regex
        :type containers:    ``str`` or ``list`` of strs

        :param get_all:     Should non-running containers also be queried?
                            Default: False
        :type get_all:      ``bool``

        :param kwargs:      Any kwargs supported by ``add_cmd_output()`` are
                            supported here
        Nr0)r�r�r�r�get_logs_commandr�)	rJrrr�rrZ�_cons�_conr?s	         r �add_container_logszPlugin.add_container_logs�
s���"�.�.�0�����*�c�*�(�\�
�'�
7�	��8�8��G�L��!�7�D�"�3�3�D��G�<�C�'�D�'�'��6�v�6�7�
7� r-c�l�|j|�r#|j�}|j|||�Sy)a@Format a command to be executed by the loaded ``ContainerRuntime``
        in a specified container

        :param container:   The name of the container to execute the `cmd` in
        :type container: ``str``

        :param cmd:         The command to run within the container
        :type cmd: ``str``

        :param quotecmd:    Whether the cmd should be quoted.
        :type quotecmd: ``bool``

        :returns: The command to execute so that the specified `cmd` will run
                  within the `container` and not on the host
        :rtype: ``str``
        r#)rjr�r�)rJrZr?r�rs     r r�zPlugin.fmt_container_cmds8��"� � ��+��2�2�4�H��-�-�i��h�G�G�r-c�2�||jjvS)aDetermine whether specified module is loaded or not

        :param module_name: Name of kernel module to check for presence
        :type module_name: ``str``

        :returns: ``True`` if the module is loaded, else ``False``
        :rtype: ``bool``
        )r�rB)rJ�module_names  r rtzPlugin.is_module_loadeds���d�k�k�5�5�5�5r-c�:�|jj|�y)z�Add an alert to the collection of alerts for this plugin. These
        will be displayed in the report

        :param alertstring: The text to add as an alert
        :type alertstring: ``str``
        N)r�rj)rJ�alertstrings  r �	add_alertzPlugin.add_alert's��	
�����;�'r-c�.�|xj|z
c_y)z�Append text to the custom text that is included in the report. This
        is freeform and can include html.

        :param text:    The text to include in the report
        :type text:     ``str``
        N)r�)rJ�texts  r �add_custom_textzPlugin.add_custom_text0s��	
���D� �r-c���t|t�r|g}|jjj}|s|jd�y|D]}|j|�d|��fi|���y)aRCollect service status information based on the ``InitSystem`` used

        :param services: Service name(s) to collect statuses for
        :type services: ``str`` or a ``list`` of strings

        :param kwargs:   Optional arguments to pass to add_cmd_output
                         (timeout, predicate, suggest_filename,..)

        zFCannot add service output, policy does not define an InitSystem to useNr�)r�r�r�r��	query_cmdrr�)rJrFr��query�services     r �add_service_statuszPlugin.add_service_status9sl���h��$� �z�H����'�'�1�1����O�O�4�
5���	F�G��D���5�'� :�E�f�E�	Fr-c�*�d}d}d}d}d}d}d}d}d	}|d
k(s|jd�rd
}n|xs|jd�}t|t�r|g}t|
t�r|
g}
n|
sg}
|r#|D]}|||zz
}|
jd
|z�� |	r|||	zz
}|
r||z
}|r|dz
}|r|dk(rd}|dk(rd}|||zz
}|r|||zz
}|r|||zz
}|r|||zz
}|r|||zz
}|j	d|z�|j|||||
|��y)a9Collect journald logs from one of more units.

        :param units:   Which journald units to collect
        :type units: ``str`` or a ``list`` of strings

        :param boot:    A boot index using the journalctl syntax. The special
                        values 'this' and 'last' are also accepted.
        :type boot: ``str``

        :param since:   Start time for journal messages
        :type since: ``str``

        :param until:   End time forjournal messages
        :type until: ``str``

        :param lines: The maximum number of lines to be collected
        :type lines: ``int``

        :param allfields: Include all journal fields regardless of size or
                          non-printable characters
        :type allfields: ``bool``

        :param output:  Journalctl output control string, for example "verbose"
        :type output: ``str``

        :param timeout: An optional timeout in seconds
        :type timeout: ``int``

        :param identifier: An optional message identifier
        :type identifier: ``str``

        :param catalog: Augment lines with descriptions from the system catalog
        :type catalog: ``bool``

        :param sizelimit: Limit to the size of output returned in MB.
                          Defaults to the value of --log-size.
        :type sizelimit: ``int``
        zjournalctl --no-pager z
 --unit %sz
 --boot %sz
 --since '%s'z --until %sz --lines %sz --output %sz --identifier %sz
 --catalogrr8r9z
journal_%sz --all�thisr#�lastz-1zcollecting journal: %s)r?r�rpr�rFr�N)rsr�r�rjrr�)rJ�units�bootr;�until�lines�	allfieldsrBr��
identifier�catalogrpr�rFr��journal_cmd�unit_opt�boot_opt�	since_opt�	until_opt�	lines_opt�
output_opt�identifier_opt�catalog_optr:�units                          r �add_journalzPlugin.add_journalPs���T/������#�	�!�	�!�	�#�
�+��"����>�T�_�_�Z�8��H� �C�D�O�O�N�$C�H��e�S�!��G�E��d�C� ��6�D���D���
1���x�$��.�����L�4�/�0�
1���>�J�6�6�K���;�&�K���8�#�K���v�~����v�~����8�d�?�*�K���9�u�,�,�K���9�u�,�,�K���9�u�,�,�K���:��.�.�K����0�;�>�?�����g�'/�d��&.�	�	0r-c	�^�����fd��tj|tj�r4�j|�r#�j	|�r�j|d�}t
j|d��}g}|D]k}	�j|�rW�j	|�rF|j|�|j�tjj|d����m|j|�tt|��S#t$r|j|�Y��wxYw)Nc	���g}tj|�}|D]�}	�j|�s�j|�r|j|�n[�j	|�r9�j|�r(|j
��j|d���n|j|���tt|��S#t$rY��wxYw)Nr�)�globrr
rjrrrEr�PermissionErrorr�r�)r��found_pathsr��_Plugin__expandrJs   ��r �__expandz*Plugin._expand_copy_spec.<locals>.__expand�s�����K��I�I�e�$�E��
����'�'��-��1A�1A�$�1G�#�*�*�4�0�����.�4�<�<��3E�#�*�*�8�D�N�N�4��4M�+N�O�#�*�*�4�0��
�"��K�(�)�)��'����s�BC�	C�Cr�T)�	recursive)r�r)r*rrrr=�removerEr�rEr>r�r�)rJrr�expanded�recursed_files�_pathr@s`    @r rizPlugin._expand_copy_spec�s����	*�,
�I�I�h����(�T�_�_�X�-F����X�&��~�~�h��4�H��9�9�X��6�����	'�E�

'��?�?�5�)�d�l�l�5�.A��O�O�E�*�"�)�)�(�2�7�7�<�<��s�3K�*L�M��
	'�	����'��C��M�"�"��
#�
'�����&�	
'�s�A(D�D,�+D,c��t|jd��D]'}|jd|z�|j|��)|j	�y)NT)rhzcollecting path '%s')r�r�r}r�rPr�s  r �_collect_copy_specszPlugin._collect_copy_specs�sJ���4�?�?�D�9�	%�D��N�N�1�D�8�9����t�$�	%�	
�#�#�%r-c
��|jsy|j�}|s|jd�y|j�s|jd�y|jD]�}|\}}}}}|jd|�d|�d��d|�d|j	d���}|j
j
|t�|j
j|�}	|j|||	|r|nd�	�}
|j|
d
��}|dd
k(r6|r|j
j|d|�|j||||���|jd|�d|�d|d�����y)a?Copy any requested files from containers here. This is done
        separately from normal file collection as this requires the use of
        a container runtime.

        This method will iterate over self.container_copy_paths which is a set
        of 5-tuples as (container, path, sizelimit, stdout, tags).
        NzDCannot collect container based files - no runtime is present/active.zYLoaded runtime '%s' does not support copying files from containers. Skipping collections.zcollecting 'r[r�r�r%)rprN)r�r�rrBzerror copying 'r�)
r�r�r}�check_can_copyr�r�r�rr��get_copy_commandrkr�r�)rJ�rtr�rur�rprqrF�arcdestr�cpcmd�cprets            r �_collect_container_copy_specsz$Plugin._collect_container_copy_specs�sW���(�(��
�
(�
(�
*����N�N�0�
1��� � �"��N�N�J�
K���/�/�	?�F�17�.�C��y�&�$��N�N�D�#�N�O�03�T�[�[��5E�F�G��L�L�#�#�G�V�4��<�<�)�)�'�2�D��'�'��T�4��9�D�(��E��M�M�%��M�4�E��X��!�#���L�L�+�+�E�(�O�W�E��4�4�S�$���N����"&��U�8�_� >�?�)	?r-c��|jjd���|jD]^}|jd|j�z�|j	d|j
z�|jdi|j���`y)Nc��|jSr�)r�)�xs r rgz&Plugin._collect_cmds.<locals>.<lambda>s
��Q�Z�Z�r-)r�zunpacked command: zcollecting output of '%s'r�)r�rmrr]r}r?r�r�)rJr�s  r �
_collect_cmdszPlugin._collect_cmdssu�������#7��8��'�'�	8�F��O�O�0�6�>�>�3C�C�D��N�N�6����C�D�$�D�$�$�7�v���7�	8r-c�l�|jD�]$\}}|jd|�d��|}|dtjk(r|j	tj�}|jtjjd�dz}|jt||�|�tjjdtjj|��}tjj|d|j�|�}|jj||���'y)Nzcollecting tail of 'z' due to size limitrr&r�r%r�)r�r}r�r�r�rpr�r�rr�r�rEr�r�r�)rJr|re�	file_name�strfile�rel_path�	link_paths       r �_collect_tailed_fileszPlugin._collect_tailed_filess��� �1�1�	4�L�E�5��N�N�1�%��8K�L�M��I���|�r�v�v�%�%�,�,�R�V�V�4�	��!�!�"�'�'�+�+�s�3�i�?�
�
�#�#�D���$6��@��w�w���s�B�G�G�O�O�E�,B�C�H������X�}�%)�Y�Y�[�'�;�I��L�L�!�!�)�U�3�	4r-c��|jD]�\}}}|jry|jd|z�	|jj	||�|jd�dj
dd�}||d�|jj|<��y#t$r!}|jd|�d|���Yd}~��d}~wwxYw)	Nzcollecting string as '%s'r%rr&r$)r�rFzcould not add string 'r�)r�r2r}r�r�rVrpr�rr�r)rJ�stringrVrF�_namer�s      r �_collect_stringszPlugin._collect_strings*s���'+�'8�'8�
	2�#�F�I�t�� � ���N�N�6��B�C�	
2����'�'��	�:�!����,�R�0�8�8��c�B��%� �0��
�
�%�%�e�,�
	2���
2����#,�a�!1�2�2��
2�s�AB�	C�B;�;Cc�z�	|j�y#t$r}|jd|���Yd}~yd}~wwxYw)a�Kick off manual collections performed by the plugin. These manual
        collections are anything the plugin collects outside of existing
        files and/or command output. Anything the plugin manually compiles or
        constructs for data that is included in the final archive.

        Plugins will need to define these collections by overriding the
        ``collect()`` method, similar to how plugins define their own
        ``setup()`` methods.
        z!Error during plugin collections: N)�collectr�rv)rJr5s  r �_collect_manualzPlugin._collect_manual:s:��	G��L�L�N���	G��O�O�?��u�E�F�F��	G�s��	:�5�:c��y)aCIf a plugin needs to manually compile some data for a collection,
        that should be specified here by overriding this method.

        These collections are run last during a plugin's execution, and as such
        are more likely to be interrupted by timeouts than file or command
        output collections.
        Nr�r\s r r`zPlugin.collectIs��	
r-c#�DK�	t�}|j||��}|jj|t�|jj|�}t
|d�}|jd|���|��|j�t�}||z
}	|jd|�d|	���t|t�r|g}|jjj|||d��y	#t$r!}
|jd|�d|
���Yd	}
~
y	d	}
~
wwxYw�w)
a�Handles creating and managing files within a plugin's subdirectory
        within the archive, and is intended to be used to save manually
        compiled data generated during a plugin's ``_collect_manual()`` step
        of the collection phase.

        Plugins should call this method using a ``with`` context manager.

        :param fname:       The name of the file within the plugin directory
        :type fname:        ``str``

        :param subdir:      If needed, specify a subdir to write the file to
        :type subdir:       ``str``

        :param tags:        Tags to be added to this file in the manifest
        :type tags:         ``str`` or ``list`` of ``str``s
        )r��wzmanual collection file opened: zmanual collection 'z' finished in )r�r�rFzError with collection file 'r�N)rr�r�r�rr��openr�closer}r�r�r�rrjr�)rJrr�rFr��_pfnamer]r|r��runr5s           r �collection_filezPlugin.collection_fileSs����$	K��F�E��1�1�%��1�G�G��L�L�#�#�G�V�4��L�L�*�*�7�3�E����$�E��O�O�=�e�W�E�F��K��K�K�M��&�C���+�C��N�N�0���~�c�U�K�L��$��$��v���M�M�%�%�,�,��#��.�
��
�	K��N�N�9�%���C�5�I�J�J��	K�s/�D �C.C3�2D �3	D�<D�D �D�D c�:�t�}|j�|j�|j�|j	�|j�|j
�|j�t�|z
f}|jd|z�y)zCollect the data for a plugin.zcollected plugin '%s' in %sN)	rrHrPrZr^rTrar�r)rJr��fieldss   r �collect_pluginzPlugin.collect_plugin{sy������ � �"��*�*�,��"�"�$��������������)�)�+�t�v��~�.�����5��>�?r-c�:�	|jS#t$rYywxYw)z8This function will return the description for the pluginz<no description available>)rSr�r\s r �get_descriptionzPlugin.get_description�s#��	0��?�?�"���	0�/�	0�s��	�c	�z�t|j|j|j|j|j
|j|jg��r t|jt�r|jg|_t|jt�r|jg|_t|jt�r|jg|_t|jt�r|jg|_t|j
t�r|j
g|_t|t�r�gt|�_|j�D]�}|jD�cgc]	}|d|iz��}}|jD�cgc]	}|d|iz��}}|jD�cgc]	}|d|iz��}}|j
D�cgc]	}|d|iz��}	}|j||||	d�s��t|�jj|���t|�jry|j|j|j|j|j
|j�St|t�r|j�t|�_ycc}wcc}wcc}wcc}w)aThis method will be used to verify that a plugin should execute
        given the condition of the underlying environment.

        The default implementation will return True if none of class.files,
        class.packages, nor class.commands is specified. If any of these is
        specified the plugin will check for the existence of any of the
        corresponding paths, packages or commands and return True if any
        are present.

        For SCLPlugin subclasses, it will check whether the plugin can be run
        for any of installed SCLs. If so, it will store names of these SCLs
        on the plugin class in addition to returning True.

        For plugins with more complex enablement checks this method may be
        overridden.

        :returns:   ``True`` if the plugin should be run for this system, else
                    ``False``
        :rtype: ``bool``
        �scl_namer�T)rbr
rGrrBrFr�
architecturesr�r��	SCLPluginr��
_scls_matched�	_get_scls�_check_plugin_triggersrj)
rJ�sclrr
rSrGrFrrQrFs
          r �
check_enabledzPlugin.check_enabled�s/��,��
�
�D�M�M�4�=�=�$�:J�:J��
�
�t����0B�0B�D�E��$�*�*�c�*�"�j�j�\��
��$�-�-��-�!%�����
��$�-�-��-�!%�����
��$�*�*�C�0�$(�$4�$4�#5�� ��$�-�-��-�!%�����
��$�	�*�+-��T�
�(��>�>�+�=�C�<@�J�J�G�q�Q�*�c�!2�2�G�E�G�?C�}�}�M�!��Z��$5� 5�M�H�M�?C�}�}�M�!��Z��$5� 5�M�H�M�?C�}�}�M�!��Z��$5� 5�M�H�M��2�2�5�3;�3;�3;�35�7��T�
�0�0�7�7��<�=���:�+�+���.�.�t�z�z�/3�}�}�/3�}�}�/3�}�}�/3���	@�
@��d�I�&�'+�~�~�'7�D��J�$���1H��M��M��Ms�7J)�J.�3J3�J8c���t|||||g�s�j�St�fd�|D��xsvt�fd�|D��xs`t�fd�|D��xsJt�fd��jD��xs*t�fd�|D��xst�fd�|D��xr�j�S)Nc3�@�K�|]}�j|����y�wr�)r
)r�rrJs  �r r�z0Plugin._check_plugin_triggers.<locals>.<genexpr>�s�����@��T�%�%�e�,�@���c3�@�K�|]}�j|����y�wr�)r)r�r�rJs  �r r�z0Plugin._check_plugin_triggers.<locals>.<genexpr>�s�����?�s�D�%�%�c�*�?�rzc3�J�K�|]}t|�j����y�wr�)rr�)r�r?rJs  �r r�z0Plugin._check_plugin_triggers.<locals>.<genexpr>�s�����I��M�#�t�|�|�4�I�rc3�@�K�|]}�j|����y�wr�)rt)r��modrJs  �r r�z0Plugin._check_plugin_triggers.<locals>.<genexpr>�s�����K�3�D�)�)�#�.�K�rzc3�@�K�|]}�j|����y�wr�)r�)r�r|rJs  �r r�z0Plugin._check_plugin_triggers.<locals>.<genexpr>�s�����=�S�D�O�O�C�(�=�rzc3�@�K�|]}�j|����y�wr�)rj)r��cntrrJs  �r r�z0Plugin._check_plugin_triggers.<locals>.<genexpr>�s�����G�D�D�)�)�$�/�G�rz)rb�check_is_architecturerB)rJr
rGrrFrs`     r ruzPlugin._check_plugin_triggers�s�����E�8�X�x��D�E��-�-�/�/��@�%�@�@�H��?�h�?�?�H��I��I�I�H��K�$�:J�:J�K�K�H��=�H�=�=�	H�
�G�J�G�G�-��*�*�,�
	.r-c��|j�yddj|j�z}tj||jj��S)a?Checks whether or not the system is running on an architecture that
        the plugin allows. If not architecture is set, assume plugin can run
        on all arches.

        :returns:   ``True`` if the host's architecture allows the plugin to
                    run, else ``False``
        :rtype: ``bool``
        Tr�r�)rqrErr�r�r�r�s  r r�zPlugin.check_is_architecture�sJ�����%���3�8�8�D�$6�$6�7�7���x�x��t�{�{�3�3�5�6�6r-c��y)zwThis decides whether a plugin should be automatically loaded or
        only if manually specified in the command line.Tr�r\s r �default_enabledzPlugin.default_enabled�s��r-c��|jD]6}|j|�s�|j|�|j|��8|jD](}|j|�s�|j
d|����*y)z�Based on the class attrs defined for plugin enablement, add a
        standardized set of collections before we call the plugin's own setup()
        method.
        zmodinfo N)rFr�r%r:rBrtr�)rJr$rvs   r �add_default_collectionszPlugin.add_default_collections�sy���}�}�	*�G����w�'��'�'��0�� � ��)�	*��$�$�	7�D��$�$�T�*��#�#�h�t�f�$5�6�	7r-c�L�|jt|j��y)z�Collect the list of files declared by the plugin. This method
        may be overridden to add further copy_specs, forbidden_paths, and
        external programs if required.
        N)rr�r
r\s r �setupzPlugin.setup
s��
	
���4��
�
�+�,r-c�@�t|d�r|js<t|d�r/|jr#|jD�cgc]}|dz��	c}|_ny|jj}|j|j�}|r|j
|�yycc}w)NrHrG�$)rXrHrGr�r��build_verify_commandr�)rJrS�pm�
verify_cmds    r �setup_verifyzPlugin.setup_verify
s����t�.�/�t�7K�7K��t�Z�(�T�]�]�9=���'G�A��C��'G��$��
�[�[�
(�
(���,�,�T�-A�-A�B�
�����
�+���
(Hs�Bc�.�t||j�S)a\Helper to call the sos.utilities wrapper that allows the
        corresponding `os` call to account for sysroot

        :param path:        The canonical path for a specific file/directory
        :type path:         ``str``


        :returns:           True if the path exists in sysroot, else False
        :rtype:             ``bool``
        )r
r�r�s  r r
zPlugin.path_exists
����4����.�.r-c�.�t||j�S)aSHelper to call the sos.utilities wrapper that allows the
        corresponding `os` call to account for sysroot

        :param path:        The canonical path for a specific file/directory
        :type path:         ``str``


        :returns:           True if the path is a dir, else False
        :rtype:             ``bool``
        )rr�r�s  r rzPlugin.path_isdir%
s���$����-�-r-c�.�t||j�S)aTHelper to call the sos.utilities wrapper that allows the
        corresponding `os` call to account for sysroot

        :param path:        The canonical path for a specific file/directory
        :type path:         ``str``


        :returns:           True if the path is a file, else False
        :rtype:             ``bool``
        )rr�r�s  r rzPlugin.path_isfile2
r�r-c�.�t||j�S)aTHelper to call the sos.utilities wrapper that allows the
        corresponding `os` call to account for sysroot

        :param path:        The canonical path for a specific file/directory
        :type path:         ``str``


        :returns:           True if the path is a link, else False
        :rtype:             ``bool``
        )r
r�r�s  r r
zPlugin.path_islink?
r�r-c�.�t||j�S)aTHelper to call the sos.utilities wrapper that allows the
        corresponding `os` call to account for sysroot

        :param path:        The canonical path for a specific file/directory
        :type path:         ``str``


        :returns:           Contents of path, if it is a directory
        :rtype:             ``list``
        )rr�r�s  r rzPlugin.listdirL
s���t�T�\�\�*�*r-c�4�t|g|��d|ji�S)a�Helper to call the sos.utilities wrapper that allows the
        corresponding `os` call to account for sysroot

        :param path:    The leading path passed to os.path.join()
        :type path:     ``str``

        :param p:       Following path section(s) to be joined with ``path``,
                        an empty parameter will result in a path that ends with
                        a separator
        :type p:        ``str``
        r�)rr�)rJr�rSs   r rzPlugin.path_joinY
s����8��8�4�<�<�8�8r-c��y)zLPerform any postprocessing. To be replaced by a plugin if required.
        Nr�r\s r rzPlugin.postprocg
s��	
r-c���d}d}	tj|�}|D]B}t|j|�d�}|j�j	�}||vs�Ad}�D	|S#t
$rYywxYw)z�Checks if a named process is found in /proc/[0-9]*/cmdline.

        :param process:     The name of the process
        :type process:      ``str``

        :returns: ``True`` if the process exists, else ``False``
        :rtype: ``bool``
        F�/proc/[0-9]*/cmdline�rT)r=rerrr(r�)rJ�processr��
cmd_line_glob�cmd_line_pathsr�r�cmd_lines        r �check_process_by_namezPlugin.check_process_by_namel
s����.�
�	�!�Y�Y�}�5�N�&�
"�������-�s�3���6�6�8�>�>�+���h�&�!�F�	
"��
���	��	�s�AA%�A%�%	A1�0A1c�2�g}d}tj|�}|D]]}	t|d�5}|j�j�}||vr#|j	|jd�d�ddd��_|S#1swY�
xYw#t$rY�ywxYw)z�Get a list of all PIDs that match a specified name

        :param process:     The name of the process the get PIDs for
        :type process:  ``str``

        :returns: A list of PIDs
        :rtype: ``list``
        r�r�r%�N)r=rerr(rjrVr�)rJr��pidsr�r�r�rr�s        r �get_process_pidszPlugin.get_process_pids�
s�����.�
����=�1��"�	�D�
��$��_�8�� �v�v�x�~�~�/�H��(�*����D�J�J�s�O�A�$6�7�8��	���
8�8���
��
�s)�B
�AA>�2B
�>B	�B
�
	B�Bc��|�2|jdjr|jdj}|j|jdd||�S)Nr��
namespaces�network)r�r��filter_namespaces)rJ�
ns_pattern�ns_maxs   r �get_network_namespaceszPlugin.get_network_namespaces�
sT���>�d�l�l�=�9�D�D��\�\�-�0�;�;�F��%�%�d�l�l�<�&@��&K�&0�&�:�	:r-c�6�g}|r2ddj|j��jdd�z}|D]]}|r tt	j
|��s�%|j
|�|s�9t|�|k(s�H|jd|z�|S|S)z�Filter a list of namespaces by regex pattern or max number of
        namespaces (options originally present in the networking plugin.)
        z(?:%s$)z$|r�z.*z9Limiting namespace iteration to first %s namespaces found)	rErVrpr�rr�rjr�rz)rJ�ns_listr�r��out_nsr��nss       r r�zPlugin.filter_namespaces�
s�������D�I�I�j�&6�&6�&8�9�A�A�#�t�L�L�
��	�B��$�r�x�x���'<�"=���M�M�"��
��v�;�&�(��N�N�$B�%+�$,�-���
�!	� �
r-r�)FN)F)r#)NF)r)NT)
NTTNNFNFFF)NNNNNFNNNNNNNrN)NN)�r�r�r�r�r8rGr
rrBrFrrqr�rWr�r	r-r/r2r�rAr�r�r�r�r�rrrr"r+�propertyr�rr4r6�classmethodr�r?r=r<rsrvrzr}rr�r�r�rr�r�r�rzr�r�r�r�r�r�r�r�r�r�r�r�r�rr
r�rrrr"r�r2r6rsr?rCrGrPrr�r�r�r�r�r�r�r�r,r�r�r�r�r�rkr�r�r�rjrrrrrrr�rtrr r%r:rirHrPrTrZr^rar`�
contextlib�contextmanagerrirlrnrwrur�r�r�r�r�r
rrr
rrrr�r�r�r�r�r-r r�r��sA��,�\�K��H��E��H��K��H��J��M��G��H��G�$�N�!�K��L��G��H��K��I��M�#/�J
� 2�.4� 2�� *�X��������5�
!�&�$��$��-��-��d��d�L�8
��8
�tL�1�3�0�1�
�7�
7�
�	8�	8�	9�
8�	J�	@��"��,�"�8@�05�n8�62�h=�*+�=(�~�$�
�
�
�H�<�|0�*�*�@+�&�"� :�$26�d�!��2��w�r59�D�"�$�D��$(�B�"�2� "�4�OO�b6:�T�#�4�T�%�%)��R��4�.K�259�$(�$�t�"�$�D��!%�D��$��R� "�u��$�
jO�X%� ��.%�.�+�8C�$:>�� "�#;�J9=�).��#'��D�d�#(�D��$)�e�"�%'�E�5�*/�
q�f8<�(-�t�"&�t�4�T�"'�4�d�#(�U�4� "�G
�R?C�:>�=B�JL�X�0I�B�� �$��2�&�&7�6�,	6�(�!�F�.DH�8<�;?�CE�f0�P*#�X&�(?�T8�
4�2� 
G�
����,0�r�%K��%K�N
@�0�C�J
.�7��

7�-�,�/�.�/�/�+�9�
�
�,�,:�r-r�c��eZdZdZy)�PluginDistroTagz�The base tagging class for distro-specific classes used to signify that
    a Plugin is written for that distro.

    Use IndependentPlugin for plugins that are distribution agnostic
    N�r�r�r�r�r�r-r r�r��
s���
	r-r�c��eZdZdZy)�RedHatPluginz/Tagging class for Red Hat's Linux distributionsNr�r�r-r r�r��
���9�r-r�c��eZdZdZy)�UbuntuPluginzTagging class for Ubuntu LinuxNr�r�r-r r�r��
���(�r-r�c��eZdZdZy)�DebianPluginzTagging class for Debian LinuxNr�r�r-r r�r��
r�r-r�c��eZdZdZy)�
SuSEPluginz*Tagging class for SuSE Linux distributionsNr�r�r-r r�r��
s��4�r-r�c��eZdZdZy)�OpenEulerPluginz/Tagging class for openEuler linux distributionsNr�r�r-r r�r��
r�r-r�c��eZdZdZy)�	CosPluginz(Tagging class for Container-Optimized OSNr�r�r-r r�r��
s��2�r-r�c��eZdZdZy)�IndependentPluginz6Tagging class for plugins that can run on any platformNr�r�r-r r�r��
s��@�r-r�c��eZdZdZy)�ExperimentalPluginz=Tagging class that indicates that this plugin is experimentalNr�r�r-r r�r��
s��G�r-r�c�>�eZdZdZed��Zd�Zd�Zd�Zd�Z	d�Z
y)	rra�Superclass for plugins operating on Software Collections (SCLs).

    Subclasses of this plugin class can specify class.files and class.packages
    using "%(scl_name)s" interpolation. The plugin invoking mechanism will try
    to match these against all found SCLs on the system. SCLs that do match
    class.files or class.packages are then accessible via self.scls_matched
    when the plugin is invoked.

    Additionally, this plugin class provides "add_cmd_output_scl" (run
    a command in context of given SCL), and "add_copy_spec_scl" and
    "add_copy_spec_limit_scl" (copy package from file system of given SCL).

    For example, you can implement a plugin that will list all global npm
    packages in every SCL that contains "npm" package:

    class SCLNpmPlugin(Plugin, SCLPlugin):
        packages = ("%(scl_name)s-npm",)

        def setup(self):
            for scl in self.scls_matched:
                self.add_cmd_output_scl(scl, "npm ls -g --json")
    c�v�tt|�d�sgt|�_t|�jS)Nrs)rXr�rsr\s r �scls_matchedzSCLPlugin.scls_matcheds,���t�D�z�?�3�')�D��J�$��D�z�'�'�'r-c��td�d}|j�D�cgc]}|j���c}Scc}w)Nzscl -lrB)rr�r()rJrBrvs   r rtzSCLPlugin._get_sclss4��'��1�(�;��'-�'8�'8�':�;���	�	��;�;��;s�;c��d|�d|�d�}|S)z.wrapping command in "scl enable" call
        zscl enable z "�"r�)rJrvr?�scl_cmds    r �convert_cmd_sclzSCLPlugin.convert_cmd_scls��-0��5���r-c���||jvryt|t�r|g}g}|D]#}|j|j	||���%|j
|fi|��y)zpSame as add_cmd_output, except that it wraps command in
        "scl enable" call and sets proper PATH.
        N)r�r�r�rjr�r�)rJrvr�r��scl_cmdsr?s      r �add_cmd_output_sclzSCLPlugin.add_cmd_output_sclsh���d�'�'�'���d�C� ��6�D����	<�C��O�O�D�0�0��c�:�;�	<�����H�/��/r-c���|jj�}dD]S}tjd|z�}tj
j
|jd|�d|�d|�d�|��}�U|S)N)rR�varz^/%s/r%)r��get_default_scl_prefixrr�r�r�r�r')rJrvrr�
scl_prefix�rootdirrSs      r �convert_copyspec_sclzSCLPlugin.convert_copyspec_scl&sj���[�[�7�7�9�
�%�	2�G��
�
�7�W�,�-�A��w�w���q�u�u�(/��S�.B�'/�(1�2�H�	2�
�r-c��||jvryt|t�r|g}g}|D]#}|j|j	||���%|j|�y)z`Same as add_copy_spec, except that it prepends path to SCL root
        to "copyspecs".
        N)r�r�r�rjr�r)rJrvro�
scl_copyspecsrrs     r �add_copy_spec_sclzSCLPlugin.add_copy_spec_scl/se���d�'�'�'���i��%�"��I��
�!�	K�H�� � ��!:�!:�3��!I�J�	K����=�)r-N)r�r�r�r�r�r�rtr�r�r�r�r�r-r rrrr�
s4���.�(��(�
<��0�"�*r-rrc�6�d|z}|stf}t||�S)z�Import name as a module and return a list of all classes defined in that
    module. superclasses should be a tuple of valid superclasses to import,
    this defaults to (Plugin,).
    zsos.report.plugins.%s)r�r)r��superclasses�
plugin_fqnames   r �
import_pluginr�=s%��
,�d�2�M���y�����5�5r-r�)7r��
sos.utilitiesrrrrrrr	r
rrr
rrrrr�sos.archiverrr�r�r=rr1rr�r�r�r[rr!r,r:r��DOTALLr�r��objectr<r�r�r�r�r�r�r�r�r�r�r�r�rrr�r�r-r �<module>r�s+��B�9�9�9�9�9�'��	��	������������R�Z�Z�)�2�9�9�
5�
��
�j
�6�j
�Z	8��8�,P�P�f]/�]/�@_	�	�	�?�	�
	�?�	�
	�?�	�
	��	�
	�o�	�
	��	�
	��	�
	��	�
M*��M*�`6r-

Zerion Mini Shell 1.0