%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/current/lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/current/lib/python3/dist-packages/cloudinit/__pycache__/subp.cpython-38.pyc

U

�f2�
@sdZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZe�
e�Ze�dddg�Zd	d
�ZGdd�de�Zeeeeefd
�dd�Zdddddddddd�	eeeeeeefed�dd�Zddd�Zd dd�Zdd�Zd!dd�ZdS)"z9Common utility functions for interacting with subprocess.�N)�ENOEXEC)�
TextIOWrapper)�List�Union�
SubpResult�stdout�stderrcCs�g}g}g}|D]�}t|t�rR|ddkr8|dd�}q�|d|kr�|�d|�n6t|t�rx|�|�d��s�|�|�n|�t|��q|�|�q|r�t�d||d�|��|r�t	dj
|d�|�d���|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)Zbase_commandZcommands�warningsr
Zfixed_commandsZcommand�r�0/usr/lib/python3/dist-packages/cloudinit/subp.py�prepend_base_commands<

���rc@sHeZdZdZdZddd�Zdd�Zd
eee	feee	fd	�d
d�Z
dS)�ProcessExecutionErrorzr%(description)s
Command: %(cmd)s
Exit code: %(exit_code)s
Reason: %(reason)s
Stdout: %(stdout)s
Stderr: %(stderr)s�-Nc		Cs|p|j|_|r||_n|s,|tkr,d|_nd|_t|t�r@|n|j|_|sb|dkrZ|jn||_n|�|�|_|s�|dkr�|jn||_	n|�|�|_	|p�|j|_
|r�||_|j|�
|j�|�
|j�|�
|j�|�
|j	�|�
|j�|�
|j
�d�}t�||�dS)Nz(Exec format error. Missing #! in script?z'Unexpected error while running command.)�description�cmd�	exit_coderr�reason)�
empty_attrr rrr�intr!r�_indent_textrr"�errno�MESSAGE_TMPL�_ensure_string�IOError�__init__)	�selfrrr!r rr"r&�messagerrrr*Ps4
�





�zProcessExecutionError.__init__cCst|t�r|��S|S)z1
        if data is bytes object, decode
        �r�bytes�decode)r+�textrrrr(sz$ProcessExecutionError._ensure_string�)r0�returncCs>t|t�s$|�d��ddd|�S|�d��ddd|�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
        rr
�
� )rr.�rstrip�replace)r+r0Zindent_levelrrrr%�s	
z"ProcessExecutionError._indent_text)NNNNNNN)r1)�__name__�
__module__�__qualname__r'r#r*r(rrr.r%rrrrrEs"��
/�

�r)�argscCs@|D]6}t|t�st|d�st�d|�t|d|��d��qdS)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)rr.�hasattrrrr)r:Z	componentrrr�raise_on_invalid_command�s�r=TFr6)	�data�rcs�capture�shell�	logstringr/�
update_env�cwd�timeout)r:r2c	
s�|dkrdg}tj��}
|r&|
�|�|s>t�d||||�nt�d|�d}d}|rbtj}tj}|dkrrtj}
ntj}
t	|t
�s�|��}t	|t
�r�|}n,t	|t�r�|�d�}nt
|�dd�|D�}zZt��}tj||||
|
||d�}|j||	d	�\}}t��|}|d
k�rt�d||�WnNtk
�rn}z.t|||j��rHdnd
��rTdnd
d�|�W5d}~XYnX��r�d�fdd�	}||�}||�}|j}||k�r�t||||d��t||�S)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-8cSs$g|]}t|t�r|n|�d��qS)rF)rr.r;)�.0�xrrr�
<listcomp>szsubp.<locals>.<listcomp>)rr�stdin�envrArD)rEg�������?zcommand %s took %.3ss to runr�-)r r"r&rrcst|t�r|�|��S|S�Nr-)r>�m�r/rr�ldecode"szsubp.<locals>.ldecode)rrr!r )rF)�os�environ�copy�updater�debug�
subprocess�PIPEZDEVNULLrr.r;rr=�time�PopenZcommunicate�OSErrorrr&�
returncoder)r:r>r?r@rArBr/rCrDrErKrrrJZ
bytes_argsZbeforeZsp�out�errZtotal�erPZrcrrOr�subp�s�2

�	�


��	
��
�r_cCs�|dkrd}n<t|t�s(td|����n"tj�|�}|�d�rJ|dd�}|sR|St|�rt|ddkrt|dd�}qRtj�||�S)N)N��/zUnexpected input for target: z//r	r)	rr�
ValueErrorrQ�path�abspathr�lenr)�targetrcrrr�target_path0s

rgcCs�t|�}tjj|kr&tt||��r&|S|dkrhdd�tj�dd��tj�D�}|dkrZ|ndd�|D�}dd�|D�}|D],}tjj�	||f�}tt||��rz|SqzdS)NcSsg|]}|�d��qS)�")�strip�rG�prrrrIOszwhich.<locals>.<listcomp>�PATHr`racSsg|]}|�d�r|�qS)ra)rrjrrrrISs
cSsg|]}tj�|��qSr)rQrcrdrjrrrrIVs)
rgrQrc�sep�is_exerR�get�split�pathsepr)Zprogram�searchrf�pathsrcZppathrrr�whichEs��
rtcCstj�|�ot�|tj�SrM)rQrc�isfile�access�X_OK)Zfpathrrrrn`srnc	Cs<|rtj�|�sdSg}g}|dkr*g}n.t|t�r@t|�g}nt|t�rP|}ntd��tt�|��D]�}tj�	||�}t
|�r�|�|�zt||gdd�Wn6t
k
r�}zt�|�|�|�W5d}~XYnXqftj�|�r�t�d|�qft�d|�qf|�r8|�r8tdt|��dd�	|��d	t|��d
���dS)Nz%exe_prefix must be None, str, or listF)r@zjskipping %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)rQrc�isdirrrrr�sorted�listdirrrnrr_rrrUrur�RuntimeErrorre)	ZdirpZ
skip_no_existZ
exe_prefixZfailedZ	attempted�prefixZexe_nameZexe_pathr^rrr�runpartses<



�$�r~)NN)NN)TN)�__doc__�collectionsZloggingrQrVrXr&r�ior�typingrrZ	getLoggerr7r�
namedtuplerrr)rrr.r=r_rgrtrnr~rrrr�<module>s>
3N��



Zerion Mini Shell 1.0