
    vg                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$m%Z%m&Z& dZ' G d d          Z(d Z)d Z*d Z+d Z,d Z-d  Z.dS )!    N)	as_string)as_bytes)unicode)	Automaticsignal_number)readFile)tailFile)
BadCommand)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_STATESz3.0c                       e Zd Zd Zd Zd ZeZd Zd Zd Z	d Z
d ZeZd	 Zd
 Zd Zd Zd Zd Zd,dZd Zd-dZd-dZd-dZd-dZd-dZd-dZd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$e$Z%d# Z&d$ Z'd% Z(e(Z)d& Z*d' Z+e+Z,d( Z-d) Z.d* Z/d+S ).SupervisorNamespaceRPCInterfacec                     || _         d S Nsupervisord)selfr#   s     T/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/supervisor/rpcinterface.py__init__z(SupervisorNamespaceRPCInterface.__init__1   s    &    c                     || _         t          | j        j        j        t
                    r8| j        j        j        t          j        k     rt          t          j
                  d S d S r!   )update_text
isinstancer#   optionsmoodintr   RUNNINGr   r   SHUTDOWN_STATE)r$   texts     r%   _updatez'SupervisorNamespaceRPCInterface._update4   s^    (05s;; 	2%*-=-EEE60111	2 	2EEr'   c                 :    |                      d           t          S )zb Return the version of the RPC API used by supervisord

        @return string version id
        getAPIVersion)r1   API_VERSIONr$   s    r%   r3   z-SupervisorNamespaceRPCInterface.getAPIVersion<   s    
 	_%%%r'   c                 :    |                      d           t          S )zo Return the version of the supervisor package in use by supervisord

        @return string version id
        getSupervisorVersion)r1   r   r5   s    r%   r7   z4SupervisorNamespaceRPCInterface.getSupervisorVersionF   s    
 	+,,,r'   c                 N    |                      d           | j        j        j        S )zh Return identifying string of supervisord

        @return string identifier identifying string
        getIdentification)r1   r#   r+   
identifierr5   s    r%   r9   z1SupervisorNamespaceRPCInterface.getIdentificationN   s&    
 	()))'22r'   c                 z    |                      d           | j        j        j        }t	          |          }||d}|S )z Return current state of supervisord as a struct

        @return struct A struct with keys int statecode, string statename
        getState)	statecode	statename)r1   r#   r+   r,   r   )r$   stater>   datas       r%   r<   z(SupervisorNamespaceRPCInterface.getStateV   sJ    
 	Z    (-1%88	!  r'   c                 h    |                      d           | j        j                                        S )z@ Return the PID of supervisord

        @return int PID
        getPID)r1   r#   r+   get_pidr5   s    r%   rB   z&SupervisorNamespaceRPCInterface.getPIDe   s.    
 	X'//111r'   c           	         |                      d           | j        j        j        }|t          j                            |          st          t          j	        |          	 t          t          |t          |          t          |                              S # t          $ r4}|j        d         }t          t          t          |                    d}~ww xY w)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   )r1   r#   r+   logfileospathexistsr   r   NO_FILEr   r   r-   
ValueErrorargsgetattr)r$   offsetlengthrF   instwhys         r%   rE   z'SupervisorNamespaceRPCInterface.readLogm   s     	Y"*2?"'.."9"9?6>7333	1Xgs6{{CKKHHIII 	1 	1 	1)A,C763//000	1s   #7B 
C%/CCc                 &   |                      d           | j        j        j        }|| j        j                            |          st          t          j                  	 | j        j                            |           n.# t          t          f$ r t          t          j                  w xY w| j        j        j        j        D ]J}t          |d          r8| j        j        j                            d           |                                 KdS )z^ Clear the main log.

        @return boolean result always returns True unless error
        clearLogNreopenzreopening log fileT)r1   r#   r+   rF   rI   r   r   rJ   removeOSErrorIOErrorFAILEDloggerhandlershasattrinforT   )r$   rF   handlers      r%   rS   z(SupervisorNamespaceRPCInterface.clearLog   s   
 	Z   "*2?$"2":"A"A'"J"J?6>***	*$++G4444! 	* 	* 	*6=)))	* '/6? 	! 	!Gw)) ! (/445IJJJ   ts   "B +B-c                 f    |                      d           t          j        | j        j        _        dS )zk Shut down the supervisor process

        @return boolean result always returns True unless error
        shutdownT)r1   r   SHUTDOWNr#   r+   r,   r5   s    r%   r_   z(SupervisorNamespaceRPCInterface.shutdown   s,    
 	Z   (8(A %tr'   c                 f    |                      d           t          j        | j        j        _        dS )zi Restart the supervisor process

        @return boolean result  always return True unless error
        restartT)r1   r   
RESTARTINGr#   r+   r,   r5   s    r%   rb   z'SupervisorNamespaceRPCInterface.restart   s,    
 	Y(8(C %tr'   c                 V   |                      d           	 | j        j                            d           n,# t          $ r}t          t          j        |          d}~ww xY w| j                                        \  }}}d |D             }d |D             }d |D             }|||ggS )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)do_usageNc                     g | ]	}|j         
S  name.0groups     r%   
<listcomp>z@SupervisorNamespaceRPCInterface.reloadConfig.<locals>.<listcomp>   s    //////r'   c                     g | ]	}|j         
S rh   ri   rk   s     r%   rn   z@SupervisorNamespaceRPCInterface.reloadConfig.<locals>.<listcomp>       333%5:333r'   c                     g | ]	}|j         
S rh   ri   rk   s     r%   rn   z@SupervisorNamespaceRPCInterface.reloadConfig.<locals>.<listcomp>   rp   r'   )	r1   r#   r+   process_configrK   r   r   CANT_REREADdiff_to_active)r$   msgaddedchangedremoveds        r%   re   z,SupervisorNamespaceRPCInterface.reloadConfig   s      	^$$$	4$33U3CCCC 	4 	4 	46-s333	4 #'"2"A"A"C"Cw/////337333337333)**s    8 
A!AA!c                    |                      d           | j        j        j        D ]F}|j        |k    r9| j                            |          }|st          t          j        |           dS Gt          t          j	        |          )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
        addProcessGroupT)
r1   r#   r+   process_group_configsrj   add_process_groupr   r   ALREADY_ADDEDBAD_NAME)r$   rj   configresults       r%   rz   z/SupervisorNamespaceRPCInterface.addProcessGroup   s     	&'''&.D 	 	F{d"");;FCC ?"6#7>>>tt	 #
 v---r'   c                     |                      d           || j        j        vrt          t          j        |          | j                            |          }|st          t          j        |          dS )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)r1   r#   process_groupsr   r   r~   remove_process_groupSTILL_RUNNING)r$   rj   r   s      r%   r   z2SupervisorNamespaceRPCInterface.removeProcessGroup   sp     	)***t'6666?D111!66t<< 	76/666tr'   Fc                    g }|rt          | j        j                                                  }|                                 |D ]w}| j        j        |         }t          |j                                                  }|                                 |D ]&}|j        |         }|                    ||f           'xnt          | j        j                                                  }	|	                                 |	D ]X}t          |j                                                  }
|
                                 |
D ]}|                    ||f           Y|S r!   )listr#   r   keyssort	processesappendvalues)r$   lexicalall_processesgroup_names
group_namerm   process_namesprocess_nameprocessgroupsr   s              r%   _getAllProcessesz0SupervisorNamespaceRPCInterface._getAllProcesses   so     	;t/>CCEEFFK) ; ;
(7
C $U_%9%9%;%; < <""$$$$1 ; ;L#ol;G!((%)9::::;	; $*9@@BBCCFKKMMM ; ; !7!7!9!9::	   ( ; ;G!((%)9::::; r'   c                    t          |          \  }}| j        j                            |          }|t	          t
          j        |          ||d fS |j                            |          }|t	          t
          j        |          ||fS r!   )r   r#   r   getr   r   r~   r   )r$   rj   r   r   rm   r   s         r%   _getGroupAndProcessz3SupervisorNamespaceRPCInterface._getGroupAndProcess  s    #1$#7#7 
L /33J??=6?D111$;/%%l33?6?D111g~r'   Tc                   
 |                      d           |                               \  }

(t                    \  }}|                     ||          S 	 
                                \  }}nv# t
          $ r*}t          t          j        |j	        d                   d}~wt          t          t          f$ r*}t          t          j        |j	        d                   d}~ww xY w
                                t          v rt          t          j                  
                                t"          j        k    rt          t          j        dz            
                                 | j                                         
j        rt          t          j                  
                                 |r8
                                t"          j        k    r
fd}	d|	_        | |	_        |	S dS )z Start a process

        @param string name Process name (or ``group:name``, or ``group:*``)
        @param boolean wait Wait for process to be fully started
        @return boolean result     Always true unless error

        startProcessNr   z!%s is in an unknown process statec                     j         rt          t          j                                                  } | t
          j        t
          j        fvrt          t          j                  | t
          j        k    rdS t          S NT)
spawnerrr   r   SPAWN_ERROR	get_stater   STARTINGr.   ABNORMAL_TERMINATIONr   )r?   rj   r   s    r%   onwaitz<SupervisorNamespaceRPCInterface.startProcess.<locals>.onwaitO  st    # ="6#5t<<<))++!79N OOO"6#>EEEM1114##r'   皙?T)r1   r   r   startProcessGroupget_execv_argsr   r   r   rJ   rL   r
   r   r   NOT_EXECUTABLEr   r   ALREADY_STARTEDr   UNKNOWNrX   spawnr#   reapr   r   
transitionr.   delayrpcinterface)r$   rj   waitrm   r   r   filenameargvrQ   r   r   s    `        @r%   r   z,SupervisorNamespaceRPCInterface.startProcess  s    	^$$$11$77w?'5d';';$J))*d;;;	?$3355NHdd 	8 	8 	86>38A;777M<8 	? 	? 	?60#(1+>>>	? .00614888-"7776=>EG G G 	 	 	56-t444
 	 	G%%''=+@@@$ $ $ $ $ $  FL"&FMts$   A3 3
C&=%B""C&<%C!!C&c                    |                      d           | j        j                            |          t	          t
          j        |          t          j        	                                          }|
                                 fd|D             }t          |t          | j        |          }d|_        | |_        |S )z Start all processes in the group named 'name'

        @param string name     The group name
        @param boolean wait    Wait for each process to be fully started
        @return array result   An array of process status info structs
        r   Nc                     g | ]}|fS rh   rh   rl   r   rm   s     r%   rn   zESupervisorNamespaceRPCInterface.startProcessGroup.<locals>.<listcomp>s      AAA7ug&AAAr'   r   r   )r1   r#   r   r   r   r   r~   r   r   r   r   make_allfuncisNotRunningr   r   r   )r$   rj   r   r   startallrm   s        @r%   r   z1SupervisorNamespaceRPCInterface.startProcessGroupc  s     	())) /33D99=6?D111//1122	AAAAiAAA		<9J%)+ + +  $r'   c                     |                      d           |                                 }t          |t          | j        |          }d|_        | |_        |S )z Start all processes listed in the configuration file

        @param boolean wait    Wait for each process to be fully started
        @return array result   An array of process status info structs
        startAllProcessesr   r   )r1   r   r   r   r   r   r   )r$   r   r   r   s       r%   r   z1SupervisorNamespaceRPCInterface.startAllProcesses|  s^     	()))))++		<9J%)+ + +  $r'   c                    |                      d           |                     |          \  }(t          |          \  }}|                     ||          S                                 t
          vrt          t          j        |          	                                }|t          t          j
        |          | j                                         |r0                                t          vrfd}d|_        | |_        |S dS )a   Stop a process named by name

        @param string name  The name of the process to stop (or 'group:name')
        @param boolean wait        Wait for the process to be fully stopped
        @return boolean result     Always return True unless error
        stopProcessNc                  t                                                                        t          vrt          S dS r   )stop_reportr   r   r   r   s   r%   r   z;SupervisorNamespaceRPCInterface.stopProcess.<locals>.onwait  s9     ##%%%$$&&n<<''tr'   r   T)r1   r   r   stopProcessGroupr   r   r   r   NOT_RUNNINGstoprX   r#   r   r   r   r   )	r$   rj   r   rm   r   r   ru   r   r   s	           @r%   r   z+SupervisorNamespaceRPCInterface.stopProcess  s    	]###11$77w?'5d';';$J((T:::n446-t444llnn?6=#... 	 	G%%''~==     FL"&FMtr'   c                    |                      d           | j        j                            |          t	          t
          j        |          t          j        	                                          }|
                                 fd|D             }t          |t          | j        |          }d|_        | |_        |S )z Stop all processes in the process group named 'name'

        @param string name     The group name
        @param boolean wait    Wait for each process to be fully stopped
        @return array result   An array of process status info structs
        r   Nc                     g | ]}|fS rh   rh   r   s     r%   rn   zDSupervisorNamespaceRPCInterface.stopProcessGroup.<locals>.<listcomp>  r   r'   r   r   )r1   r#   r   r   r   r   r~   r   r   r   r   r   	isRunningr   r   r   )r$   rj   r   r   killallrm   s        @r%   r   z0SupervisorNamespaceRPCInterface.stopProcessGroup  s     	'((( /33D99=6?D111//1122	AAAAiAAA	y)T5E$(* * * #r'   c                     |                      d           |                                 }t          |t          | j        |          }d|_        | |_        |S )z Stop all processes in the process list

        @param  boolean wait   Wait for each process to be fully stopped
        @return array result   An array of process status info structs
        stopAllProcessesr   r   )r1   r   r   r   r   r   r   )r$   r   r   r   s       r%   r   z0SupervisorNamespaceRPCInterface.stopAllProcesses  s^     	'((())++	y)T5E$(* * * #r'   c                    |                      d           |                     |          \  }}|)t          |          \  }}|                     ||          S 	 t	          |          }n(# t
          $ r t          t          j        |          w xY w|	                                t          vrt          t          j        |          |                    |          }|t          t          j        |          dS )z Send an arbitrary UNIX signal to the process named by name

        @param string name    Name of the process to signal (or 'group:name')
        @param string signal  Signal to send, as name ('HUP') or number ('1')
        @return boolean
        signalProcessNsignalT)r1   r   r   signalProcessGroupr   rK   r   r   
BAD_SIGNALr   r   r   r   rX   )	r$   rj   r   rm   r   r   r   sigru   s	            r%   r   z-SupervisorNamespaceRPCInterface.signalProcess  s     	_%%%11$77w?'5d';';$J**:f*EEE	6''CC 	6 	6 	66,f555	6 &8886-t444nnS!!{6=#...ts   A* *%Bc                    | j         j                            |          |                     d           t	          t
          j        |          t          j        	                                          }|
                                 fd|D             }t          |t          | j        |          } |            }|                     d           |S )z Send a signal to all processes in the group named 'name'

        @param string name    The group name
        @param string signal  Signal to send, as name ('HUP') or number ('1')
        @return array
        r   Nc                     g | ]}|fS rh   rh   r   s     r%   rn   zFSupervisorNamespaceRPCInterface.signalProcessGroup.<locals>.<listcomp>  s    ???'eW%???r'   r   )r#   r   r   r1   r   r   r~   r   r   r   r   r   isSignallabler   )r$   rj   r   r   sendallr   rm   s         @r%   r   z2SupervisorNamespaceRPCInterface.signalProcessGroup  s      /33D99)***=6?D111//1122	????Y???	y-9K&,. . .)***r'   c                     |                                  }t          |t          | j        |          } |            }|                     d           |S )z Send a signal to all processes in the process list

        @param string signal  Signal to send, as name ('HUP') or number ('1')
        @return array         An array of process status info structs
        r   signalAllProcesses)r   r   r   r   r1   )r$   r   r   	signalallr   s        r%   r   z2SupervisorNamespaceRPCInterface.signalAllProcesses!  sX     ))++	 M4;M  	)***r'   c                 t   |                      d           g }| j        j        j        D ]v}|j        | j        j        v }|j        D ]W}i d|j        d|j        d|j	        d|j
        d|j        d|j        d|j        d	|d
|j        d|j        d|j        d|j        d|j        d|j        d|j        d|j        d|j        |j        |j        |j        t/          |j                  |j        |j        |j        |j        |j        |j        |j        |j         d}|!                    d |"                                D                        |!                    d |"                                D                        |#                    |           Yx|$                    d            |S )z Get info about all available process configurations. Each struct
        represents a single process (i.e. groups get flattened).

        @return array result  An array of process config info structs
        getAllConfigInfo	autostart	directoryuidcommand	exitcodesrm   
group_prioinusekillasgrouprj   process_prioredirect_stderrstartretries	startsecsstdout_capture_maxbytesstdout_events_enabledstdout_logfile)stdout_logfile_backupsstdout_logfile_maxbytesstdout_syslog
stopsignalstopwaitsecsstderr_capture_maxbytesstderr_events_enabledstderr_logfilestderr_logfile_backupsstderr_logfile_maxbytesstderr_syslog	serverurlc              3   6   K   | ]\  }}|t           u |d fV  dS )autoN)r   rl   kvs      r%   	<genexpr>zCSupervisorNamespaceRPCInterface.getAllConfigInfo.<locals>.<genexpr>Y  s.      MMAa9nn!VnnnnMMr'   c              3   (   K   | ]\  }}||dfV  d S )Nnonerh   r   s      r%   r   zCSupervisorNamespaceRPCInterface.getAllConfigInfo.<locals>.<genexpr>Z  s*      HHAai!ViiiiHHr'   c                     | d         S )Nrj   rh   )rs    r%   <lambda>zBSupervisorNamespaceRPCInterface.getAllConfigInfo.<locals>.<lambda>]  s
    ai r'   )key)%r1   r#   r+   r{   rj   r   process_configsr   r   r   r   r   priorityr   r   r   r   r   r   r   r   r   r   r-   r   r   r   r   r   r   r   r   r   updateitemsr   r   )r$   
configinfogconfigr   pconfigds         r%   r   z0SupervisorNamespaceRPCInterface.getAllConfigInfo.  sC    	'(((
'/E $	% $	%GLD$4$CCE"2 "% "%['"3  '"3GK  !'"3	
 gl "7#3 e #G$7 W\ $W%5 '(? $W%9 !'"3 /0O -g.K  &w'=!" 07/M070O&-&;#&w'9#:#:%,%9070O.5.K'.'=/6/M070O&-&;")"39  > MMMMMMMMHHHHHHHH!!!$$$$E"%H 	//000r'   c                    |d         }|t           j        k    r|d         }|d         }t          j        t          j        |          d d          }t          j        t          j        |          d d          }||z
  }t          |          dk     rt          j        d          }d|d         d|}n|t           j        t           j        fv r|d	         }|sd
|d         z  }nm|t           j	        t           j
        fv rQ|d         rF|d         }	t          j        t          j        |	          d d          }
|
                    d          }nd}nd}|S )Nr?   startnow   r   zpid pidz	, uptime r   zunknown error (try "tail %s")rj   r      z%b %d %I:%M %pzNot started )r   r.   datetimetimegmtime_total_seconds	timedeltaFATALBACKOFFSTOPPEDEXITED	localtimestrftime)r$   r\   r?   r	  r
  start_dtnow_dtuptimedescr   stop_dts              r%   _interpretProcessInfoz5SupervisorNamespaceRPCInterface._interpretProcessInfo`  s[   WM)))MEu+C($+e*<*<RaR*@AH&C(8(8!(<=Fh&Ff%%))!+A..*.u+++vv>DD}*M,ABBB
#D F6fE},m.BCCCG} %F|"+T^D-A-A"1"-EF''(899$ Dr'   c                 N   |                      d           |                     |          \  }}|t          t          j        |          t          |j                  }t          |j                  }t          |                                           }|	                                }|j
        pd}|j        pd}	|j        j        pd}
|j        j        pd}|j        j        |j        j        ||||t!          |          ||	|
|
||j        d}|                     |          }||d<   |S )z Get info about a process named name

        @param string name The name of the process (or 'group:name')
        @return struct result     A structure containing data about the process
        getProcessInfoNr  r   )rj   rm   r	  r   r
  r?   r>   r   
exitstatusrF   r   r   r  description)r1   r   r   r   r~   r   	laststartlaststop_nowr   r   r"  r   r   r   rj   r   r  r  )r$   rj   rm   r   r	  r   r
  r?   r   r"  r   r   r\   r#  s                 r%   r!  z.SupervisorNamespaceRPCInterface.getProcessInfo  s2    	%&&&11$77w?6?D111
 7,--'*++%%!!###)r',1
 6<" 6<" >&L%2599#$+++   0066)]r'   c                 (    t          j                     S r!   )r  r5   s    r%   r&  z$SupervisorNamespaceRPCInterface._now  s    y{{r'   c                    |                      d           |                     d          }g }|D ]Q\  }}t          |j        j        |j        j                  }|                    |                     |                     R|S )zh Get info about all processes

        @return array result  An array of process status results
        getAllProcessInfoT)r   )r1   r   r   r   rj   r   r!  )r$   r   outputrm   r   rj   s         r%   r)  z1SupervisorNamespaceRPCInterface.getAllProcessInfo  s    
 	()))--d-;;+ 	5 	5NE7 !2GN4GHHDMM$--d334444r'   c           	         |                      |          \  }}|t          t          j        |          t	          |j        d|z            }|t          j                            |          st          t          j	        |          	 t          t          |t          |          t          |                              S # t          $ r4}|j        d         }	t          t	          t          |	                    d }~ww xY w)N
%s_logfiler   )r   r   r   r~   rM   r   rG   rH   rI   rJ   r   r   r-   rK   rL   )
r$   rj   rN   rO   channelrm   r   rF   rP   rQ   s
             r%   _readProcessLogz/SupervisorNamespaceRPCInterface._readProcessLog  s    11$77w?6?D111'.,*@AA?"'.."9"9?6>7333	1Xgs6{{CKKHHIII 	1 	1 	1)A,C763//000	1s   	7C 
C?/C::C?c                 \    |                      d           |                     |||d          S )aI   Read length bytes from name's stdout log starting at offset

        @param string name        the name of the process (or 'group:name')
        @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
        readProcessStdoutLogstdoutr1   r.  r$   rj   rN   rO   s       r%   r0  z4SupervisorNamespaceRPCInterface.readProcessStdoutLog  1     	+,,,##D&&(CCCr'   c                 \    |                      d           |                     |||d          S )aI   Read length bytes from name's stderr log starting at offset

        @param string name        the name of the process (or 'group:name')
        @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
        readProcessStderrLogstderrr2  r3  s       r%   r6  z4SupervisorNamespaceRPCInterface.readProcessStderrLog  r4  r'   c                 :   |                      |          \  }}|t          t          j        |          t	          |j        d|z            }|t          j                            |          sg dS t          |t          |          t          |                    S )Nr,  )r  r   F)r   r   r   r~   rM   r   rG   rH   rI   r	   r-   )r$   rj   rN   rO   r-  rm   r   rF   s           r%   _tailProcessLogz/SupervisorNamespaceRPCInterface._tailProcessLog  s    11$77w?6?D111'.,*@AA?"'.."9"9?!>>!Vc&kk:::r'   c                 \    |                      d           |                     |||d          S )a  
        Provides a more efficient way to tail the (stdout) log than
        readProcessStdoutLog().  Use readProcessStdoutLog() to read
        chunks and tailProcessStdoutLog() to tail.

        Requests (length) bytes from the (name)'s log, starting at
        (offset).  If the total log size is greater than (offset +
        length), the overflow flag is set and the (offset) is
        automatically increased to position the buffer at the end of
        the log.  If less than (length) bytes are available, the
        maximum number of available bytes will be returned.  (offset)
        returned is always the last offset in the log +1.

        @param string name         the name of the process (or 'group:name')
        @param int offset          offset to start reading from
        @param int length          maximum number of bytes to return
        @return array result       [string bytes, int offset, bool overflow]
        tailProcessStdoutLogr1  r1   r9  r3  s       r%   r;  z4SupervisorNamespaceRPCInterface.tailProcessStdoutLog  1    & 	+,,,##D&&(CCCr'   c                 \    |                      d           |                     |||d          S )a  
        Provides a more efficient way to tail the (stderr) log than
        readProcessStderrLog().  Use readProcessStderrLog() to read
        chunks and tailProcessStderrLog() to tail.

        Requests (length) bytes from the (name)'s log, starting at
        (offset).  If the total log size is greater than (offset +
        length), the overflow flag is set and the (offset) is
        automatically increased to position the buffer at the end of
        the log.  If less than (length) bytes are available, the
        maximum number of available bytes will be returned.  (offset)
        returned is always the last offset in the log +1.

        @param string name         the name of the process (or 'group:name')
        @param int offset          offset to start reading from
        @param int length          maximum number of bytes to return
        @return array result       [string bytes, int offset, bool overflow]
        tailProcessStderrLogr7  r<  r3  s       r%   r?  z4SupervisorNamespaceRPCInterface.tailProcessStderrLog  r=  r'   c                 "   |                      d           |                     |          \  }}|t          t          j        |          	 |                                 n/# t          t          f$ r t          t          j        |          w xY wdS )z Clear the stdout and stderr logs for the named process and
        reopen them.

        @param string name   The name of the process (or 'group:name')
        @return boolean result      Always True unless error
        clearProcessLogsNT)	r1   r   r   r   r~   
removelogsrW   rV   rX   )r$   rj   rm   r   s       r%   rA  z0SupervisorNamespaceRPCInterface.clearProcessLogs$  s     	'(((11$77w?6?D111	0    ! 	0 	0 	06=$///	0 ts   A   ,Bc                     |                      d           g g |                                 }|D ]"\  }}                    ||| j        f           #fd}d|_        | |_        |S )zm Clear all process log files

        @return array result   An array of process status info structs
        clearAllProcessLogsc                     sS                      d          \  } }}t          | j        j        |j        j                  }	  ||                               |j        j        | j        j        t
          j        dd           nO# t          $ rB}                    |j        j        | j        j        |j        |j	        d           Y d }~nd }~ww xY wrt          S S )Nr   OKrj   rm   statusr#  )popr   r   rj   r   r   SUCCESSr   coder0   r   )rm   r   callbackrj   e	callbacksresultss        r%   clearallzESupervisorNamespaceRPCInterface.clearAllProcessLogs.<locals>.clearallJ  s    '0}}Q'7'7$E7H !2GN4GHHD #N/"\.$n#') )     , , ,#N/"\.f#$6+ +, , , , , , , ,,  $##Ns   B 
C8CCr   )r1   r   r   clearProcessLogr   r   )r$   r   rm   r   rP  rN  rO  s        @@r%   rD  z3SupervisorNamespaceRPCInterface.clearAllProcessLogs<  s    
 	*+++	--//+ 	E 	ENE7eWd.BCDDDD	 	 	 	 	 	6  $r'   c                 <   |                      d           t          |t          t          t          f          st          t          j        |          t          |          }| 	                    |          \  }}|t          t          j
        |          |j        r|j        rt          t          j        |          	 |                    |           nH# t          $ r;}|j        d         t"          j        k    rt          t          j        |           d}~ww xY wdS )a   Send a string of chars to the stdin of the process name.
        If non-7-bit data is sent (unicode), it is encoded to utf-8
        before being sent to the process' stdin.  If chars is not a
        string or is not unicode, raise INCORRECT_PARAMETERS.  If the
        process is not running, raise NOT_RUNNING.  If the process'
        stdin cannot accept input (e.g. it was closed by the child
        process), raise NO_FILE.

        @param string name        The process name to send to (or 'group:name')
        @param string chars       The character data to send to the process
        @return boolean result    Always return True unless error
        sendProcessStdinNr   T)r1   r*   strbytesr   r   r   INCORRECT_PARAMETERSr   r   r~   r  killingr   writerV   rL   errnoEPIPErJ   )r$   rj   charsrm   r   rQ   s         r%   rS  z0SupervisorNamespaceRPCInterface.sendProcessStdini  s
    	'(((%#ug!677 	?66>>>11$77w?6?D111{ 	5go 	56-t444	MM%     	 	 	x{ek))v~t444		 ts   >C 
D6DDc                     t          |t                    r|                    d          }t          |t                    r|                    d          }t          t	          ||                     dS )aB   Send an event that will be received by event listener
        subprocesses subscribing to the RemoteCommunicationEvent.

        @param  string  type  String for the "type" key in the event header
        @param  string  data  Data for the event body
        @return boolean       Always return True unless error
        zutf-8T)r*   r   encoder   r   )r$   typer@   s      r%   sendRemoteCommEventz3SupervisorNamespaceRPCInterface.sendRemoteCommEvent  sp     dG$$ 	(;;w''DdG$$ 	(;;w''D$T400	
 	
 	
 tr'   N)F)T)0__name__
__module____qualname__r&   r1   r3   
getVersionr7   r9   r<   rB   rE   readMainLogrS   r_   rb   re   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r!  r&  r)  r.  r0  readProcessLogr6  r9  r;  tailProcessLogr?  rA  rQ  rD  rS  r_  rh   r'   r%   r   r   0   s       ' ' '2 2 2   J  3 3 3  2 2 21 1 1( K  .    + + +:. . .      6  "L L L L\   2    1 1 1 1f   2   "  >  2  0 0 0d  >, , ,\    1 1 1"	D 	D 	D *N	D 	D 	D; ; ;D D D, *ND D D,  , 'O+ + +Z$ $ $L    r'   r   c                 B    | j         dz  | j        z   dz  | j        z   dz  S )NiQ i@B )dayssecondsmicroseconds)r  s    r%   r  r    s1    ^e#i&775@&'*/0 0r'   c                 "    g }g }| |||||fd}|S )zl Return a closure representing a function that calls a
    function for every process, and returns a result c           	         |s| D ]\  }}t          |j        j        |j        j                  } ||          r	  ||fi |}	nO# t          $ rB}
|                    |j        j        |j        j        |
j        |
j        d           Y d }
~
d }
~
ww xY wt          |	t          j	                  r|                    |||	f           |                    |j        j        |j        j        t          j        dd           |s|S |d d          D ]}|\  }}}	  |            }|t          urM|                    |j        j        |j        j        t          j        dd           |                    |           j# t          $ rW}
|                    |j        j        |j        j        |
j        |
j        d           |                    |           Y d }
~
d }
~
ww xY w|rt          S |S )NrG  rF  )r   r   rj   r   r   rK  r0   r*   typesFunctionTyper   rJ  r   rU   )r   	predicatefuncextra_kwargsrN  rO  rm   r   rj   rL  rM  structcbvalues                 r%   allfunczmake_allfunc.<locals>.allfunc  sn     	"+  w$U\%68KLL9W%% !#'4#=#=#=#=# ! ! !w~/B050A1267f(> (> ? ? ? !! "(E,>?? !((%()CDDDD$+N$7%*\%6&,n+/1 1    	Nl 	- 	-F!'E7B- ,,NN ' 3!&!2"(.'+- -   $$V,,,  ) ) )#N/"\.f#$6+ +, , ,
   (((((((()"  	 s0   	A
B8BB
E77
GAGGrh   )r   ro  rp  rq  rN  rO  ru  s          r%   r   r     s>     IG != = = =b Nr'   c                 8    |                                  t          v S r!   )r   r   r   s    r%   r   r      s    .00r'   c                 "    t          |            S r!   )r   r   s    r%   r   r     s    !!!!r'   c                 @    |                                  t          v rdS d S r   )r   r   r   s    r%   r   r     s'    000t 10r'   c                      t          |           S r!   )r   r"   s    r%   make_main_rpcinterfacerz    s    *;777r'   )/rG   r  r  rY  rm  supervisor.compatr   r   r   supervisor.datatypesr   r   supervisor.optionsr   r	   r
   r   r   r   r   r   r   supervisor.eventsr   r   supervisor.httpr   supervisor.xmlrpcr   r   r   supervisor.statesr   r   r   r   r   r   r   r4   r   r  r   r   r   r   rz  rh   r'   r%   <module>r     s   				     ' ' ' ' ' ' & & & & & & % % % % % %       
 ( ' ' ' ' ' ' ' ' ' ' ' ) ) ) ) ) ) , , , , , , ' ' ' ' ' ' + + + + + + , , , , , , - - - - - - & & & & & & $ $ $ $ $ $ 6 6 6 6 6 6 ( ( ( ( ( (          / . . . . . ; ; ; ; ; ; + + + + + + 8 8 8 8 8 8          p p p p p p p pd0 0 0X X Xt1 1 1" " "  
8 8 8 8 8r'   