File: //usr/lib/python3.9/site-packages/cloudinit/__pycache__/subp.cpython-39.opt-1.pyc
a
'�Dgp1 �
@ s d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
Z
mZmZ ddl
mZ e�e�Ze�ddd g�Zd
d� ZG dd
� d
e�Zee
e e
e f d�dd�Zdddddddddd� eeee
e e
e f ed�dd�Zd!dd�Zd"ee d�dd�Zdd� Zd#dd �ZdS )$z9Common utility functions for interacting with subprocess.� N)�ENOEXEC)�
TextIOWrapper)�List�Optional�Union)�performance�
SubpResult�stdout�stderrc C s� g }g }g }|D ]�}t |t�rR|d du r8|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.
r N� � 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)Zbase_commandZcommands�warningsr Zfixed_commandsZcommand� r �2/usr/lib/python3.9/site-packages/cloudinit/subp.py�prepend_base_command s:
�
��r c @ sH e Zd ZdZdZddd�Zdd� Zd
eee f eee f d �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 C s |p| j | _|r|| _n|s,|tkr,d| _nd| _t|t�r@|n| j | _|sb|d u rZ| j n|| _n| �|�| _|s�|d u r�| j n|| _ n| �|�| _ |p�| j | _
|r�|| _| j| �
| j�| �
| j�| �
| j�| �
| j �| �
| j�| �
| j
�d� }t�| |� d S )Nz(Exec format error. Missing #! in script?z'Unexpected error while running command.)�description�cmd� exit_coder r
�reason)�
empty_attrr"