U
|f+ @ st d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ddlm Z ddlm
Z
ddlmZ dd lm
Z
dd
lmZ ddlmZ ddlmZ dd
lmZ ddlmZ ddlmZ erddlmZ e
rddlZndZddddgZdd Zedk r.eedr.ededd ejD Zdd Zndd Zddeje edeje!ej"efddZ#dd Z$e d d Z%dS )!z%Routines common to all posix systems. N )MACOSTimeoutExpired)memoize)
sdiskusage)
usage_percent)PY3)ChildProcessError)FileNotFoundError)InterruptedError)PermissionError)ProcessLookupError)unicode)_psutil_osx
pid_existswait_pid
disk_usageget_terminal_mapc C sP | dkrdS zt | d W n* tk
r2 Y dS tk
rF Y dS X dS dS )z6Check whether pid exists in the current process table.r TFN)oskillr r
)pid r B/opt/alt/python38/lib64/python3.8/site-packages/psutil/_psposix.pyr ( s Signals Negsignalc C s g | ]}|j |j fqS r )namevalue).0xr r r
B s r c C s( z
t | W S tk
r" | Y S X dS )z+Convert a negative signal value to an enum.N)r
ValueErrornumr r r negsig_to_enumE s
r$ c C s | S )Nr r" r r r r$ N s monotonicc s dkrd}t |d} d}
dk r8|
tjO }
fdd}zt|
\}}
W nB tk
r || } Y qP tk
r |r|| } qY dS X |dkr|| } qPt|
rt|
S t|
rt t
|
S t d|
qPdS )a Wait for a process PID to terminate.
If the process terminated normally by calling exit(3) or _exit(2),
or by returning from main(), the return value is the positive integer
passed to *exit().
If it was terminated by a signal it returns the negated value of the
signal which caused the termination (e.g. -SIGTERM).
If PID is not a children of os.getpid() (current process) just
wait until the process disappears and return None.
If PID does not exist at all return None immediately.
If *timeout* != None and process is still alive raise TimeoutExpired.
timeout=0 is also possible (either return immediately or raise).
r zcan't wait for PID 0g-C6?Nc s6 d k r kr t d| | d dS )N)r r g{Gz?r )interval_min_sleep_timerr proc_nameZstop_attimeoutr r sleepw s
zwait_pid..sleepzunknown process exit status %r)r! r WNOHANGwaitpidr r
WIFEXITEDWEXITSTATUSWIFSIGNALEDr$ WTERMSIG)r r- r, _waitpidr+ r) r* Z_pid_existsmsgr' flagsr. Zretpidstatusr r( r r R s2
c C s t rt| }ndzt| }W nT tk
rr t| trlz| t } W n tk
r^ Y nX t| }n Y nX |j |j
}|j|j
}|j|j
}|| }t
rt| |}|| }t||dd}t||||dS )a. Return disk usage associated with path.
Note: UNIX usually reserves 5% disk space which is not accessible
by user. In this function "total" and "used" values reflect the
total and used disk space whereas "free" and "percent" represent
the "free" and "used percent" user disk space.
r )Zround_)totalusedfreepercent)r r statvfsUnicodeEncodeError
isinstancer encodesysgetfilesystemencodingf_blocksf_frsizef_bfreef_bavailr r Zdisk_usage_usedr r )pathstr9 Z
avail_to_rootZ
avail_to_userr: Z
total_userZusage_percent_userr r r r s4
c C s` i } t dt d }|D ]>}|| ks0t|z|| t|j<