a 2hV%@sddlmZddlmZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZedZdZGdd d eZGd d d eZd d ZddZddZddZddZdS))absolute_import)print_function)unicode_literalsN)_dnfzdnf.plugin.dynamicc@s\eZdZdZdZdZeddZddZdd Z d d Z d d Z ddZ ddZ ddZdS)Pluginz5The base class custom plugins must derive from. #:apiz Nc stj}|jr|jn|jfdd|jD}|D]\}tj|r4z| |Wq4t y}z$t j tdt|WYd}~q4d}~00q4|S)Ncsg|]}d|fqS)z %s/%s.conf).0pathnamer./usr/lib/python3.9/site-packages/dnf/plugin.py 9z&Plugin.read_config..zParsing file failed: %s)libdnfconfZ ConfigParser config_namer Zpluginconfpathosr isfileread Exceptionr exceptionsZ ConfigErrorrstr)clsrparserfilesfileerr r read_config4s  0zPlugin.read_configcCs||_||_dSN)basecliselfr r!rrr __init__BszPlugin.__init__cCsdSrrr#rrr pre_configGszPlugin.pre_configcCsdSrrr%rrr configKsz Plugin.configcCsdSrrr%rrr resolvedOszPlugin.resolvedcCsdSrrr%rrr sackSsz Plugin.sackcCsdSrrr%rrr pre_transactionWszPlugin.pre_transactioncCsdSrrr%rrr transaction[szPlugin.transaction)__name__ __module__ __qualname____doc__r r classmethodrr$r&r'r(r)r*r+rrrr r.s rc@s~eZdZddZddZddZddZd d Zd d Zd dZ dddZ ddZ ddZ ddZ ddZddZddZdS)PluginscCsg|_g|_dSr) plugin_clspluginsr%rrr r$aszPlugins.__init__cCs |dSr)_unloadr%rrr __del__eszPlugins.__del__c Csv|jD]j}zt||Wqtjjy2Yqtynt\}}}t |||}t d |Yq0qdS)N) r3getattrrrErrorrsysexc_info tracebackformat_exceptionloggerZcriticaljoin)r#methodpluginexc_type exc_value exc_tracebackZ except_listrrr _callerhs  zPlugins._callercst|jddD]`}|jtfdd|Dr0q||}|do\|ddo\|dd }|r|j|qdS)zwChecks whether plugins are enabled or disabled in configuration files and removes disabled plugins from listNc3s|]}t|VqdSrfnmatch)r patternr rr xrz)Plugins._check_enabled..mainZenabled)r2r anyrZ has_sectionZ has_optionZ getbooleanremove)r#renable_pluginsZplug_clsrZdisabledrr r _check_enabledss    zPlugins._check_enabledcCsttjvrtdtjttjt<}g|_t|j ||}t ||t dd|_ | ||t|j dkrtdd|j D}ttdd|dS)z)Dynamically load relevant plugin modules.zload_plugins() called twiceNrcss|] }|jVqdSrr )r r@rrr rHrz Plugins._load..zLoaded plugins: %s, )DYNAMIC_PACKAGEr9modules RuntimeErrorrZpycomp ModuleType__path___get_plugins_filesZ pluginpath_import_modules_plugin_classesr2rMlensortedr=debugrr>)r#rZskipsrLpackagernamesrrr _loads   z Plugins._loadcCs|ddS)Nr&rDr%rrr _run_pre_configszPlugins._run_pre_configcCs|ddS)Nr'r]r%rrr _run_configszPlugins._run_configNcCs&|jD]}|||}|j|qdSr)r2r3append)r#r r!Zp_clsr@rrr _run_inits  zPlugins._run_initcCs|ddS)Nr)r]r%rrr run_sackszPlugins.run_sackcCs|ddS)Nr(r]r%rrr run_resolvedszPlugins.run_resolvedcCs|ddS)Nr*r]r%rrr run_pre_transactionszPlugins.run_pre_transactioncCs|ddS)Nr+r]r%rrr run_transactionszPlugins.run_transactioncCs&ttjvr"ttjjdtjt=dS)NzPlugins were unloaded.)rOr9rPr=logrloggingZDDEBUGr%rrr r4s zPlugins._unloadcCs|js dSt}|jD]}||t|j<qt|}t}|jD]}|| |j qD|sddS|j D]}| |j qj|D]}|j ||qdS)zH Unload plugins that were removed in the `transaction`. N)Z remove_setdictr3inspectZgetfile __class__setkeysupdate intersectionrZ install_setdifference_updaterK)r#r+r3r@Z plugin_filesZerased_plugin_filespkgZ plugin_filerrr unload_removed_pluginss    zPlugins.unload_removed_plugins)N)r,r-r.r$r5rDrMr\r^r_rarbrcrdrer4rqrrrr r1`s  r1cCstSr)r__subclasses__rrrr rVsrVc Cs|D]}tj|\}}|j|tj|\}}d|j|f}zt|}Wqt y}z2t t d||t j tjjdddWYd}~qd}~00qdS)Nz%s.%szFailed loading plugin "%s": %sr6T)r:)rr splitrSr`splitextr, importlib import_modulerr=errorrrfrrgZSUBDEBUG)rZZpy_filesfnr moduleextr rrrr rUs rUcCs6g}t|}t|}t}t}|D]}td|D]}tjtj|\}} d} d} |D]B} t|| r^|| d} |D]} t|| r~d} || q~d} q^| s|D]} t|| r|| q| r6||q6q$| |}|rt t d dt|| |}|r2t t d dt||S)Nz%s/*.pyTFz=No matches found for the following enable plugin patterns: {}rNz>No matches found for the following disable plugin patterns: {})rkglobrr rtbasename_plugin_name_matches_patternaddr` differencer=Zwarningrformatr>rX)pathsZdisable_pluginsrLr3Zpattern_enable_foundZpattern_disable_foundprx plugin_nameZdummyZmatchedZenable_pattern_testedZ pattern_skipZpattern_enableZenable_not_foundZdisable_not_foundrrr rTsH            rTcs*t||ddf}tfdd|DS)z Checks plugin name matches the pattern. The alternative plugin name using dashes instead of underscores is tried in case of original name is not matched. (see https://bugzilla.redhat.com/show_bug.cgi?id=1980712) r-c3s|]}t|VqdSrrE)r r rGrr rH rz/_plugin_name_matches_pattern..)rkreplacerJ)rrGZ try_namesrrr r}s r}cs<fdd}ttjdtjf|jdd}|_S)z5A class decorator for automatic command registration.cs|r|dSr)register_commandr" command_classrr r$sz"register_command..__init__rr)r$r )typerr,rraliasesZ_plugin)rr$Z plugin_classrrr rs r)Z __future__rrrrFr{rurirgoperatorrr9r;rZ dnf.loggingrZ dnf.pycompZdnf.utilZdnf.i18nrZ getLoggerr=rOobjectrr1rVrUrTr}rrrrr s2     2k %