Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/tracer/resources/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/tracer/resources/__pycache__/processes.cpython-36.pyc

3

"eq#�@s�ddlmZddlmZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
Gdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de
ee��ZGdd�de�ZdS)�)�ProcessesCollection)�FilenameCleaner�N)�PIPE�Popen)�Timer)�with_metaclassc@s$eZdZedd��Zedd��ZdS)�	ProcessescCs&ytj�Stk
r tj�SXdS)N)�psutil�pids�AttributeErrorZget_pid_list�r
r
�/usr/lib/python3.6/processes.pyr!szProcesses.pidscCsZt�}xNtj�D]B}y|jt|��Wqtjk
r<Yqtjk
rPYqXqW|S)N)rr	r�append�Processr
Z
NoSuchProcess�AccessDenied)Z	processes�pidr
r
r�all(s
z
Processes.allN)�__name__�
__module__�__qualname__�staticmethodrrr
r
r
rr	sr	c@s�eZdZdZd!dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
d"dd�Zdd�Zdd�Zd#dd �ZdS)$�ProcessWrappera�
	Wrapper for ``psutil.Process class``
	Library ``psutil`` is not backward compatible from version 2.x.x to 1.x.x.

	Purpose of this class is cover incompatibility in ``psutil.Process`` class and
	provide interface of new version. It allows using new interface even with
	old version of ``psutil``.

	Note that, for performance reasons, process information is cached at
	object creation. To force a refresh, invoke the ``rebuild_cache()``
	method.
	NcCstj|�|_|j�dS)N)r
r�_process�
rebuild_cache)�selfrr
r
r�__init__AszProcessWrapper.__init__cCs
t|j�S)N)�boolr)rr
r
r�__nonzero__EszProcessWrapper.__nonzero__cCs |jjddddddgd�|_dS)N�name�exe�cmdline�ppid�username�create_time)Zattrs)rZas_dict�	_procdict)rr
r
rrHszProcessWrapper.rebuild_cachecCs|yZ|jd�dkrX|jd�|jd�krXt|jd��dkrX|jd�djd�d}dj|�SWntjk
rpYnX|jd�S)	NrZsshdr r!r�@rzssh-{0}-session)�_attr�len�split�formatr
r)rr#r
r
rrKs&zProcessWrapper.namecCs
|jd�S)Nr )r')rr
r
rr WszProcessWrapper.execCs
|jd�S)Nr!)r')rr
r
rr!ZszProcessWrapper.cmdlinecCs
|jd�S)Nr")r')rr
r
rr"]szProcessWrapper.ppidcCs
|jd�S)N�parent)r')rr
r
rr+`szProcessWrapper.parentcCs
|jd�S)Nr#)r')rr
r
rr#cszProcessWrapper.usernamecCs
|jd�S)Nr$)r')rr
r
rr$fszProcessWrapper.create_timeFcCs\dj|�}||jkrRy|jj|�|j|<Wn&tk
rP|jj|�|j|<YnX|j|S)Nzchildren-{0})r*r%r�childrenrZget_children)r�	recursive�keyr
r
rr,is

zProcessWrapper.childrencCsP||jkrFt|j|�}y|�|j|<Wntk
rD||j|<YnX|j|S)N)r%�getattrr�	TypeError)rr�attrr
r
rr'rs
zProcessWrapper._attrcCst|j|�S)N)r/r)r�itemr
r
r�__getattr__{szProcessWrapper.__getattr__TcCs`dj|�}||jkrVy|jj|d�|j|<Wn(tk
rT|jj|d�|j|<YnX|j|S)Nzmemory_maps-{0})�grouped)r*r%r�memory_mapsrZget_memory_maps)rr4r.r
r
rr5s

zProcessWrapper.memory_maps)N)F)T)rrr�__doc__rrrrr r!r"r+r#r$r,r'r3r5r
r
r
rr3s

		rcs(eZdZdZ�fdd�Zdd�Z�ZS)�ProcessMetaz�
	Caching metaclass that ensures that only one ``Process`` object is ever
	instantiated for any given PID. The cache can be cleared by calling
	``Process.reset_cache()``.

	Based on https://stackoverflow.com/a/33458129
	cs6tt��j|||��fdd�}|�t�d|�dS)Ncs
i�_dS)N)�_cacher
)�clsr
r�reset_cache�sz)ProcessMeta.__init__.<locals>.reset_cacher:)�superr7r�setattr)r9r�basesZ
attributesr:)�	__class__)r9rr�szProcessMeta.__init__cOsJ|d}||jkr@|j|f|�|�}|j|f|�|�||j|<|j|S)Nr)r8�__new__r)r9�args�kwargsrrr
r
r�__call__�s

zProcessMeta.__call__)rrrr6rrB�
__classcell__r
r
)r>rr7�sr7cs�eZdZdZdd�Zdd�Zdd�Zedd	d
��Ze	dd��Z
d
d�Z�fdd�Zd�fdd�	Z
e	�fdd��Ze	dd��Ze	dd��Ze	dd��Ze	dd��Z�ZS) raS
	Represent the process instance uniquely identifiable through PID

	For all class properties and methods, please see
	http://pythonhosted.org/psutil/#process-class

	Below listed are only reimplemented ones.

	For performance reasons, instances are cached based on PID, and
	multiple instantiations of a ``Process`` object with the same PID will
	return the same object. To clear the cache, invoke
	``Process.reset_cache()``. Additionally, as with ``ProcessWrapper``,
	process information is cached at object creation. To force a refresh,
	invoke the ``rebuild_cache()`` method on the object.
	cCs|j|jkS)zBFor our purposes, two processes are equal when they have same name)r)r�processr
r
r�__eq__�szProcess.__eq__cCs|j|�S)N)rE)rrDr
r
r�__ne__�szProcess.__ne__cCs
t|j�S)N)�hashr)rr
r
r�__hash__�szProcess.__hash__��?c
CsJtdd|gttd�}t||j�}z|j�|j�|jdkS|j�XdS)z�
		Process arguments could be referring to files on remote filesystems and
		os.path.isfile will hang forever if the shared FS is offline.
		Instead, use a subprocess that we can time out if we can't reach some file.
		Ztestz-f)�stdout�stderrrN)rrr�kill�startZcommunicate�
returncodeZcancel)Z	file_pathZtimeoutrDZtimerr
r
r�safe_isfile�s
zProcess.safe_isfilecCslg}x"|j�D]}|jtj|j��qWx:|j�dd�D]&}tjj|�sLq:tj	|�r:|j|�q:Wt
|�S)Nr)r5rr�strip�pathr!�os�isabsrrO�sorted)r�filesZmmap�argr
r
rrU�s
z
Process.filescCs|j�rt|j��SdS)zGThe parent process casted from ``psutil.Process`` to tracer ``Process``N)r"r)rr
r
rr+�szProcess.parentcs(ytt|�j�Stk
r"dSXdS)zcThe user who owns the process. If user was deleted in the meantime,
		``None`` is returned instead.N)r;rr#�KeyError)r)r>r
rr#�szProcess.usernameFcs"tt|�j|�}tdd�|D��S)zjThe collection of process's children. Each of them casted from ``psutil.Process``
		to tracer ``Process``.cSsg|]}t|j��qSr
)rr)�.0Zchildr
r
r�
<listcomp>�sz$Process.children.<locals>.<listcomp>)r;rr,r)rr-r,)r>r
rr,�szProcess.childrencsBtt|�j�}|jd�r$|dd�}d|kr>|d|jd��}|S)zcThe absolute path to process executable. Cleaned from arbitrary strings
		which appears on the end.z#newr��;���)r;rr �endswith�index)rr )r>r
rr �s
zProcess.execCs|j�dkS)N�python)r_)r)rr
r
r�is_interpretedszProcess.is_interpretedcCs8|j�}|dkrdS|j�}|dks0||j�kr4dSdS)NT)�terminalr+)rrar+r
r
r�
is_sessionszProcess.is_sessioncCs@|jr8x0|j�dd�D]}tjj|�rtjj|�SqW|j�S)Nr)r`r!rRrQ�isfile�basenamer)rrVr
r
r�	real_names
zProcess.real_namecCs�tjjtj��}tjj|j��}||}d}|jdkrFt|j�d}n`|jdkrhtt|jd	��d}n>|jdkr�tt|jd��d}n|jdkr�tt|j��d}|S)
z�
		The time of how long process is running. Returned as string
		in format ``XX unit`` where unit is one of
		``days`` | ``hours`` | ``minutes`` | ``seconds``
		�rz days�<z hoursz minutesz secondsii)�datetimeZ
fromtimestamp�timer$Zdays�strZseconds�int)rZnowZstartedZstarted_strr
r
r�str_started_agos



zProcess.str_started_ago)rI)F)rrrr6rErFrHrrO�propertyrUr+r#r,r r`rbrerlrCr
r
)r>rr�s
	rc@s&eZdZdZdZddd�Zdd�ZdS)�AffectedProcessNcCs tj||�t�|_t�|_dS)N)rr�set�packagesrU)rrr
r
rr9szAffectedProcess.__init__cCs$|jj|j�|_|jj|j�|_dS)N)rU�unionrp)rrDr
r
r�update>szAffectedProcess.update)N)rrrrprUrrrr
r
r
rrn5s
rn)�collectionsrrr
rhrirR�
subprocessrrZ	threadingrZsixr�objectr	r�typer7rrnr
r
r
r�<module>sV

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists