3 ft`t@sddlmZddlmZddlmZddlmZmZddlm Z ddlZ ddl Z ddl Z ddl Z ddlZ ddlZddlZddlZddlZejdZdd d gd gd gd gdd d gd Zd dZddZddZddZGdddejZdS))absolute_import)unicode_literals)commands)_P_)miscNdnfmetadatadbcachez expire-cachepackages)r r r z expire-cacheallccsVxPtj|D]B\}}}tjj||}x(|D] }tjj||}tjj|Vq*Wq WdS)z:Traverse dirpath recursively and yield relative filenames.N)oswalkpathrelpathjoinnormpath)dirpathrootdirsfilesbasefrr/usr/lib/python3.6/clean.py_tree1s  rcsfdd|DS)z5Yield those filenames that match any of the patterns.c3s(|] }D]}tj||r |Vq qdS)N)rematch).0rp)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 rrloggerlogrloggingZDDEBUGrrZunlink_f)rrcountrrrrr_clean?s   r(cs0tjjdfdd|D}tdd|DS)z:Return the repo IDs that have some cached metadata around.r c3s|]}tj|VqdS)N)rr)rr)metapatrrr!Msz _cached_repos..css|]}|r|jdVqdS)ZrepoidN)group)rmrrrr!Ns)rrepo CACHE_FILESset)rZmatchesr)r)r _cached_reposJs r/c@s0eZdZdZd ZedZeddZddZ dS) CleanCommandzSA class containing methods needed by the cli to execute the clean command. cleanzremove cached datacCs|jddtjtdddS)Ntype+zMetadata type to clean)nargschoiceshelp) add_argument _CACHE_TYPESkeysr)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|krt|}|jjjj||jdtjtddd |D}t|t||} tjtd d | | dSQRXWq>tjjk r\} z:|jjjsHtd | j} tj| tj d n| WYdd} ~ Xq>Xq>WdS)NTcss |]}t|D] }|VqqdS)N)r8)rctrrrr!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.)!rZconfcachedirrlockZbuild_metadata_lockZbuild_download_lockZbuild_rpmdb_lockZ persistdirr.Zoptsr2listrr$debugrrr/Z_repo_persistorZexpired_to_addupdateremoveinfor(r"r exceptionsZ LockErrorZ exit_on_lockpidtimeZsleep) selfrAZmd_lockZ download_lockZ rpmdb_locktypesrZexpiredr r'emsgrrrrun_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/ZCommandr0rrrrs0