a "e½ã@s ddlmZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZmZdd lmZdd lmZmZdd lmZGd d „d eƒZdS)é)Úabsolute_importN)Ú NoSuchProcess)ÚPackage)ÚSystem)ÚFilenameCleaner)ÚAffectedProcess)ÚApplicationsCollectionÚAffectedProcessesCollectionÚPackagesCollection)ÚUnsupportedDistribution)Ú ApplicationsÚAffectedApplication)Ú_c@sˆeZdZdZdZdZdZdZdZdZ dZ dZ dZ ddd„Z dd„Zddd „Zd d „Zd d „Zdd„Zefdd„Zefdd„Zdd„ZdS)ÚTracerz9Tracer finds outdated running applications in your systemNFcCs8|stt ¡ƒ‚||_||_||_||_||_||_dS©N) r rZ distributionÚ_PACKAGE_MANAGERÚ_rulesÚ _applicationsÚ_memoryÚ_hooks_observerÚ_erased)ÚselfZpackage_managerZrulesZ applicationsÚmemoryZhooks_observerZerased©rú;/usr/lib/python3.9/site-packages/tracer/resources/tracer.pyÚ__init__Bs zTracer.__init__cCsF|jr|jrt|jƒS|jr"|jnt ¡}|j |¡}| |j¡}|S)z6Returns list of packages what tracer should care about) Úspecified_packagesÚnowr Ú timestamprZ boot_timerZpackages_newer_thanÚ intersection)rrÚpackagesrrrÚ_modified_packagesMs     zTracer._modified_packagesc Csp| |¡}| ¡}i}g}| ¡D]}|j |j¡D]ò}t |¡}||vrNq6||D]Ð}|j|vrfqVzª|  ¡|j kr|  |j¡|  |¡}|j  | ¡¡} | js| j|vrü|jrÎ|j | ¡sÎtjd| _t| jƒ|| j<tƒ|| j_| || j¡|| jj  |¡WqVty$YqV0qVq6q"|j  d¡jsd| ¡rdtdtjdtdƒdœƒ|d<t| ¡ƒS)z‡ Returns collection of applications which uses some files that have been modified @TODO This function should be hardly optimized ZERASEDZkernelZSTATICz%You will have to reboot your computer)ÚnameÚtypeÚhelper)rr!Z unique_newestrÚ package_filesr"rÚstripÚpidÚ create_timeÚmodifiedÚappendÚ _apply_rulesrÚfindÚignorerZ provided_byr ZTYPESr#r Ú _attributesr Zaffected_instancesÚ _call_hookrÚ_has_updated_kernelrrÚvalues) rÚuserrr ÚaffectedÚfoundÚpackageÚfileÚpÚarrrÚtrace_affectedWs@          ÿ zTracer.trace_affectedcCsBt ¡}|durdSt ¡}t|ƒ}| |j¡|j ||¡dkS)NFéÿÿÿÿ)rZrunning_kernel_packageÚkernel_package_namerZ load_inforZcompare_packages)rZrunningr;Zlatestrrrr0…s zTracer._has_updated_kernelcCsx| ¡}|s|S|j | ¡¡}|j | ¡¡}|rJ|j|jjdkrJ|S|rT|jsX|S|j|jjdkrt| |¡S|S)NZRETURNz CALL-PARENT)Úparentrr,r"ÚactionZACTIONSr+)rÚprocessr<Zc_ruleZp_rulerrrr+’s  zTracer._apply_rulescCs|jr| |j¡dSr)rr")rÚapprrrr/§szTracer._call_hookcCsF| ¡}tƒ}|jD],}| | |||¡¡| | |||¡¡q|S)z£ Returns collection of processes where each of them contains packages which affected it. Packages contains only files matching with the particular process )r!r Z instancesÚupdateÚ_affecting_processesÚ_affecting_children)rr?Úaffected_process_factoryr Ú processesr>rrrÚtrace_application«s  zTracer.trace_applicationc Cs tƒ}|j}|D]Š}tƒ}|j |j¡D]0}t |¡}||vr@q(| ¡|j kr(|  |¡q(|r|} || _||j ƒ} | j   |j ¡| j  | g¡|  | g¡q|Sr)r ÚfilesÚsetrr%r"rr&r(r)Úaddr'Ú__dict__r@r ) rr>r rCZ collectionZ process_filesr5Zmatching_filesZ package_fileZaff_pkgr3rrrrA¸s$   zTracer._affecting_processescCsT|j | ¡¡siStƒ}| ¡D],}| | |||¡¡| | |||¡¡q"|Sr)rr,r"r Zchildrenr@rArB)rr>r rCrDÚchildrrrrBÏs zTracer._affecting_children)NNF)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrrrrr!r9r0r+r/rrErArBrrrrr!s&  .  r)Z __future__rÚosZpsutilrZtracer.resources.packagerZtracer.resources.systemrZ tracer.resources.FilenameCleanerrZtracer.resources.processesrZtracer.resources.collectionsrr r Ztracer.resources.exceptionsr Ztracer.resources.applicationsr r Ztracer.resources.langrÚobjectrrrrrÚs