a "e#@sddlmZddlmZddlmZddlmZmZddl m Z m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lZdd lZGd ddeZGdddZGdddeZd S))absolute_import)minidom) ExpatError)DATA_DIRUSER_CONFIG_DIRS) PathNotFound TracerError)ApplicationsCollection)_) Processes)System) SystemdDbus) lru_cacheNc@seZdZeddegeZddddddd Zed Zd Z e d d Z e ddZ e ddZ eddZeddZe ifddZe ddZd S) ApplicationscCs|dS)Nz/applications.xml)xrrA/usr/lib/python3.9/site-packages/tracer/resources/applications.py%zApplications.daemonZstaticZsession applicationZerasedZ undefined)DAEMONSTATICSESSION APPLICATIONZERASEDUNDEFrNcCsZtjsttjD]*}|j|krd|vr.|n t|jSqt|tjdddddS)NrenamerF)nametypehelpernoteignore)r_apps_load_definitionsrfindr ApplicationTYPES)Zapp_nameapprrrr$2s  zApplications.findcCstjsttjSN)rr"r#rrrrallDszApplications.allc Cs`tt_tjD]L}zt|WqtyX}z tj|t vrD|WYd}~qd}~00qdSr() r rr" DEFINITIONS_loadrospathdirnamer)fileexrrrr#Ks  zApplications._load_definitionsc Cs"z) __class__rKrQr[rrr__str__szApplication.__str__cCs|Sr()rgr[rrr__repr__szApplication.__repr__cCs|j||dSr()rQrD)rSkeyvaluerrrrDszApplication.setdefaultcCs t|tr|j}|j|dSr()rUr%rQrB)rSvaluesrrrrBs zApplication.updatecCs|jo|jdjS)Nr) instancesis_interpretedr[rrrrmszApplication.is_interpreted)maxsizecCs.|jdr|jdrdS|jo,|jdjS)Nzssh-z-sessionTr)r startswithendswithrl is_sessionr[rrrrqszApplication.is_sessioncCsD|jdtjdkr|jdS|jr.tjdS|jr>tjdStjS)Nrrrr)rQrr&rq is_servicerEr[rrrrs   zApplication.typecCs$tdkr td|jSdS)NrIz {0}.service)r rJr Zunit_path_from_idr7rr[rrrrrs zApplication.is_servicecCsJ|jdpt|}tdkrF|jtjdkrF|rF|dsFd|}|S)Nrrootrzsudo )rQrrFr userrr&ro)rSrrrrrs zApplication.helpercCs|js dSttd|jS)Nz\{.*\}rboolresearchr[rrrhelper_contains_formatingsz%Application.helper_contains_formatingcCs|js dSttd|jS)Nz\{NAME\}rur[rrrhelper_contains_namesz Application.helper_contains_namec CsPg}|jrL|js||jn.|jD]&}||jj|j|j|j|jdq$|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)rryrGaffected_instancesr7rpidZexe)rShelpersprocessrrrr~s    zApplication.helperscsjfddS)zo Return collection of processes with same name as application. I.e. running instances of the application csjd||jfvS)Nr)rQr real_name)rr[rrrrz'Application.instances..)processes_factoryr)Zfilteredr[rr[rrls  zApplication.instances)rKrLrM__doc__r rrQrTrXrYr\r`rbrcrgrhrDrBpropertyrmrrqrrrrryrzr~rlr|rrrrr%sF          r%c@s eZdZeddZddZdS)AffectedApplicationcCs|js||_|jSr()rR_namer[rrrr s zAffectedApplication.namecCstdkrt}z|jdj}Wnty8d}Yn0|r|jr||r||ds||d}|rt d|rt dd|S|j r|jdj S|jdS)NrIrZPAMNameIdz \.service$r)r rJr rlr} IndexErrorZunit_path_from_pidZhas_service_property_from_pidZget_unit_property_from_pidrwrxsubrmrrQ)rSZbusr}rrrrr(s      zAffectedApplication._nameN)rKrLrMrrrrrrrrs r)Z __future__rZxml.domrZxml.parsers.expatrZ tracer.pathsrrZtracer.resources.exceptionsrrZtracer.resources.collectionsr Ztracer.resources.langr Ztracer.resources.processesr Ztracer.resources.systemr Ztracer.resources.SystemdDbusr Ztracer.resources.pycomprr,rwobjectrr%rrrrrs         p