Edit File: utils_cmd.cpython-37.opt-1.pyc
B �e� � @ sR d dl mZ d dlZd dlZd dlZG dd� de�Zdd� Zd d d �Zdd� Z dS )� )�absolute_importNc @ s e Zd ZdZded�dd�ZdS )�ExternalProgramFailedzCException class for errors related to externally executed commands.� )�messagec C s t �| |� d S )N)� Exception�__init__)�selfr � r ��/builddir/build/BUILDROOT/alt-python27-cllib-3.3.5-1.el8.cloudlinux.x86_64/opt/alt/python37/lib/python3.7/site-packages/clcommon/utils_cmd.pyr s zExternalProgramFailed.__init__N)r )�__name__� __module__�__qualname__�__doc__�strr r r r r r s r c C s* t j�| �s&td| � d�� t�d� dS )z6 Checks if command is present and exits if no zCommand not found: (�)� N)�os�path�exists�print�sys�exit)Zcmdnamer r r � check_command s r FTc C s� d� | �}y>|rtjntj}|r&tjntj}tj| |tj|d||d�}W n: tk r� } zt|� dt| �� ��| �W dd} ~ X Y nX |s�|� � \} }n|� |�\} }|r�|j | |fS |j dkr�|s�td|� ���nt|p�d|| f ��| S ) a[ Runs external process and returns output :param cmd: command and arguments as a list :param env_data: environment data for process :param return_full_output: if true, returns (ret_code, std_out, std_err) @return: process stdout if is_full_output==False else - cortege (ret_code, std_out, std_err) without any checking � T)�stdin�stdout�stderrZ close_fds�env�textz. Cannot run command: Nr z Error during command execution: zoutput of the command: %s %s)�join� subprocess�PIPEZSTDOUTZDEVNULL�Popen�OSErrorr r �communicate� returncode)�cmdZenv_dataZreturn_full_outputZstd_inZconvert_to_strZcmd_lineZstd_err_objZ stdin_arg�outputZoserrZstd_outZstd_errr r r �run_command s6 r( c C sJ t � }|�| � |�|� tj|tjdd�}|�� \}}|j}||�� fS )z� Executes supplied utility with supplied parameters :param util_path: Executable file to run path :param params: utility parameters :return: Cortege (ret_code, utility_stdout) T)r r ) �list�append�extendr r"