%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/cloudinit/__pycache__/subp.cpython-35.pyc



"�T`A4�@s�dZddlZddlZddlZddlmZeje�Zdd�Z	Gdd�de
�Zddddd	d	d	d
dddddd�Zdd
d�Z
dddd�Zdd�Zdddd�ZdS)z9Common utility functions for interacting with subprocess.�N)�ENOEXECcCs#g}g}g}x�|D]�}t|t�rt|ddkrQ|dd�}q�|d|kr�|jd|�nHt|t�r�|jd|�s�|j|�n|jt|��q|j|�qW|r�tjd||dj|��|rt	dj
d|d	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%s 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�LOGZwarning�join�	TypeError�format)Zbase_commandZcommands�warningsrZfixed_commands�command�r�0/usr/lib/python3/dist-packages/cloudinit/subp.py�prepend_base_command
s0
	rc	@sXeZdZdZdZddddddddd�Zdd�Zdd	d
�ZdS)�ProcessExecutionErrorzr%(description)s
Command: %(cmd)s
Exit code: %(exit_code)s
Reason: %(reason)s
Stdout: %(stdout)s
Stderr: %(stderr)s�-Nc	Cs�|s|j|_n	||_|sO|rC|tkrCd|_qXd|_n	||_t|t�sv|j|_n	||_|s�|dkr�|j|_q�||_n|j|�|_|s�|dkr�|j|_	q�||_	n|j|�|_	|r||_
n|j|_
||_|jd|j
|j�d|j
|j�d|j
|j�d|j
|j	�d|j
|j�d|j
|j
�i}tj||�dS)	Nz(Exec format error. Missing #! in script?z'Unexpected error while running command.�description�cmd�	exit_code�stdout�stderr�reason)�
empty_attrrrrr�intrr�_indent_textrr�errno�MESSAGE_TMPL�_ensure_string�IOError�__init__)	�selfrrrrrrr!�messagerrrr%EsB				zProcessExecutionError.__init__cCst|t�r|j�S|S)z1
        if data is bytes object, decode
        )r�bytes�decode)r&�textrrrr#{sz$ProcessExecutionError._ensure_string�cCsTd}d|}t|t�r7|j�}|j�}|j|�j|||�S)zY
        indent text on all but the first line, allowing for easy to read output
        r� )rr(�encode�rstrip�replace)r&r*Zindent_levelZcr�indentrrrr �s
z"ProcessExecutionError._indent_text)�__name__�
__module__�__qualname__r"rr%r#r rrrrr;s3rTFr/c
s�|	dk	rtd��|dkr-dg}d}
|
rg|dkrNtj}|j�}|j|
�t|	�dkr�d|	gt|�}|r�t|t�r�dj|�n|}|dj	d|��|s�t
jd	||||r�d
n|�nt
jd|�d}d}d}|r7tj
}tj
}|rOtj
}tj}|dkrsttj�}
|
}n$tj
}t|t�s�|j�}t|t�r�|}n4t|t�r�|jd�}nd
d�|D�}z�yLtj|d|d|d|d|d|d|�}|j|�\}}Wnztk
r�}zZ|rW|d�td|d|d|jd�r~dndd�r�dnd�|�WYdd}~XnXWd|
r�|
j�X|s�|r�|s�d}|s�d}�rd�fdd�}||�}||�}|j}||krm|rL|dj	d|��td|d|d |d|��|r�|d!j	d|��||fS)"a2	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 env: a dictionary for the command's environment.
    :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 combine_capture:
        boolean indicating if stderr should be redirected to stdout. When True,
        interleaved stderr and stdout will be returned as the first element of
        a tuple, the second will be empty string or bytes (per decode).
        if combine_capture is True, then output is captured independent of
        the value of capture.
    :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 target:
        not supported, kwarg present only to make function signature similar
        to curtin's subp.
    :param update_env:
        update the enviornment for this command with this dictionary.
        this will not affect the current processes os.environ.
    :param status_cb:
        call this fuction with a single string argument before starting
        and after finishing.
    :param cwd:
        change the working directory to cwd before executing the command.

    :return
        if not capturing, return is (None, None)
        if capturing, stdout and stderr are returned.
            if decode:
                entries in tuple will be python2 unicode or python3 string
            if not decode:
                entries in tuple will be python2 string or python3 bytes
    Nz&target arg not supported by cloud-initr�/�chrootr,zBegin run command: {command}
rzFRunning command %s with allowed return codes %s (shell=%s, capture=%s)ZcombinezFRunning hidden command to protect sensitive input/output logstring: %szutf-8cSs4g|]*}t|t�r!|n|jd��qS)zutf-8)rr(r-)�.0�xrrr�
<listcomp>�s	zsubp.<locals>.<listcomp>rr�stdin�env�shell�cwdz1ERROR: End run command: invalid command provided
rrr!r�-�cs#t|t�s|S|j|��S)N)rr(r))�data�m)r)rr�ldecodeszsubp.<locals>.ldecodez%ERROR: End run command: exit({code})
�coderzEnd run command: exit({code})
)�
ValueError�os�environ�copy�update�target_pathrrrrr
�debug�
subprocess�PIPEZSTDOUT�open�devnullr(r-r
�PopenZcommunicate�OSErrorrr!�close�
returncode)�argsr?Zrcsr:�captureZcombine_capturer;Z	logstringr)�targetZ
update_envZ	status_cbr<Z
devnull_fprr9rrZ
bytes_argsZsp�out�err�erA�rcr)r)r�subp�s�6		
$										

		rYcCs�|dkrd}nSt|t�s7td|��n1tjj|�}|jd�rh|dd�}|sr|Sx0t|�r�|ddkr�|dd�}quWtjj||�S)N�r4zUnexpected input for target: %sz//rr)NrZ)	rr
rCrD�path�abspathr�lenr)rTr[rrrrH-s	rHcCs�t|�}tjj|kr7tt||��r7|S|dkr�dd�tjjdd�jtj�D�}|dkr�|}ndd�|D�}dd�|D�}xB|D]:}tjjj	||f�}tt||��r�|Sq�WdS)NcSsg|]}|jd��qS)�")�strip)r6�prrrr8Ns	zwhich.<locals>.<listcomp>�PATHrZr4cSs%g|]}|jd�r|�qS)r4)r)r6r`rrrr8Ss	cSs"g|]}tjj|��qSr)rDr[r\)r6r`rrrr8Vs	)
rHrDr[�sep�is_exerE�get�split�pathsepr)Zprogram�searchrT�pathsr[Zppathrrr�whichCs 	%	
ricCs%tjj|�o$tj|tj�S)N)rDr[�isfile�access�X_OK)Zfpathrrrrc`srcc	Csl|rtjj|�rdSg}g}|dkr>g}nEt|t�r_t|�g}n$t|t�rw|}ntd��x�ttj|��D]�}tjj	||�}t
|�r�|j|�yt||gdd�Wq�t
k
r)}ztj|�|j|�WYdd}~Xq�Xq�W|rh|rhtdt|�dj	|�t|�f��dS)Nz%exe_prefix must be None, str, or listrSFz3Runparts: %s failures (%s) in %s attempted commands�,)rDr[�isdirrr
rr�sorted�listdirrrcrrYrr
rI�RuntimeErrorr])	ZdirpZ
skip_no_existZ
exe_prefixZfailedZ	attempted�prefixZexe_nameZexe_pathrWrrr�runpartses0		

$rs)�__doc__ZloggingrDrJr!rZ	getLoggerr1r
rr$rrYrHrircrsrrrr�<module>s.U�

Zerion Mini Shell 1.0