a !cn@sddlmZddlmZddlmZddlmZmZddlm Z ddlZ ddl Z ddl Z ddl Z ddlZ ddlZddlZddlZddlZedZgdd gd gd ggd d ZddZddZddZddZGdddejZdS))absolute_import)unicode_literals)commands)_P_)miscNdnf)metadatadbcache expire-cachepackagesr r )r r r )r r r r allccsNt|D]>\}}}tj||}|D] }tj||}tj|Vq&q dS)z:Traverse dirpath recursively and yield relative filenames.N)oswalkpathrelpathjoinnormpath)dirpathrootdirsfilesbasefrr:/usr/lib/python3.9/site-packages/dnf/cli/commands/clean.py_tree1s rcsfdd|DS)z5Yield those filenames that match any of the patterns.c3s(|] }D]}t||r |Vq qdSNrematch).0rppatternsrr <z_filter..r)rr$rr#r_filter:sr'cCsHd}|D]:}tj||}ttjjtd|t ||d7}q|S)z(Remove the given filenames from dirpath.rzRemoving file %s) rrrloggerlogrloggingZDDEBUGrrZunlink_f)rrcountrrrrr_clean?s  r-cs0tjjdfdd|D}tdd|DS)z:Return the repo IDs that have some cached metadata around.r c3s|]}t|VqdSrr)r!rZmetapatrrr%Mr&z _cached_repos..css|]}|r|dVqdS)ZrepoidN)group)r!mrrrr%Nr&)rrepo CACHE_FILESset)rmatchesrr.r _cached_reposJs r5c@s0eZdZdZdZedZeddZddZ dS) CleanCommandzSA class containing methods needed by the cli to execute the clean command. )Zcleanzremove cached datacCs|jddttdddS)Ntype+zMetadata type to clean)nargschoiceshelp) add_argument _CACHE_TYPESkeysr)parserrrr set_argparserYszCleanCommand.set_argparserc Cs|jjj}tj|d}tj|d}tj|jjjd}z<| ||t dd|j j D}t t |}ttdd|d|vrt|}|jjj||dttddd |D}t|t||} ttd d | | WdWdWdWdS1s,0YWdn1sL0YWdn1sl0YWq:tjjy} z@|jjjstd | j} t| t d n| WYd} ~ q:d} ~ 00q:dS)NTcss |]}t|D] }|VqqdSr)r=)r!ctrrrr%gr&z#CleanCommand.run..zCleaning data:  r zCache was expiredcSsg|]}tjj|qSr)rr1r2)r!rBrrr qr&z$CleanCommand.run..z%d file removedz%d files removedz*Waiting for process with pid %d to finish.)!rZconfcachedirrlockZbuild_metadata_lockZbuild_download_lockZbuild_rpmdb_lockZ persistdirr3Zoptsr7listrr)debugrrr5Z_repo_persistorZexpired_to_addupdateremoveinfor-r'r exceptionsZ LockErrorZ exit_on_lockpidtimesleep) selfrFZmd_lockZ download_lockZ rpmdb_locktypesrZexpiredr$r,emsgrrrrun_s0      zCleanCommand.runN) __name__ __module__ __qualname____doc__aliasesrZsummary staticmethodr@rUrrrrr6Qs  r6)Z __future__rrZdnf.clirZdnf.i18nrrZdnf.yumrrZdnf.exceptionsZdnf.lockZ dnf.loggingZdnf.repor+rrrOZ getLoggerr)r=rr'r-r5ZCommandr6rrrrs2