U
    ;gLG                     @   s  d Z ddlZ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 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gZeedZeedZeedZe Z ej!Z!ej"e
j#ej$e
j%ej&e
j'ej(e
j'ej)e
j*iZ+ej,e
j-ej.e
j/ej0e
j1ej2e
j3ej4e
j5ej6e
j7ej8e
j9ej:e
j;ej<e
j=ej>e
j?ej@e
jAejBe
jCiZDeEdddddddddZFeddd gZGeGZHed!d"d#d$d%gZIed&d'd(d)d*d+gZJd,d- ZKd.d/ ZLd0d1 ZMd2d3 ZNd4d5 ZOd6d7 ZPd8d9 ZQejRZRejSZSdNd;d<ZTejUZUerZejVZVdOd>d?ZWd@dA ZXdBdC ZYdDdE ZZdFdG Z[dHdI Z\dJdK Z]G dLdM dMZ^dS )PzAIX platform implementation.    N)
namedtuple   )_common)_psposix)_psutil_aix)_psutil_posix)NIC_DUPLEX_FULL)NIC_DUPLEX_HALF)NIC_DUPLEX_UNKNOWN)AccessDenied)NoSuchProcess)ZombieProcess)conn_to_ntuple)get_procfs_path)memoize_when_activated)usage_percentZPROCFS_PATHproc_threadsnet_io_countersproc_io_counters                  )ppidrssvmscreate_timenicenum_threadsstatusttynrpmemr   r   	scputimesusersystemZidleZiowaitsvmemtotal	availablepercentusedfreec                  C   s4   t  \} }}}}t| | | dd}t| ||||S )Nr   Zround_)cextZvirtual_memr   r'   )r(   Zavailr,   Z_pinnedZinuser*    r/   M/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/psutil/_psaix.pyvirtual_memoryg   s    r1   c                  C   s:   t  \} }}}| | }t|| dd}t| |||||S )z=Swap system memory as a (total, used, free, sin, sout) tuple.r   r-   )r.   Zswap_memr   r   Zsswap)r(   r,   sinZsoutr+   r*   r/   r/   r0   swap_memorym   s    r3   c                  C   s   t  } tdd t|  D  S )z.Return system-wide CPU times as a named tuple.c                 S   s   g | ]}t |qS r/   )sum.0xr/   r/   r0   
<listcomp>}   s     zcpu_times.<locals>.<listcomp>)r.   per_cpu_timesr$   zipretr/   r/   r0   	cpu_timesz   s    r=   c                  C   s   t  } dd | D S )z6Return system per-CPU times as a list of named tuples.c                 S   s   g | ]}t | qS r/   )r$   r5   r/   r/   r0   r8      s     z!per_cpu_times.<locals>.<listcomp>)r.   r9   r;   r/   r/   r0   r9      s    r9   c                   C   s(   zt dW S  tk
r"   Y dS X dS )z0Return the number of logical CPUs in the system.SC_NPROCESSORS_ONLNN)ossysconf
ValueErrorr/   r/   r/   r0   cpu_count_logical   s    rB   c                  C   sx   dddg} t j| t jt jd}| \}}dd ||fD \}}|jdkr`| d| }t||  }t|pvd S )	NZlsdevz-Cc	processorstdoutstderrc                 s   s   | ]}| tjjV  qd S NdecodesysrE   encodingr5   r/   r/   r0   	<genexpr>   s     z"cpu_count_cores.<locals>.<genexpr>r   z command error
)	
subprocessPopenPIPEcommunicate
returncodeRuntimeErrorstrip
splitlineslen)cmdprE   rF   msgZ
processorsr/   r/   r0   cpu_count_cores   s    

rY   c                  C   s    t  \} }}}t| |||S )z*Return various CPU stats as a named tuple.)r.   	cpu_statsr   Z	scpustats)Zctx_switchesZ
interruptsZsoft_interruptsZsyscallsr/   r/   r0   rZ      s       rZ   Fc           	      C   s\   g }t  }|D ]F}|\}}}}|dkr,d}| s<t|js<qt||||}|| q|S )zReturn system disk partitions.none )r.   disk_partitions
disk_usager(   r   Z	sdiskpartappend)	allretlistZ
partitions	partitionZdeviceZ
mountpointZfstypeoptsntupler/   r/   r0   r]      s    
r]   c                 C   s~   t j|  \}}t|}g }|D ]X}|\}}}	}
}}}||kr@q |	|krJq t|||	|
||t|dkrf|ndd}|| q |S )zReturn socket connections.  If pid == -1 return system-wide
    connections (as opposed to connections opened by one process only).
    re   Npid)r   Z	conn_tmapr.   net_connectionsr   TCP_STATUSESr_   )kind_pidZfamiliestypesrawlistr<   itemfdZfamtype_laddrraddrr!   rg   ntr/   r/   r0   rh      s*    

rh   c                  C   s   t td} dd t D }i }|D ]}t|}t|}d}d}tjdd|gtjtjd}|	 \}	}
d	d
 |	|
fD \}	}
|j
dkrtd|	}|dk	rt|d}|d}d|}d|k}| |t}t|||||||< q"|S )z)Get NIC stats (isup, duplex, speed, mtu).)FullZHalfc                 S   s   h | ]}|d  qS )r   r/   r5   r/   r/   r0   	<setcomp>   s     znet_if_stats.<locals>.<setcomp>r\   r   z/usr/bin/entstatz-drD   c                 s   s   | ]}| tjjV  qd S rG   rH   r5   r/   r/   r0   rL      s    znet_if_stats.<locals>.<genexpr>z"Running: (\d+) Mbps.*?(\w+) DuplexNr   r   ,running)r   r	   net_if_addrs
cext_posixZ
net_if_mtuZnet_if_flagsrM   rN   rO   rP   rQ   researchintgroupjoingetr
   r   Z	snicstats)Z
duplex_mapnamesr<   nameZmtuflagsZduplexspeedrW   rE   rF   Z	re_resultZoutput_flagsZisupr/   r/   r0   net_if_stats   s<    




 

r   c                   C   s   t  S )z:The system boot time expressed in seconds since the epoch.)r.   	boot_timer/   r/   r/   r0   r     s    r   c                  C   s\   g } t  }d}|D ]B}|\}}}}}}	|s.q||kr:d}t|||||	}
| |
 q| S )z:Return currently connected users as a list of namedtuples.)z:0.0z:0	localhost)r.   usersr   Zsuserr_   )ra   rm   r   rn   r%   ttyhostnameZtstampZuser_processrg   rs   r/   r/   r0   r     s    r   c                   C   s   dd t t D S )z7Returns a list of PIDs currently running on the system.c                 S   s   g | ]}|  rt|qS r/   )isdigitr|   r5   r/   r/   r0   r8   1  s      zpids.<locals>.<listcomp>)r?   listdirr   r/   r/   r/   r0   pids/  s    r   c                 C   s   t jt jt t| dS )z&Check for the existence of a unix pid.Zpsinfo)r?   pathexistsr~   r   strrf   r/   r/   r0   
pid_exists4  s    r   c                    s   t   fdd}|S )zCall callable into a try/except clause and translate ENOENT,
    EACCES and EPERM in NoSuchProcess or AccessDenied exceptions.
    c              
      s   | j | j| j  }}}z | f||W S  ttfk
rp } z&t|sRt|||t||||W 5 d }~X Y n. tk
r } zt	|||W 5 d }~X Y nX d S rG   )
rg   _ppid_nameFileNotFoundErrorProcessLookupErrorr   r   r   PermissionErrorr   )selfargskwargsrg   r   r   errfunr/   r0   wrapper>  s    z wrap_exceptions.<locals>.wrapper)	functoolswraps)r   r   r/   r   r0   wrap_exceptions9  s    r   c                   @   sx  e Zd ZdZdddddgZdd Zd	d
 Zdd Zee	dd Z
ee	dd Zedd Zedd Zedd Zedd Zedd Zedd Zeredd ZedAd d!Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 ZeZed4d5 Zd6d7 Z ed8d9 Z!ed:d; Z"edBd=d>Z#e$rted?d@ Z%d<S )CProcessz1Wrapper class around underlying C implementation._cacher   r   _procfs_pathrg   c                 C   s   || _ d | _d | _t | _d S rG   )rg   r   r   r   r   )r   rg   r/   r/   r0   __init__U  s    zProcess.__init__c                 C   s   | j |  | j|  d S rG   )_proc_basic_infoZcache_activate
_proc_credr   r/   r/   r0   oneshot_enter[  s    zProcess.oneshot_enterc                 C   s   | j |  | j|  d S rG   )r   Zcache_deactivater   r   r/   r/   r0   oneshot_exit_  s    zProcess.oneshot_exitc                 C   s   t | j| jS rG   )r.   Zproc_basic_inforg   r   r   r/   r/   r0   r   c  s    zProcess._proc_basic_infoc                 C   s   t | j| jS rG   )r.   Z	proc_credrg   r   r   r/   r/   r0   r   h  s    zProcess._proc_credc                 C   s$   | j dkrdS t| j | jdS )Nr   Zswapper )rg   r.   Z	proc_namer   rstripr   r/   r/   r0   r   m  s    
zProcess.namec                 C   s   |   }|sdS |d }tjj|krtj|sJtjtj|  |}tj|rttj|rtt	|tj
rt|S tj|}tjd dD ]<}tjtj||}tj|rt	|tj
r|  S qdS )Nr\   r   PATH:)cmdliner?   r   sepisabsabspathr~   cwdisfileaccessX_OKbasenameenvironsplit)r   r   exer   Zpossible_exer/   r/   r0   r   t  s.    

 
zProcess.exec                 C   s   t | jS rG   )r.   Z	proc_argsrg   r   r/   r/   r0   r     s    zProcess.cmdlinec                 C   s   t | jS rG   )r.   Zproc_environrg   r   r/   r/   r0   r     s    zProcess.environc                 C   s   |   td  S )Nr   r   proc_info_mapr   r/   r/   r0   r     s    zProcess.create_timec                 C   s   |   td  S )Nr    r   r   r/   r/   r0   r      s    zProcess.num_threadsc                 C   sX   t | j}g }|D ]"\}}}t|||}|| q|sTt| j d| j  |S )N/)	r.   r   rg   r   Zpthreadr_   r?   statr   )r   rm   ra   Z	thread_idutimeZstimerd   r/   r/   r0   threads  s    zProcess.threadsinetc                 C   s.   t || jd}|s*t| j d| j  |S )N)rk   r   )rh   rg   r?   r   r   )r   rj   r<   r/   r/   r0   rh     s    zProcess.net_connectionsc                 C   s   t | jS rG   )ry   getpriorityrg   r   r/   r/   r0   nice_get  s    zProcess.nice_getc                 C   s   t | j|S rG   )ry   setpriorityrg   )r   valuer/   r/   r0   nice_set  s    zProcess.nice_setc                 C   s   |   td  | _| jS )Nr   )r   r   r   r   r/   r/   r0   r     s    zProcess.ppidc                 C   s"   |   \}}}}}}t|||S rG   r   r   Zpuids)r   real	effectivesaved_r/   r/   r0   uids  s    zProcess.uidsc                 C   s"   |   \}}}}}}t|||S rG   r   )r   r   r   r   r   r/   r/   r0   gids  s    zProcess.gidsc                 C   s   t | j| j}tj| S rG   )r.   Zproc_cpu_timesrg   r   r   Z	pcputimes)r   tr/   r/   r0   r=     s    zProcess.cpu_timesc                 C   sP   |   td  }|d@ d? |d@ B }tdD ]}t|j|kr.|  S q.d S )Nr"   l           i  z	/dev/**/*)r   r   globr?   r   st_rdev)r   Zttydevdevr/   r/   r0   terminal  s    
zProcess.terminalc                 C   s\   | j }z$t| d| j d}|dW S  tk
rV   t| d| j  Y dS X d S )Nr   z/cwdr\   )r   r?   readlinkrg   r   r   r   )r   Zprocfs_pathresultr/   r/   r0   r     s    zProcess.cwdc                 C   s2   |   }|td  d }|td  d }t||S )Nr   i   r   )r   r   r#   )r   r<   r   r   r/   r/   r0   memory_info  s    zProcess.memory_infoc                 C   s   |   td  }t|dS )Nr!   ?)r   r   PROC_STATUSESr   )r   coder/   r/   r0   r!     s    zProcess.statusc                 C   s   t jddt| jgt jt jd}| \}}dd ||fD \}}d| kr\t| j| jt	
d|}g }|D ]J\}}| }|dr|d	d  }| d
krqp|t|t| qp|S )Nz/usr/bin/procfilesz-nrD   c                 s   s   | ]}| tjjV  qd S rG   rH   r5   r/   r/   r0   rL     s    z%Process.open_files.<locals>.<genexpr>zno such processz(\d+): S_IFREG.*name:(.*)\nz//r   zcannot be retrieved)rM   rN   r   rg   rO   rP   lowerr   r   rz   findallrS   
startswithr_   r   Z	popenfiler|   )r   rW   rE   rF   Z	procfilesra   ro   r   r/   r/   r0   
open_files  s*    

zProcess.open_filesc                 C   s,   | j dkrdS tt| j d| j  dS )Nr   r   z/fd)rg   rU   r?   r   r   r   r/   r/   r0   num_fds  s    
zProcess.num_fdsc                 C   s   t jt| j S rG   )r   Zpctxswr.   Zproc_num_ctx_switchesrg   r   r/   r/   r0   num_ctx_switches!  s    zProcess.num_ctx_switchesNc                 C   s   t | j|| jS rG   )r   Zwait_pidrg   r   )r   timeoutr/   r/   r0   wait%  s    zProcess.waitc              
   C   sh   zt | j\}}}}W n> tk
rV } z t| jsDt| j| j| W 5 d }~X Y nX t||||S rG   )	r.   r   rg   OSErrorr   r   r   r   Zpio)r   rcwcrbwbr   r/   r/   r0   io_counters+  s    
zProcess.io_counters)r   )N)&__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   r   r   r   r   r   r   r    HAS_THREADSr   rh   r   r   r   r   r   r=   r   r   r   Zmemory_full_infor!   r   r   r   r   HAS_PROC_IO_COUNTERSr   r/   r/   r/   r0   r   P  sv   















	



r   )F)re   )_r   r   r   r?   rz   rM   rJ   collectionsr   r\   r   r   r   r.   r   ry   r   r	   r
   r   r   r   r   r   r   r   Z__extra__all__hasattrr   ZHAS_NET_IO_COUNTERSr   ZgetpagesizeZ	PAGE_SIZEZAF_LINKZSIDLZSTATUS_IDLEZSZOMBZSTATUS_ZOMBIEZSACTIVEZSTATUS_RUNNINGZSSWAPZSSTOPZSTATUS_STOPPEDr   ZTCPS_ESTABLISHEDZCONN_ESTABLISHEDZTCPS_SYN_SENTZCONN_SYN_SENTZTCPS_SYN_RCVDZCONN_SYN_RECVZTCPS_FIN_WAIT_1ZCONN_FIN_WAIT1ZTCPS_FIN_WAIT_2ZCONN_FIN_WAIT2ZTCPS_TIME_WAITZCONN_TIME_WAITZTCPS_CLOSEDZ
CONN_CLOSEZTCPS_CLOSE_WAITZCONN_CLOSE_WAITZTCPS_LAST_ACKZCONN_LAST_ACKZTCPS_LISTENZCONN_LISTENZTCPS_CLOSINGZCONN_CLOSINGZPSUTIL_CONN_NONEZ	CONN_NONEri   dictr   r#   Zpfullmemr$   r'   r1   r3   r=   r9   rB   rY   rZ   Zdisk_io_countersr^   r]   rx   r   rh   r   r   r   r   r   r   r   r/   r/   r/   r0   <module>   s   


     	            	

+