File: //proc/thread-self/root/usr/libexec/kcare/python/kcarectl/__pycache__/process_utils.cpython-38.pyc
U
n�h, � @ s^ d dl Z d dlZd dlZddlmZmZ ej
ddd��Zddd �Zd
d� Z
dd
� Zdd� ZdS )� N� )� log_utils�utilsTc C sR |pd}|D ]&}t j�|| �}t j�|�r| S q|rJtd�| |���nd S d S )N)z /usr/sbinz/sbinz/usr/binz/binz{0} could not be found at {1})�os�path�join�isfile� Exception�format)�name�pathsZ raise_exc�it�fname� r �3/usr/libexec/kcare/python/kcarectl/process_utils.py�find_cmd s
r Fc
C s� |r
t jnd }|rt jnd }t j| |||d�}|�� \}}|j} |d k rRt�|�}|d k rdt�|�}t�t �
d�j|j||d�| �d�� | ||fS )N)�stdout�stderr�shellz�
Call result for `{cmd}`:
exit code {exit_code}
=== STDOUT ===
{stdout}
=== STDERR ===
{stderr}
=== END ===
� )Z exit_coder r �cmd)
�
subprocess�PIPE�PopenZcommunicate�
returncoder �nstrr �logdebug�textwrap�dedentr
r )
Zcommand�catch_stdout�catch_stderrr r r �pZstdout_capturedZstderr_captured�coder r r �run_command s(
�
��
r# c C s t | dd�\}}}|S )NT�r )r# )�args�_r r r r �check_output<