/
usr
/
libexec
/
kcare
/
python
/
kcarectl
/
__pycache__
/
New Directory
Upload File
HOME
a @�j� � @ s� d dl Z d dlZd dlZd dlZddlmZmZ ejddd��Z dd� Zdd d�Zddd �Zdd� Zdd� Zdd� 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/sbin�/usr/bin�/binz{0} could not be found at {1})�os�path�join�isfile� Exception�format)�name�paths� raise_exc�it�fname� r �3/usr/libexec/kcare/python/kcarectl/process_utils.py�find_cmd s r c C s( t dddd�} | d u r$tjddd� | S )N� systemctl)r r F)r z:systemctl utility wasn't found, assuming systemd is absent�� print_msg)r r �logwarn)r r r r �find_systemctl s r Fc C s� |r t jnd }|rt jnd }t j| |||d�}|�� \}} |j} |d urVtj|dd�}| d urltj| dd�} t�t � d�j|j|| d�| �d�� |r�| r�t � | | �}||_| |_|�| || fS )N)�stdout�stderr�shell�replace)�errorsz� Call result for `{cmd}`: exit code {exit_code} === STDOUT === {stdout} === STDERR === {stderr} === END === � )Z exit_coder r �cmd)� subprocess�PIPE�Popen�communicate� returncoder �nstrr �logdebug�textwrap�dedentr r �CalledProcessError�outputr )�command�catch_stdout�catch_stderrr �checkr r �pZstdout_capturedZstderr_captured�code�excr r r �run_command'