%PDF- %PDF-
Mini Shell

Mini Shell

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

�

i��d~H�
���ddlZddlZddlZddlmZmZmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZ	ddlmZdZ	ddlZej8e�dZdZ&d�Z'd0d�Z(d1d�Z)d�Z*d2d�Z+d�Z,d3d�Z-e&dddddddddf
d�Z.d3d�Z/d4d�Z0d5d�Z1ejdfd�Z3d�Z4d�Z5d�Z6d�Z7d �Z8ejrd!�d"�Z:d#�Z;gfd$�Z<d%�ZGd&�d'�Z=Gd(�d)e
j|�Z?Gd*�d+e@�ZAGd,�d-�ZBGd.�d/eC�ZDy#e$r	ddlmZY��wxYw#eef$r>ej@d	�Z!dd
l"m#Z#dZ$e!jKde#e$d
d��zdz�Y��wxYw)6�N)�Popen�PIPE�STDOUT)�closing)�deque)�
parse_version)�parseFT�sos)�fillz�WARNING: Failed to load 'magic' module version >= 0.4.20 which sos aims to use for detecting binary files. A less effective method will be used. It is recommended to install proper python3-magic package with the module.
�
�H)�replace_whitespacei,c���t|d�5}tj|�j|kDr|j	|d�|j�cddd�S#1swYyxYw)z,Returns the last number_of_bytes of filename�rb�N)�open�os�stat�st_size�seek�read)�filename�number_of_bytes�fs   �//usr/lib/python3/dist-packages/sos/utilities.py�tailr2sT��	
�h��	���
�7�7�8��$�$��6�
�F�F�O�#�Q�'��v�v�x����s�AA�A%c��t|t�r
	t||�St|�S#t$rIt	j
d�}|j
d|z�ttj��cYSwxYw)z@Returns a file-like object that can be used as a context managerr
zfileobj: %s could not be opened)
�
isinstance�strr�IOError�logging�	getLogger�debugr�io�StringIO)�path_or_file�mode�logs   r�fileobjr):so���,��$�	*���d�+�+��|�$�$���	*��#�#�E�*�C��I�I�7�,�F�G��2�;�;�=�)�)�	*�s�)�AA;�:A;c��t|�}||k\rd||zzS||k\rd||zzS||k\rd||zzS||k\rd||zzSd|zS)zCConverts a number of bytes to a shorter, more human friendly formatz%.1fTz%.1fGz%.1fMz%.1fKz%d)�float)�bytes_�K�M�G�T�fns      r�
convert_bytesr2Gsm��	�v��B�
��{��"�q�&�!�!�	�1���"�q�&�!�!�	�1���"�q�&�!�!�	�1���"�q�&�!�!��f�}��c�F��tr@	tj|��ddg}�jdk(xrt	�fd�|D��St
|d�5}	|jd�	ddd�y#t
$rY�4wxYw#t$rYddd�y	wxYw#1swYyxYw)
azHelper to determine if a given file contains binary content or not.

    This is especially helpful for `sos clean`, which cannot obfuscate binary
    data and instead, by default, will remove binary files.

    :param fname:   The full path of the file to check binaryness of
    :type fname:    ``str``

    :returns:   True if binary, else False
    :rtype:     ``bool``
    ztext/zinode/�binaryc3�T�K�|]}�jj|����!y�w�N)�	mime_type�
startswith)�.0�_mt�_ftups  �r�	<genexpr>z!file_is_binary.<locals>.<genexpr>hs �����F��E�O�O�.�.�s�3�F�s�%(�tr�NFT)	�	magic_mod�magic�detect_from_filename�encoding�any�	Exceptionrr�UnicodeDecodeError)�fname�_mimes�tfiler<s   @r�file_is_binaryrJVs�����	��.�.�u�5�E��x�(�F����(�*�G��F�v�F�F�0G�
�
�e�T�	��e�	�
�J�J�q�M�����	�	��	��"�	����	��
��s;�>A1�B�B�1	A=�<A=�	B�	B�B�B�B c#��K�|rKtjj|�jtjj�}||z
}tj
|�D]�\}}}|r1|jtjj�|k\r|dd�=|rt
j||�s�St
j||�D]$}tjj||����&��y�w)z�Generator function to find files recursively.
    Usage::

        for filename in find("*.properties", "/var/log/foobar"):
            print filename
    N)	r�path�dirname�count�sep�walk�fnmatch�filter�join)	�file_pattern�top_dir�	max_depth�path_pattern�
base_depthrL�dirlist�filelist�names	         r�findr\xs�������W�W�_�_�W�-�3�3�B�G�G�K�K�@�
��Z��	�#%�7�7�7�#3�+���g�x�����B�G�G�K�K�0�I�=���
������l� C���N�N�8�\�:�	+�D��'�'�,�,�t�T�*�*�	+�+�s�C6C8c���g}|D]0}t|�5}|j�fd�|D��ddd��2|S#1swY�>xYw)z�Returns lines matched in fnames, where fnames can either be pathnames to
    files to grep through or open file objects to grep through line by linec3�P�K�|]}tj�|�s�|���y�wr7)�re�match)r:�line�patterns  �rr=zgrep.<locals>.<genexpr>�s�����K�T�2�8�8�G�T�3J�D�K�s�&�&N)r)�extend)rb�files_or_paths�matches�fop�fos`    r�greprh�s\����G��M��
�S�\�	M�R��N�N�K�R�K�L�	M�	M�M��N�	M�	M�s	�;�A	c
��tjjdd�jtjj
�}|g|D�cgc]"}tjj
||���$c}z}|r@||D�cgc]1}tjj
||jd����3c}z
}td�|D��Scc}wcc}w)z6Returns if a command matches an executable on the PATH�PATH��/c3�dK�|](}tj|tj����*y�wr7)r�access�X_OK)r:rLs  rr=z is_executable.<locals>.<genexpr>�s����?�D�r�y�y��r�w�w�'�?�s�.0)	r�environ�get�splitrL�pathseprS�lstriprD)�command�sysroot�paths�p�
candidates�cs      r�
is_executabler{�s���
�J�J�N�N�6�2�&�,�,�R�W�W�_�_�=�E����F�1�b�g�g�l�l�1�g�6�F�F�J���:D�
�56�B�G�G�L�L��!�(�(�3�-�0�
�	
�
��?�J�?�?�?��G��
s�'C�6Cc
�l���	���fd�}�	fd�}tjj�}
d|
d<|r2|j�D]\}}|r||
|<�|
j	|d��!|rtd�rd|rdnd	||fz}t
j|�}g}|D]c}|jd
�r?d|vr;tj|�}|r|j|��A|j|��S|j|��e|
r
t|
d�}nt}	t|d
||rtntd|
d|��}|
st!|j"||�}nt%||�}�	r"|j&r,||�|j&r�n	|j)|r|nd�|
r|j/�|j5��	|j5���|j1�}|j2}|j<dk(s|j<dk(rd}|j<||d�S#t*$rJ|j-�|
r|j/�d
|_d|j1�|j2d�cYSwxYw#t6$rA}|
r|j/�|j8t8j:k(rdd	d	d�cYd}~S|�d}~wwxYw)z�Execute a command and return a dictionary of status and output,
    optionally changing root or current working directory before
    executing command.
    c�n���r�dk7rtj���rtj��yy�Nrl)r�chroot�chdir)r�rs��r�_child_prep_fnz.sos_get_command_output.<locals>._child_prep_fn�s+����f��m��I�I�f����H�H�U�O�
r3c�����s|j�dk(r|j�t�tjd�y)N�|�{�G�z�?)�poll�	terminate�SoSTimeoutError�time�sleep)�proc�pollers �r�
_check_pollerz-sos_get_command_output.<locals>._check_poller�s1����8�t�y�y�{�c�)��N�N��!�!��
�
�4�r3zC.UTF-8�LC_ALLN�timeoutztimeout %s %ds %sz--foregroundrkrl�*�wF���T)�shell�stdout�stderr�bufsize�env�	close_fds�
preexec_fnr�)�status�output�	truncated��~r3)rrp�copy�items�popr{�shlexrrr9�globrc�appendrrrr�AsyncReaderr��
FakeReader�running�waitrEr��close�get_contents�is_fullr��OSError�errno�ENOENT�
returncode)rur�r�rr�r��
foregroundr5�	sizelimitr��to_filer�r��cmd_env�key�value�args�
expanded_args�arg�expanded_arg�_outputrx�readerr�r��es   ``    `                r�sos_get_command_outputr��s�������j�j�o�o��G�!�G�H��
��)�)�+�	'�J�C���$�������C��&�		'��=��+�%�(�N�b���)
�
���;�;�w��D��M��&���>�>�#��3�#�:��9�9�S�>�L���$�$�\�2��$�$�S�)�� � ��%�&���w��$����,��-�u�W�#)��t��'�T�+�
-��
� ����9�f�=�F���6�*�F���.�.��a� ��.�.�
5����'�w�t�4���M�M�O��f�f�h����f�f�h���$�$�&���N�N�	�	�|�|�s��a�l�l�c�1����,�,������=�
5����
���M�M�O�"'���"%��1D�1D�1F�%+�^�^�5�5�
5��&����M�M�O��7�7�e�l�l�"�!�R�b�A�A��G��
�sV�A'I)�<I)�>H�3I)�I)�AI&�#I)�%I&�&I)�)	J3�24J.�&J3�,J.�.J3c�H�|jd�d}t|t�t�|g�}t	j
|tj�D��cgc]\}}|j|k(r|��}}}|r|D�cgc]}t||�s�|��}}|Scc}}wcc}w)aImports the module module_fqname and returns a list of defined classes
    from that module. If superclasses is defined then the classes returned will
    be subclasses of the specified superclass or superclasses. If superclasses
    is plural it must be a tuple of classes.�.r�)	�
rpartition�
__import__�globals�locals�inspect�
getmembers�isclass�
__module__�
issubclass)�
module_fqname�superclasses�module_name�module�cname�class_�modules�ms        r�
import_moduler�s���
 �*�*�3�/��3�K�
�
�w�y�&�(�[�M�
J�F��!�!�&�'�/�/�:�6�-�%���#�#�}�4��6�G�6��%�E���A�|�)D�1�E��E��N��
6��Fs�B�?B�Bc�&�t||||��dS)zeShell out to an external command and return the output or the empty
    string in case of error.
    )r�rr�r�)r�)�cmdr�r�runats    r�	shell_outr�'s$��"�#�w�)/�u�>�>F�H�Hr3c�b�gd�}d}|dkDr|dkr|dz
}|dz}|dkDr|dkr�d||||fzS)N)�B�KiB�MiB�GiB�TiBr��r?g�@z%.*f%s�)�size�	precision�suffixes�suffixindexs    r�get_human_readabler�/sT��0�H��K�
��+�+��/��q����F�{����+�+��/��y�$���(=�>�>�>r3c���|rS|tjk7r@|j|�s/tjj	||jd��}t
||�}||�Sr~)rrOr9rLrSrt�getattr)rLrv�methodr��_meths     r�_os_wrapperr�9sO���7�b�f�f�$����w�'��7�7�<�<�����S�)9�:�D��F�F�#�E���;�r3c�J�d|vrt||dt��St||d�S)Nr�r�)r��exists)r�r��rLrvs  r�path_existsr�As)��
�d�{��4��&��>�>��t�W�h�/�/r3c��t||d�S)N�isdir�r�r�s  r�
path_isdirr�Gs���t�W�g�.�.r3c��t||d�S)N�isfiler�r�s  r�path_isfiler�K����t�W�h�/�/r3c��t||d�S)N�islinkr�r�s  r�path_islinkr�Or�r3c�&�t||dt�S)N�listdir)r�rr�s  rr�r�Ss���t�W�i��4�4r3)rvc���|rN|j|�s=tjj||j	tj
��}tjj|g|���Sr7)r9rrLrSrtrO)rLrvrxs   r�	path_joinr�WsI���t���w�/��w�w�|�|�G�T�[�[����%8�9��
�7�7�<�<��!�q�!�!r3c��d|zdzS)a"Helper to make text bold in console output, without pulling in
    dependencies to the project unneccessarily.

    :param text:    The text to make bold
    :type text:     ``str``

    :returns:       The text wrapped in the ASCII codes to display as bold
    :rtype:         ``str``
    zzr�)�texts r�boldr�]s���t��i�'�'r3c���g}g}|j|�t|t�r�|j�D]�\}�|j	|�|r||vr|jt����8t�t�s�I	|jt�fd�|D��d�|j�j����n|j|�|D�cgc]	}||vs�|��c}S#t$rY�SwxYwcc}w)a	Recursively compile all elements of a potentially nested dict by a set
    of keys. If a given key is a dict within ``dobj``, then _all_ elements
    within that dict, regardless of child keys, will be returned.

    For example, if a Plugin searches the devices dict for the 'storage' key,
    then all storage devices under the that dict (e.g. block, fibre, etc...)
    will be returned. However, if the Plugin specifies 'block' via ``keys``,
    then only the block devices within the devices['storage'] dict will be
    returned.

    Any elements passed here that are _not_ keys within the dict or any nested
    dicts will also be returned.

    :param dobj:    The 'top-level' dict to intially search by
    :type dobj:     ``dict``

    :param keys:    Which keys to compile elements from within ``dobj``. If no
                    keys are given, all nested elements are returned
    :param keys:    ``list`` of ``str``

    :returns:       All elements within the dict and any nested dicts
    :rtype:         ``list``
    c3�2�K�|]}|�vs��|���y�wr7r�)r:r��vs  �rr=z/recursive_dict_values_by_key.<locals>.<genexpr>�s �����5�'*�c�Q�h�A�c�F�5�s�	�
r)rcr�dictr�r��recursive_dict_values_by_key�
IndexError�keys)�dobjr�_items�_filt�k�drs      @rrrjs����0�F��E�
�M�M�$���$����J�J�L�	'�D�A�q��L�L��O��1��9��
�
�:�1�=�>��A�t�$�	��M�M�4�5�.2�5��������Q�V�V�X�&�%	'�*	�
�
�d���0�!��%��A�0�0��"�����1s�&C/�	C>�(C>�/	C;�:C;c��t|�S)zParse the version string
    )�
version_parse)�versions rrr�s����!�!r3c�<�eZdZdZd�Zed��Zd�Zed��Zy)r�z�Used as a replacement AsyncReader for when we are writing directly to
    disk, and allows us to keep more simplified flows for executing,
    monitoring, and collecting command output.
    c� �||_||_yr7)�processr5)�selfrr5s   r�__init__zFakeReader.__init__�s�������r3c��y)NFr��rs rr�zFakeReader.is_full�s��r3c�"�|jsdSdS)Nrkr3)r5rs rr�zFakeReader.get_contents�s�����r�-�#�-r3c�:�|jj�duSr7)rr�rs rr�zFakeReader.running�s���|�|� � �"�d�*�*r3N)	�__name__r��__qualname__�__doc__r�propertyr�r�r�r�r3rr�r��s9���
�����.��+��+r3r�c�>��eZdZdZ�fd�Zd�Zd�Zed��Z�xZ	S)r�z�Used to limit command output to a given size without deadlocking
    sos.

    Takes a sizelimit value in MB, and will compile stdout from Popen into a
    string that is limited to the given sizelimit.
    c���tt|��||_||_d|_d|_|r"|dz}t||j
z�|_t|j��|_d|_	|j�y)Ni�)�maxlenT)�superr�r�chanr5�	chunksize�slots�intrr��start)r�channelr�r5�	__class__s    �rrzAsyncReader.__init__�sn���
�k�4�)�+���	���������
��!�G�+�I��Y����7�8�D�J��$�*�*�-��
�����
�
�r3c���		|jj|j�}|sn|jj	|��D	d|_y#t
tf$r
Yd|_ywxYw)alReads from the channel (pipe) that is the output pipe for a
        called Popen. As we are reading from the pipe, the output is added
        to a deque. After the size of the deque exceeds the sizelimit
        earlier (older) entries are removed.

        This means the returned output is chunksize-sensitive, but is not
        really byte-sensitive.
        FN)rrr rr��
ValueErrorr r�)rras  r�runzAsyncReader.run�sk��		���y�y�~�~�d�n�n�5�����
�
�!�!�$�'���
�����G�$�	�����	�s�AA�A)�(A)c��|jr"tjd�|jr�"|js"dj	d�|j
D��Sdj	d�|j
D��S)z-Returns the contents of the deque as a stringr�rkc3�@K�|]}|jdd����y�w)zutf-8�ignoreN)�decode�r:�lns  rr=z+AsyncReader.get_contents.<locals>.<genexpr>�s����M�B�2�9�9�W�h�7�M�s�r3c3� K�|]}|���y�wr7r�r-s  rr=z+AsyncReader.get_contents.<locals>.<genexpr>�s����4�2�B�4�s�)r�r�r�r5rSrrs rr�zAsyncReader.get_contents�sY���l�l��J�J�t���l�l��{�{��7�7�M�$�*�*�M�M�M��8�8�4����4�4�4r3c�`�|jsyt|j�|jk(S)z?Checks if the deque is full, implying that output was truncatedF)r!�lenrrs rr�zAsyncReader.is_full�s%���z�z���4�:�:��$�*�*�,�,r3)
rr�rrrr(r�rr��
__classcell__)r%s@rr�r��s+������*	5��-��-r3r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�ImporterHelperz�Provides a list of modules that can be imported in a package.
    Importable modules are located along the module __path__ list and modules
    are files that end in .py.
    c��||_y)zopackage is a package module
        import my.package.module
        helper = ImporterHelper(my.package.module)N)�package)rr6s  rrzImporterHelper.__init__�s����r3c��tjj|�}tjj|�\}}|S)z-Returns the plugin module name given the path)rrL�basename�splitext)rrL�baser[�exts     r�_plugin_namezImporterHelper._plugin_names3���w�w����%���G�G�$�$�T�*�	��c��r3c��|D�cgc](}d|vr"|jd�r|j|���*}}|j�|Scc}w)Nrz.py)�endswithr<�sort)r�list_�plugin�pluginss    r�_get_plugins_from_listz%ImporterHelper._get_plugins_from_listsV��!&�K�� ��.�6�?�?�5�3I��$�$�V�,�K��K�	�������	Ks�-Ac��tjj|�r,tt	d|��}|j|�}|r|SgSy)Nz*.py)rrLr��listr\rC)rrL�py_files�pnamess    r�_find_plugins_in_dirz#ImporterHelper._find_plugins_in_dirsE��
�7�7�>�>�$���D���.�/�H��0�0��:�F���
��	�
 r3c��g}|jjD]B}tjj	|�s�#|j|j
|���D|S)zQReturns the list of importable modules in the configured python
        package. )r6�__path__rrLr�rcrH)rrBrLs   r�get_moduleszImporterHelper.get_modulessR�����L�L�)�)�	@�D��w�w�}�}�T�"����t�8�8��>�?�	@��r3N)	rr�rrrr<rCrHrKr�r3rr4r4�s ���
����r3r4c��eZdZd�Zd�Zd�Zy)�TempFileUtilc� �||_g|_yr7)�tmp_dir�files)rrOs  rrzTempFileUtil.__init__(s�������
r3c��tj|j��\}}tj|d�}|j
j
||f�|S)N)�dirzw+)�tempfile�mkstemprOr�fdopenrPr�)r�fdrG�fobjs    r�newzTempFileUtil.new,sE���$�$����6�	��E��y�y��T�"���
�
���5�$�-�(��r3c���|jD]<\}}	|j�|j�	t	j
|��>g|_y#t$rY�+wxYw#t$rY�awxYwr7)rP�flushr�rEr�unlink)rrGrs   r�cleanzTempFileUtil.clean3sq���
�
�		�H�E�1�
����	����	�
��	�	�%� �		���
��
�
��
���
��
�s"� A�A#�	A �A �#	A/�.A/N)rr�rrrXr\r�r3rrMrM&s����r3rMc��eZdZy)r�N)rr�rr�r3rr�r�As��r3r�)�r)r�ri@l)NNr7)�NN)r)Err_r��
subprocessrrrr!rQr�r�r�rS�	threadingr�r$�
contextlibr�collectionsr�
pkg_resourcesrr�SyntaxError�packaging.versionr	r@rArB�__file__�ImportError�AttributeErrorr"r(�textwrapr�msg�warning�TIMEOUT_DEFAULTrr)r2rJr\rhr{r�r�r�r�rLr�r�r�r�r�r�rOr�r�rr��Threadr��objectr4rMr�r�r�r3r�<module>rps���
�	��*�*���������	���9�<�

�	�G���E���x�(��I����
%���D+�,	�	@�-<�E�"&�d���"'�4��#(�n�b
� H�?�/1�g�g��0�/�0�0�5�!#���"�
(�-/�31�l"�+�+�,:-�)�"�"�:-�z*�V�*�Z��6	�g�	��M�9�8�9��	�^�$�G�
�'�
�
�E�
"�C���C�
�K�K��t�C���>�>��E�F�G�s%�D�D(�D%�$D%�(AE-�,E-

Zerion Mini Shell 1.0