3 ©ft`tã@sêddlmZddlmZddlmZddlmZmZddlm Z ddlZ ddl Z ddl Z ddl Z ddlZ ddlZddlZddlZddlZejdƒZdd d gd gd gd gdd d gd œZd d„Zdd„Zdd„Zdd„ZGdd„dejƒZdS)é)Úabsolute_import)Úunicode_literals)Úcommands)Ú_ÚP_)ÚmiscNÚdnfÚmetadataÚdbcachez expire-cacheÚpackages)r r r z expire-cacheÚallccsVxPtj|ƒD]B\}}}tjj||ƒ}x(|D] }tjj||ƒ}tjj|ƒVq*Wq WdS)z:Traverse dirpath recursively and yield relative filenames.N)ÚosÚwalkÚpathÚrelpathÚjoinÚnormpath)ÚdirpathÚrootÚdirsÚfilesÚbaseÚfr©rú/usr/lib/python3.6/clean.pyÚ_tree1s  rcs‡fdd„|DƒS)z5Yield those filenames that match any of the patterns.c3s(|] }ˆD]}tj||ƒr |Vq qdS)N)ÚreÚmatch)Ú.0rÚp)Úpatternsrrú <sz_filter..r)rr r)r rÚ_filter:sr"cCsLd}xB|D]:}tjj||ƒ}tjtjjtdƒ|ƒt j |ƒ|d7}q W|S)z(Remove the given filenames from dirpath.rzRemoving file %sé) r rrÚloggerÚlogrÚloggingZDDEBUGrrZunlink_f)rrÚcountrrrrrÚ_clean?s   r(cs0tjjd‰‡fdd„|Dƒ}tdd„|DƒƒS)z:Return the repo IDs that have some cached metadata around.r c3s|]}tjˆ|ƒVqdS)N)rr)rr)Úmetapatrrr!Msz _cached_repos..css|]}|r|jdƒVqdS)ZrepoidN)Úgroup)rÚmrrrr!Ns)rÚrepoÚ CACHE_FILESÚset)rZmatchesr)r)rÚ _cached_reposJs r/c@s0eZdZdZd ZedƒZedd„ƒZdd„Z dS) Ú CleanCommandzSA class containing methods needed by the cli to execute the clean command. Úcleanzremove cached datacCs|jddtjƒtdƒd�dS)NÚtypeú+zMetadata type to clean)ÚnargsÚchoicesÚhelp)Ú add_argumentÚ _CACHE_TYPESÚkeysr)ÚparserrrrÚ set_argparserYszCleanCommand.set_argparserc Csf|jjj}tjj|dƒ}tjj|dƒ}tjj|jjjdƒ}�x$yÂ|oJ|oJ|�¬t dd„|j j Dƒƒ}t t |ƒƒ}tjtddj|ƒƒƒd|krÀt|ƒ}|jjjj|ƒ|jdƒtjtdƒƒdd „|Dƒ}t|t||ƒƒ} tjtd d | ƒ| ƒdSQRXWq>tjjk �r\} z:|jjj�sHtd ƒ| j} tj| ƒtj d ƒn| ‚WYdd} ~ Xq>Xq>WdS)NTcss |]}t|D] }|VqqdS)N)r8)rÚcÚtrrrr!gsz#CleanCommand.run..zCleaning data: ú z expire-cachezCache was expiredcSsg|]}tjj|‘qSr)rr,r-)rr=rrrú qsz$CleanCommand.run..z%d file removedz%d files removedz*Waiting for process with pid %d to finish.é)!rZconfÚcachedirrÚlockZbuild_metadata_lockZbuild_download_lockZbuild_rpmdb_lockZ persistdirr.Zoptsr2Úlistrr$Údebugrrr/Z_repo_persistorZexpired_to_addÚupdateÚremoveÚinfor(r"rÚ exceptionsZ LockErrorZ exit_on_lockÚpidÚtimeZsleep) ÚselfrAZmd_lockZ download_lockZ rpmdb_lockÚtypesrZexpiredr r'ÚeÚmsgrrrÚrun_s2      zCleanCommand.runN)r1) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚaliasesrZsummaryÚ staticmethodr;rOrrrrr0Qs  r0)Z __future__rrZdnf.clirZdnf.i18nrrZdnf.yumrrZdnf.exceptionsZdnf.lockZ dnf.loggingZdnf.repor&r rrJZ getLoggerr$r8rr"r(r/ZCommandr0rrrrÚs0