%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/tracer/resources/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/tracer/resources/__pycache__/processes.cpython-39.opt-1.pyc

a

"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*z
t��WSty$t��YS0dS�N)�psutil�pids�AttributeErrorZget_pid_list�rr�>/usr/lib/python3.9/site-packages/tracer/resources/processes.pyr!s
zProcesses.pidsc	CsRt�}t��D]>}z|�t|��Wqtjy8YqtjyJYq0q|Sr
)rr	r�append�ProcessrZ
NoSuchProcess�AccessDenied)Z	processes�pidrrr�all(sz
Processes.allN)�__name__�
__module__�__qualname__�staticmethodrrrrrrr	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.
	NcCst�|�|_|��dSr
)rr�_process�
rebuild_cache��selfrrrr�__init__AszProcessWrapper.__init__cCs
t|j�Sr
)�boolr�rrrr�__nonzero__EszProcessWrapper.__nonzero__cCs|jjgd�d�|_dS)N)�name�exe�cmdline�ppid�username�create_time)�attrs)rZas_dict�	_procdictr rrrrHszProcessWrapper.rebuild_cachecCs|z\|�d�dkrZ|�d�|�d�vrZt|�d��dkrZ|�d�d�d�d}d�|�WSWntjypYn0|�d�S)	Nr"Zsshdr#r$r�@rzssh-{0}-session)�_attr�len�split�formatrr)rr&rrrr"Ks&zProcessWrapper.namecCs
|�d�S)Nr#�r+r rrrr#WszProcessWrapper.execCs
|�d�S)Nr$r/r rrrr$ZszProcessWrapper.cmdlinecCs
|�d�S)Nr%r/r rrrr%]szProcessWrapper.ppidcCs
|�d�S)N�parentr/r rrrr0`szProcessWrapper.parentcCs
|�d�S)Nr&r/r rrrr&cszProcessWrapper.usernamecCs
|�d�S)Nr'r/r rrrr'fszProcessWrapper.create_timeFcCsZd�|�}||jvrPz|j�|�|j|<Wn$tyN|j�|�|j|<Yn0|j|S)Nzchildren-{0})r.r)r�childrenr
Zget_children)r�	recursive�keyrrrr1is

zProcessWrapper.childrencCsN||jvrDt|j|�}z|�|j|<WntyB||j|<Yn0|j|Sr
)r)�getattrr�	TypeError)rr"�attrrrrr+rs
zProcessWrapper._attrcCst|j|�Sr
)r4r)r�itemrrr�__getattr__{szProcessWrapper.__getattr__TcCs^d�|�}||jvrTz|jj|d�|j|<Wn&tyR|jj|d�|j|<Yn0|j|S)Nzmemory_maps-{0})�grouped)r.r)r�memory_mapsr
Zget_memory_maps)rr9r3rrrr:s

zProcessWrapper.memory_maps)N)F)T)rrr�__doc__rr!rr"r#r$r%r0r&r'r1r+r8r:rrrrr3s

		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���|||��fdd�}|�t�d|�dS)Ncs
i�_dSr
)�_cacher��clsrr�reset_cache�sz)ProcessMeta.__init__.<locals>.reset_cacher@)�superr<r�setattr)r?r"�basesZ
attributesr@��	__class__r>rr�szProcessMeta.__init__cOsV|d}||jvrL|j|g|�Ri|��}|j|g|�Ri|��||j|<|j|S)Nr)r=�__new__r)r?�args�kwargsrrrrr�__call__�s

zProcessMeta.__call__)rrrr;rrI�
__classcell__rrrDrr<�sr<cs�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�processrrr�__eq__�szProcess.__eq__cCs|�|�Sr
)rMrKrrr�__ne__�szProcess.__ne__cCs
t|j�Sr
)�hashrr rrr�__hash__�szProcess.__hash__��?cCsTtdd|gttd�}t||j�}z$|��|��|jdkW|��S|��0dS)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.
		�testz-f)�stdout�stderrrN)rrr�kill�startZcommunicate�
returncode�cancel)Z	file_path�timeoutrLZtimerrrr�safe_isfile�s
�zProcess.safe_isfilecCsdg}|��D]}|�t�|j��q|��dd�D]&}tj�|�sFq4t�	|�r4|�|�q4t
|�S�Nr)r:rr�strip�pathr$�os�isabsrrZ�sorted)r�filesZmmap�argrrrra�s
z
Process.filescCs|��rt|���SdS)zGThe parent process casted from ``psutil.Process`` to tracer ``Process``N)r%rr rrrr0�szProcess.parentcs*ztt|���WSty$YdS0dS)zcThe user who owns the process. If user was deleted in the meantime,
		``None`` is returned instead.N)rArr&�KeyErrorr rDrrr&�szProcess.usernameFcs"tt|��|�}tdd�|D��S)zjThe collection of process's children. Each of them casted from ``psutil.Process``
		to tracer ``Process``.cSsg|]}t|j��qSr)rr)�.0�childrrr�
<listcomp>��z$Process.children.<locals>.<listcomp>)rArr1r)rr2r1rDrrr1�szProcess.childrencsBtt|���}|�d�r$|dd�}d|vr>|d|�d��}|S)zcThe absolute path to process executable. Cleaned from arbitrary strings
		which appears on the end.z#newr����;)rArr#�endswith�index)rr#rDrrr#�s
zProcess.execCs|��dvS)N)Zpython)r"r rrr�is_interpretedszProcess.is_interpretedcCs8|��}|durdS|��}|dus0||��kr4dSdS)NT)�terminalr0)rrmr0rrr�
is_sessionszProcess.is_sessioncCs@|jr8|��dd�D] }tj�|�rtj�|�Sq|��Sr[)rlr$r^r]�isfile�basenamer")rrbrrr�	real_names
zProcess.real_namecCs�tj�t���}tj�|���}||}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 daysiz hours�<z minutesz seconds)�datetimeZ
fromtimestamp�timer'Zdays�strZseconds�int)rZnow�startedZstarted_strrrr�str_started_agos



zProcess.str_started_ago)rQ)F)rrrr;rMrNrPrrZ�propertyrar0r&r1r#rlrnrqryrJrrrDrr�s*




rc@s&eZdZdZdZddd�Zdd�ZdS)�AffectedProcessNcCs t�||�t�|_t�|_dSr
)rr�set�packagesrarrrrr9szAffectedProcess.__init__cCs$|j�|j�|_|j�|j�|_dSr
)ra�unionr}rKrrr�update>szAffectedProcess.update)N)rrrr}rarrrrrrr{5s
r{)�collectionsrrrrtrur^�
subprocessrr�	threadingrZsixr�objectr	r�typer<rr{rrrr�<module>sV

Zerion Mini Shell 1.0