관리-도구
편집 파일: applications.cpython-39.pyc
a ����"e�#����������������������@���s����d�dl�mZ�d�dlmZ�d�dlmZ�d�dlmZmZ�d�dl m Z mZ�d�dlm Z �d�dlmZ�d�dlmZ�d�d lmZ�d�d lmZ�d�dlmZ�d�dlZd�dlZG�d d��de�ZG�dd��d�ZG�dd��de�ZdS�)�����)�absolute_import)�minidom)� ExpatError)�DATA_DIR�USER_CONFIG_DIRS)�PathNotFound�TracerError)�ApplicationsCollection)�_)� Processes)�System)�SystemdDbus)� lru_cacheNc�������������������@���s����e�Zd�Zedd��ege��Zddddddd �Zed �ZdZ e dd ���Ze dd���Ze dd���Z edd���Zedd���Ze i�fdd��Ze dd���ZdS�)�Applicationsc�����������������C���s���|�d�S�)Nz/applications.xml��)�xr���r����A/usr/lib/python3.9/site-packages/tracer/resources/applications.py�<lambda>%��������zApplications.<lambda>�daemonZstaticZsession�applicationZerasedZ undefined)�DAEMON�STATIC�SESSION�APPLICATIONZERASED�UNDEFr���Nc�����������������C���sZ���t�jst�����t�jD�]*}|j|�krd|vr.|n t��|j���S�qt|�t�jd�d�d�dd��S�)N�renamer���F)�name�type�helper�note�ignore)r����_apps�_load_definitionsr����findr����Application�TYPES)Zapp_name�appr���r���r���r$���2���s���� �zApplications.findc�������������������C���s���t�jst�����t�jS��N)r���r"���r#���r���r���r���r����allD���s����zApplications.allc������������������C���s`���t���t_tjD�]L}�zt�|���W�q�tyX�}�z tj�|��t vrD|�W�Y�d�}~qd�}~0�0�qd�S�r(���) r ���r���r"����DEFINITIONS�_loadr����os�path�dirnamer���)�file�exr���r���r���r#���K���s���� zApplications._load_definitionsc�������������� ���C���s"��z<t�|d��}t�|����}W�d�����n1�s00����Y��W�nP�tyV���td��Y�n8�ty��}�z d�||�}t|��W�Y�d�}~n d�}~0�0�|� d�D�]�}|�� |��|jD�]n}|jdkr�t |j����}t�|��|jdkr�|�� |��|jD�],} t | j����} t |j����}t�| |��q�q�q�d�S�)N�rr���zUnable to parse {0} Hint: {1}�applicationsr'����group)�openr���ZparseString�read�IOErrorr���r����formatr���ZgetElementsByTagName�_remove_unwanted_children� childNodesZnodeName�dictZ attributes�itemsr����_append_application)�clsr/����fZxmldocr0����msgr2����child�attrsr'���Z app_attrsZgroup_attrsr���r���r���r+���T���s(����0 zApplications._loadc�����������������C���s&���|j�D�]}|j|jkr|�|��qd�S�r(���)r9���ZnodeTypeZELEMENT_NODEZremoveChild)r=���Znoder@���r���r���r���r8���m���s���� z&Applications._remove_unwanted_childrenc�����������������C���s����t�|��}|�|��|tjv�r:tj�|�}tj|��|��nD|�dtj��|�dt�|���|�dd���|�dd��tj�|��d�S�)Nr���r���r ���r!���F) r%����updater���r"����index� setdefault�DEFAULT_TYPE�_helper�append)Z default_attrsZspecific_attrsr����ir���r���r���r<���s���s���� z Applications._append_applicationc�����������������C���sj���|�j�tjd�kr6t���dkr(d�|�j�S�d�|�j�S�n0|�j�tjd�krNtd�S�|�j�tjd�krftd�S�d�S�) Nr����systemdzsystemctl restart {0}zservice {0} restartr���z%You will have to reboot your computerr���z'You will have to log out & log in again)r���r���r&���r����init_systemr7���r���r ���)r'���r���r���r���rF�������s����zApplications._helper)�__name__� __module__�__qualname__�mapr���r���r*���r&���rE���r"����staticmethodr$���r)���r#����classmethodr+���r8���r<���rF���r���r���r���r���r���#���s0���� r���c�������������������@���s����e�Zd�ZdZeZdZdd��Zdd��Zdd��Z d d ��Z dd��Zd d��Zdd��Z dd��Zdd��Zdd��Zdd��Zedd���Zeedd�dd����Zedd���Zeedd�d d!����Zed"d#���Zed$d%���Zed&d'���Zed(d)���Zed*d+���ZdZdS�),r%���a��� Represent the application defined in ``applications.xml`` :param str name: The name of the application :param str type: See ``Applications.TYPES`` for possible values :param str helper: Describes how to restart the applications :param bool note: Provides additional informations to the ``helper`` :param bool ignore: If ``True``, the application won't be printed :param Processes processes_factory: Class providing list of running processes Nc�����������������C���s���||�_�d�|�_d�S�r(���)�_attributes�_cached_name)�selfZattributes_dictr���r���r����__init__����s����zApplication.__init__c�����������������C���s���t�|t�o|�j|jkS�r(���)� isinstancer%���r����rS����otherr���r���r����__eq__����s����zApplication.__eq__c�����������������C���s���|���|��S�r(���)rX���rV���r���r���r����__ne__����s����zApplication.__ne__c�����������������C���s ���t�|�j�S�r(���)�hashr����rS���r���r���r����__hash__����s����zApplication.__hash__c�����������������C���s ���|�j�|�S�r(����rQ����rS����itemr���r���r����__getattr__����s����zApplication.__getattr__c�����������������C���s ���t�|�j�S�r(���)�lenrQ���r[���r���r���r����__len__����s����zApplication.__len__c�����������������C���s ���||�j�v�S�r(���r]���r^���r���r���r����__contains__����s����zApplication.__contains__c�����������������C���s���d|�j�j�d�|�jd��d�S�)N�<z: r����>)� __class__rK���rQ���r[���r���r���r����__str__����s����zApplication.__str__c�����������������C���s���|�����S�r(���)rg���r[���r���r���r����__repr__����s����zApplication.__repr__c�����������������C���s���|�j��||��d�S�r(���)rQ���rD���)rS����key�valuer���r���r���rD�������s����zApplication.setdefaultc�����������������C���s ���t�|t�r|j}|�j�|��d�S�r(���)rU���r%���rQ���rB���)rS����valuesr���r���r���rB�������s���� zApplication.updatec�����������������C���s���|�j�o|�j�d�jS�)Nr���)� instances�is_interpretedr[���r���r���r���rm�������s����zApplication.is_interpreted)�maxsizec�����������������C���s.���|�j��d�r|�j��d�rdS�|�jo,|�jd�jS�)Nzssh-z-sessionTr���)r���� startswith�endswithrl���� is_sessionr[���r���r���r���rq�������s����zApplication.is_sessionc�����������������C���sD���|�j�d�tjd�kr|�j�d�S�|�jr.tjd�S�|�jr>tjd�S�tjS�)Nr���r���r���r���)rQ���r���r&���rq���� is_servicerE���r[���r���r���r���r�������s���� zApplication.typec�����������������C���s$���t����dkr t���d�|�j��S�d�S�)NrI���z{0}.service)r���rJ���r ���Zunit_path_from_idr7���r���r[���r���r���r���rr�������s����zApplication.is_servicec�����������������C���sJ���|�j�d�pt�|��}t���dkrF|�jtjd�krF|rF|�d�sFd|�}|S�)Nr����rootr���zsudo )rQ���r���rF���r����userr���r&���ro���)rS���r���r���r���r���r�������s ����zApplication.helperc�����������������C���s���|�j�s d�S�tt�d|�j���S�)Nz\{.*\}�r����bool�re�searchr[���r���r���r����helper_contains_formating����s����z%Application.helper_contains_formatingc�����������������C���s���|�j�s d�S�tt�d|�j���S�)Nz\{NAME\}ru���r[���r���r���r����helper_contains_name����s����z Application.helper_contains_namec�������������� ���C���sP���g�}|�j�rL|�js|�|�j���n.|�jD�]&}|�|�j�j|�j|j|j|jd���q$|S�)ab�� Return the list of helpers which describes how to restart the application. When no ``helper_format`` was described, empty list will be returned. If ``helper_format`` contains process specific arguments such a ``{PID}``, etc. list will contain helper for every application instance. In other cases, there will be just one helper in the list. )�NAMEZPNAMEZPIDZEXE)r���ry���rG����affected_instancesr7���r����pidZexe)rS����helpers�processr���r���r���r~�������s���� � zApplication.helpersc��������������������s�����j�������fdd��S�)zo Return collection of processes with same name as application. I.e. running instances of the application c��������������������s�����j�d�|����|�jfv�S�)Nr���)rQ���r���� real_name)r���r[���r���r���r�����r���z'Application.instances.<locals>.<lambda>)�processes_factoryr)���Zfilteredr[���r���r[���r���rl�����s���� �zApplication.instances)rK���rL���rM����__doc__r���r����rQ���rT���rX���rY���r\���r`���rb���rc���rg���rh���rD���rB����propertyrm���r���rq���r���rr���r���ry���rz���r~���rl���r|���r���r���r���r���r%�������sF��� r%���c�������������������@���s ���e�Zd�Zedd���Zdd��ZdS�)�AffectedApplicationc�����������������C���s���|�j�s|����|�_�|�j�S�r(���)rR����_namer[���r���r���r���r��� ��s���� zAffectedApplication.namec�����������������C���s����t����dkr�t��}z|�jd�j}W�n�ty8���d�}Y�n0�|r�|�jr�|�|�r�|�|d�s�|�|d�}|r�t � d|�r�t �dd|�S�|�jr�|�jd�j S�|�jd�S�)NrI���r���ZPAMName�Idz \.service$��r���)r���rJ���r ���rl���r}���� IndexErrorZunit_path_from_pidZhas_service_property_from_pidZget_unit_property_from_pidrw���rx����subrm���r����rQ���)rS���Zbusr}���r����r���r���r���r����(��s���� zAffectedApplication._nameN)rK���rL���rM���r����r���r����r���r���r���r���r������s��� r����)Z __future__r���Zxml.domr���Zxml.parsers.expatr���Ztracer.pathsr���r���Ztracer.resources.exceptionsr���r���Ztracer.resources.collectionsr ���Ztracer.resources.langr ���Ztracer.resources.processesr���Ztracer.resources.systemr���Ztracer.resources.SystemdDbusr ���Ztracer.resources.pycompr���r,���rw����objectr���r%���r����r���r���r���r����<module>���s ���p�