%PDF- %PDF-
Mini Shell

Mini Shell

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

�

�f2�
�B�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZeje�Zej dddg�Zd	�ZGd
�de�Zdeeeeeffd
�Zdddddddddd�	deeeeeeefdefd�Zdd�Zdd�Zd�Zdd�Zy)z9Common utility functions for interacting with subprocess.�N)�ENOEXEC)�
TextIOWrapper)�List�Union�
SubpResult�stdout�stderrc��g}g}g}|D]�}t|t�r&|d�|dd}nl|d|k7rd|jd|�nQt|t�r&|j	|�d��s-|j|�n|jt|����|j|���|r'tjd||dj|��|r+tdj|dj|�����|S)	a�Ensure user-provided commands start with base_command; warn otherwise.

    Each command is either a list or string. Perform the following:
       - If the command is a list, pop the first element if it is None
       - If the command is a list, insert base_command as the first element if
         not present.
       - When the command is a string not starting with 'base-command', warn.

    Allow flexibility to provide non-base-command environment/config setup if
    needed.

    @commands: List of commands. Each command element is a list or string.

    @return: List of 'fixed up' commands.
    @raise: TypeError on invalid config item type.
    rN�� z Non-%s commands in %s config:
%s�
zHInvalid {name} config. These commands are not a string or list:
{errors})�name�errors)�
isinstance�list�insert�str�
startswith�append�LOG�warning�join�	TypeError�format)�base_command�commands�warningsr�fixed_commands�commands      �0/usr/lib/python3/dist-packages/cloudinit/subp.py�prepend_base_commandr!s
��"�H�
�F��N��'���g�t�$��q�z�!�!�!�"�+�����|�+����q�,�/�
���
%��%�%���a�&8�9�����(��M�M�#�g�,�'�����g�&�'�����/����I�I�h��		
���
B�BH�&�!�$�)�)�F�*;�CI�C�
�	
���c�X�eZdZdZdZ							d	d�Zd�Z	d
deee	fdeee	ffd�Z
y)�ProcessExecutionErrorzr%(description)s
Command: %(cmd)s
Exit code: %(exit_code)s
Reason: %(reason)s
Stdout: %(stdout)s
Stderr: %(stderr)s�-Nc	�4�|xs|j|_|r||_n|s|tk(rd|_nd|_t	|t
�r|n|j|_|s|�|jn||_n|j|�|_|s|�|jn||_	n|j|�|_	|xs|j|_
|r||_|j|j|j�|j|j�|j|j�|j|j�|j|j�|j|j�d�z}tj||�y)Nz(Exec format error. Missing #! in script?z'Unexpected error while running command.)�description�cmd�	exit_coderr	�reason)�
empty_attrr(r'rr�intr)r	�_indent_textrr*�errno�MESSAGE_TMPL�_ensure_string�IOError�__init__)	�selfrr	r)r(r'r*r.�messages	         r r2zProcessExecutionError.__init__PsQ���)�$�/�/����*�D���u��/�I�D��H�D��$�I�s�3�I����	
���-3�^�$�/�/��D�K��+�+�F�3�D�K��-3�^�$�/�/��D�K��+�+�F�3�D�K��/��������D�J��#�#��.�.�t�/?�/?�@��&�&�t�x�x�0��,�,�T�^�^�<��)�)�$�+�+�6��)�)�$�+�+�6��)�)�$�+�+�6�
'
�
��	����w�'r"c�F�t|t�r|j�S|S)z1
        if data is bytes object, decode
        �r�bytes�decode)r3�texts  r r0z$ProcessExecutionError._ensure_strings��!+�4�� 7�t�{�{�}�A�T�Ar"r9�returnc��t|t�s'|jd�jddd|zz�S|jd�jddd|zz�S)z�
        indent text on all but the first line, allowing for easy to read output

        remove any newlines at end of text first to prevent unneeded blank
        line in output
        r
r�
� )rr7�rstrip�replace)r3r9�indent_levels   r r-z"ProcessExecutionError._indent_text�sZ���$��&��;�;�t�$�,�,�T�4�#��:L�3L�M�M��{�{�5�!�)�)�%����9L�1L�M�Mr")NNNNNNN)�)�__name__�
__module__�__qualname__r/r+r2r0rrr7r-�r"r r$r$Ese��	���J��������-(�^B�56�N��#�u�*�%�N�	�s�E�z�	�Nr"r$�argsc��|D]E}t|t�r�t|d�r�!tj	d|�t|d|�����y)z�check argument types to ensure that subp() can run the argument

    Throw a user-friendly exception which explains the issue.

    args: list of arguments passed to subp()
    raises: ProcessExecutionError with information explaining the issue
    �encodezRunning invalid command: %szRunning invalid command: )r(r*N)rr7�hasattrrrr$)rF�	components  r �raise_on_invalid_commandrK�sO����	��9�e�,��	�8�0L��K�K�5�t�<�'��#<�T�F�!C��
�	r"TFr?)	�data�rcs�capture�shell�	logstringr8�
update_env�cwd�timeoutr:c		�~��|�dg}tjj�}
|r|
j|�|stjd||||�ntjd|�d}d}|r tj}tj}|�tj}
n0tj}
t|t�s|j�}t|t�r|}n]t|t�r|jd�}n;t|�|D�cgc]%}t|t�r|n|jd���'}}	tj�}t
j||||
|
||��}|j!||	��\}}tj�|z
}|dkDrtjd	||��rd�fd
�	}||�}||�}|j(}||vrt%||||���t+||�Scc}w#t"$r.}t%|||j&�rd
nd�rd
��|�d��|�d}~wwxYw)a�Run a subprocess.

    :param args: command to run in a list. [cmd, arg1, arg2...]
    :param data: input to the command, made available on its stdin.
    :param rcs:
        a list of allowed return codes.  If subprocess exits with a value not
        in this list, a ProcessExecutionError will be raised.  By default,
        data is returned as a string.  See 'decode' parameter.
    :param capture:
        boolean indicating if output should be captured.  If True, then stderr
        and stdout will be returned.  If False, they will not be redirected.
    :param shell: boolean indicating if this should be run with a shell.
    :param logstring:
        the command will be logged to DEBUG.  If it contains info that should
        not be logged, then logstring will be logged instead.
    :param decode:
        if False, no decoding will be done and returned stdout and stderr will
        be bytes.  Other allowed values are 'strict', 'ignore', and 'replace'.
        These values are passed through to bytes().decode() as the 'errors'
        parameter.  There is no support for decoding to other than utf-8.
    :param update_env:
        update the environment for this command with this dictionary.
        this will not affect the current processes os.environ.
    :param cwd:
        change the working directory to cwd before executing the command.
    :param timeout: maximum time for the subprocess to run, passed directly to
        the timeout parameter of Popen.communicate()

    :return
        if not capturing, return is (None, None)
        if capturing, stdout and stderr are returned.
            if decode:
                entries in tuple will be string
            if not decode:
                entries in tuple will be bytes
    NrzFRunning command %s with allowed return codes %s (shell=%s, capture=%s)zFRunning hidden command to protect sensitive input/output logstring: %s�utf-8)rr	�stdin�envrOrR)rSg�������?zcommand %s took %.3ss to runr%�-)r(r*r.rr	c�L��t|t�r|j|��S|S�Nr6)rL�mr8s  �r �ldecodezsubp.<locals>.ldecode"s"���-7��e�-D�4�;�;�q�&�)�N�$�Nr")rr	r)r()rU)�os�environ�copy�updater�debug�
subprocess�PIPE�DEVNULLrr7rHrrK�time�Popen�communicate�OSErrorr$r.�
returncoder)rFrLrMrNrOrPr8rQrRrSrWrr	rV�
bytes_args�x�before�sp�out�err�total�er\�rcs      `                 r �subprs�s:���d�{��c��
�*�*�/�/�
�C���
�
�:����	�	�
&�����
	
�	�	�	�
)��	
��F�
�F�����������|��"�"�������$��&��;�;�=�D��$����
�	�D�#�	��[�[��)�
� ��&�FJ�
�AB��A�u�%�A�1�8�8�G�+<�<�
�
�
�������
�
�
��������
���>�>�$��>�8���S��	�	��f�$���3�;��I�I�4�d�E�B��	O��c�l���c�l��	���B�	��}�#��s�b�d�
�	
��c�3����O
��$��#����'�'� �3�d� �3�
��
	�
'+�
��
	���s�*H�A9H�	H<�)H7�7H<c�V�|dvrd}nSt|t�std|����tjj|�}|j
d�r|dd}|s|St|�r!|ddk(r|dd}t|�r	|ddk(r�tjj||�S)N)N��/zUnexpected input for target: z//rr)	rr�
ValueErrorr]�path�abspathr�lenr)�targetrxs  r �target_pathr|0s���
�����
���
$��8���A�B�B�������(�����T�"��A�B�Z�F���
��d�)��Q��3���A�B�x���d�)��Q��3��
�7�7�<�<���%�%r"c��t|�}tjj|vrt	t||��r|S|��tj
j
dd�jtj�D�cgc]}|jd���}}|dk(r|n!|D�cgc]}|jd�s�|��c}}|D�cgc]!}tjj|���#}}|D]F}tjjj||f�}t	t||��s�D|cSycc}wcc}wcc}w)N�PATHru�"rv)
r|r]rx�sep�is_exer^�get�split�pathsep�striprryr)�program�searchr{�p�pathsrx�ppaths       r �whichr�Es��
��
 �F�	�w�w�{�{�g��&��V�W�)E�"F���
�~�"$�*�*�.�.���"<�"B�"B�2�:�:�"N�
��A�G�G�C�L�
��
��s�]�E�E�(O�q�Q�\�\�#�=N��(O�	�+1�
1�Q�b�g�g�o�o�a� �
1�F�
1��������� � �$���1���+�f�e�,�-��L��
��
��)P��2s�D;�%E�<E�&Ec��tjj|�xr$tj|tj�SrZ)r]rx�isfile�access�X_OK)�fpaths r r�r�`s)��
�7�7�>�>�%� �>�R�Y�Y�u�b�g�g�%>�>r"c
�<�|r tjj|�syg}g}|�g}n;t|t�r
t	|�g}nt|t
�r|}nt
d��ttj|��D]�}tjj||�}t|�r$|j|�	t||gzd���Rtjj!|�rtj#d|���tjd|���|r9|r6t%dt'|��ddj|��d	t'|��d
���yy#t$r1}tj|�|j|�Yd}~��d}~wwxYw)Nz%exe_prefix must be None, str, or listF)rNzjskipping %s as its not executable or the underlying file system is mounted without executable permissions.zNot executing special file [%s]z
Runparts: z failures (�,z) in z attempted commands)r]rx�isdirrrrr�sorted�listdirrr�rrsr$rrar�r�RuntimeErrorrz)	�dirp�
skip_no_exist�
exe_prefix�failed�	attempted�prefix�exe_name�exe_pathrqs	         r �runpartsr�esk���R�W�W�]�]�4�0��
�F��I�����	�J��	$��j�/�"��	�J��	%����?�@�@��2�:�:�d�+�,�C���7�7�<�<��h�/���(�����X�&�
(��V�x�j�(�%�8��W�W�^�^�H�
%��K�K�*��	
�
�I�I�7��B�#C�&�)����V��
�[����&�1A�0B�%��9�~��1�
3�
�	
��v��)�
(��	�	�!���
�
�h�'�'��
(�s�E!�!	F�*&F�F)NN)TN)�__doc__�collections�loggingr]rbrer.r�ior�typingrr�	getLoggerrBr�
namedtuplerr!r1r$rr7rKrsr|r�r�r�rEr"r �<module>r�s���?���	�������g����!��
#�[�
#�
#�L�8�X�2F�
G�
�0�fKN�G�KN�\�5��c��D��K�)?�#@��(
���
������I �
��U�D��I�t�E�{�2�
3�I ��I �X&�*�6?�
'
r"

Zerion Mini Shell 1.0