File: //usr/lib/python3.6/site-packages/supervisor/__pycache__/rpcinterface.cpython-36.opt-1.pyc
3
�k�`� � @ s~ d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dl m
Z
mZ d dlm
Z
d dlmZ d dlmZ d d lmZ d d
lmZ d dlmZ d dlmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ d dlm Z d dlm!Z! d dlm"Z" d dlm#Z#m$Z$m%Z% dZ&G dd� d�Z'dd� Z(dd� Z)dd� Z*d d!� Z+d"d#� Z,d$d%� Z-dS )&� N)� as_string)�as_bytes)�unicode)� Automatic�
signal_number)�readFile)�tailFile)�
NotExecutable)�NotFound)�NoPermission)�
make_namespec)�split_namespec)�VERSION)�notify)�RemoteCommunicationEvent)�NOT_DONE_YET)�
capped_int�Faults�RPCError)�SupervisorStates)�getSupervisorStateDescription)�
ProcessStates)�getProcessStateDescription)�RUNNING_STATES�STOPPED_STATES�SIGNALLABLE_STATESz3.0c @ sn e Zd Zdd� Zdd� Zdd� ZeZdd� Zd d
� Zdd� Z d
d� Z
dd� ZeZdd� Z
dd� Zdd� Zdd� Zdd� Zdd� ZdTdd�Zd d!� ZdUd#d$�ZdVd%d&�ZdWd'd(�ZdXd)d*�ZdYd+d,�ZdZd-d.�Zd/d0� Zd1d2� Zd3d4� Zd5d6� Zd7d8� Zd9d:� Z d;d<� Z!d=d>� Z"d?d@� Z#dAdB� Z$e$Z%dCdD� Z&dEdF� Z'dGdH� Z(e(Z)dIdJ� Z*dKdL� Z+e+Z,dMdN� Z-dOdP� Z.dQdR� Z/dSS )[�SupervisorNamespaceRPCInterfacec C s
|| _ d S )N)�supervisord)�selfr � r �"/usr/lib/python3.6/rpcinterface.py�__init__0 s z(SupervisorNamespaceRPCInterface.__init__c C s4 || _ t| jjjt�r0| jjjtjk r0tt j
��d S )N)Zupdate_text�
isinstancer �options�mood�intr �RUNNINGr r ZSHUTDOWN_STATE)r �textr r r �_update3 s z'SupervisorNamespaceRPCInterface._updatec C s | j d� tS )zj Return the version of the RPC API used by supervisord
@return string version version id
�
getAPIVersion)r( �API_VERSION)r r r r r) ; s
z-SupervisorNamespaceRPCInterface.getAPIVersionc C s | j d� tS )zw Return the version of the supervisor package in use by supervisord
@return string version version id
�getSupervisorVersion)r( r )r r r r r+ E s
z4SupervisorNamespaceRPCInterface.getSupervisorVersionc C s | j d� | jjjS )zh Return identifying string of supervisord
@return string identifier identifying string
�getIdentification)r( r r# Z
identifier)r r r r r, M s
z1SupervisorNamespaceRPCInterface.getIdentificationc C s* | j d� | jjj}t|�}||d�}|S )z� Return current state of supervisord as a struct
@return struct A struct with keys int statecode, string statename
�getState)Z statecode� statename)r( r r# r$ r )r �stater. �datar r r r- U s
z(SupervisorNamespaceRPCInterface.getStatec C s | j d� | jjj� S )z@ Return the PID of supervisord
@return int PID
�getPID)r( r r# Zget_pid)r r r r r1 d s
z&SupervisorNamespaceRPCInterface.getPIDc C s� | j d� | jjj}|dks*tjj|� r6ttj |��yt
t|t|�t|���S t
k
r� } z|jd }ttt|���W Y dd}~X nX dS )z� Read length bytes from the main log starting at offset
@param int offset offset to start reading from.
@param int length number of bytes to read from the log.
@return string result Bytes of log
�readLogNr )r( r r# �logfile�os�path�existsr r �NO_FILEr r r% �
ValueError�args�getattr)r �offset�lengthr3 �inst�whyr r r r2 l s
z'SupervisorNamespaceRPCInterface.readLogc C s� | j d� | jjj}|dks,| jjj|� r6ttj��y| jjj|� W n" t t
fk
rj ttj��Y nX x6| jjjj
D ]&}t|d�rz| jjjjd� |j� qzW dS )z^ Clear the main log.
@return boolean result always returns True unless error
�clearLogN�reopenzreopening log fileT)r( r r# r3 r6 r r r7 �remove�OSError�IOError�FAILEDZloggerZhandlers�hasattr�infor@ )r r3 Zhandlerr r r r? � s
z(SupervisorNamespaceRPCInterface.clearLogc C s | j d� tj| jj_dS )zk Shut down the supervisor process
@return boolean result always returns True unless error
�shutdownT)r( r ZSHUTDOWNr r# r$ )r r r r rG � s
z(SupervisorNamespaceRPCInterface.shutdownc C s | j d� tj| jj_dS )zi Restart the supervisor process
@return boolean result always return True unless error
�restartT)r( r Z
RESTARTINGr r# r$ )r r r r rH � s
z'SupervisorNamespaceRPCInterface.restartc C s� | j d� y| jjjdd� W n. tk
rL } zttj|��W Y dd}~X nX | jj� \}}}dd� |D �}dd� |D �}dd� |D �}|||ggS ) a�
Reload the configuration.
The result contains three arrays containing names of process
groups:
* `added` gives the process groups that have been added
* `changed` gives the process groups whose contents have
changed
* `removed` gives the process groups that are no longer
in the configuration
@return array result [[added, changed, removed]]
�reloadConfigF)Zdo_usageNc S s g | ]
}|j �qS r )�name)�.0�groupr r r �
<listcomp>� s [email protected].<locals>.<listcomp>c S s g | ]
}|j �qS r )rJ )rK rL r r r rM � s c S s g | ]
}|j �qS r )rJ )rK rL r r r rM � s ) r( r r# Zprocess_configr8 r r ZCANT_REREADZdiff_to_active)r �msgZaddedZchangedZremovedr r r rI � s
z,SupervisorNamespaceRPCInterface.reloadConfigc C sX | j d� x<| jjjD ].}|j|kr| jj|�}|s@ttj|��dS qW ttj |��dS )z� Update the config for a running process from config file.
@param string name name of process group to add
@return boolean result true if successful
�addProcessGroupTN)
r( r r# �process_group_configsrJ Zadd_process_groupr r Z
ALREADY_ADDED�BAD_NAME)r rJ �config�resultr r r rO � s
z/SupervisorNamespaceRPCInterface.addProcessGroupc C sB | j d� || jjkr"ttj|��| jj|�}|s>ttj|��dS )z� Remove a stopped process from the active configuration.
@param string name name of process group to remove
@return boolean result Indicates whether the removal was successful
�removeProcessGroupT)r( r �process_groupsr r rQ Zremove_process_groupZ
STILL_RUNNING)r rJ rS r r r rT � s
z2SupervisorNamespaceRPCInterface.removeProcessGroupFc C s� g }|rxt | jjj� �}|j� x�|D ]L}| jj| }t |jj� �}|j� x$|D ]}|j| }|j||f� qRW q&W nXt | jjj� �} | j� x>| D ]6}t |jj� �}
|
j� x|
D ]}|j||f� q�W q�W |S )N)�listr rU �keys�sort� processes�append�values)r �lexical�
all_processesZgroup_names�
group_namerL Z
process_names�process_name�process�groupsrY r r r �_getAllProcesses� s&