3 fV%@sddlmZddlmZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZejdZdZGdd 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 Ncstjj}|jr|jn|jfdd|jD}xb|D]Z}tjj|r6y|j |Wq6t k r}zt j j tdt|WYdd}~Xq6Xq6W|S)Ncsg|]}d|fqS)z %s/%s.conf).0path)namer/usr/lib/python3.6/plugin.py 9sz&Plugin.read_config..zParsing file failed: %s)libdnfconfZ ConfigParser config_namer Zpluginconfpathosr isfileread Exceptionr exceptionsZ ConfigErrorrstr)clsrparserfilesfileer)r r read_config4s   .zPlugin.read_configcCs||_||_dS)N)basecli)selfrrrrr __init__BszPlugin.__init__cCsdS)Nr)rrrr pre_configGszPlugin.pre_configcCsdS)Nr)rrrr configKsz Plugin.configcCsdS)Nr)rrrr resolvedOszPlugin.resolvedcCsdS)Nr)rrrr sackSsz Plugin.sackcCsdS)Nr)rrrr pre_transactionWszPlugin.pre_transactioncCsdS)Nr)rrrr 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|_dS)N) plugin_clsplugins)rrrr r aszPlugins.__init__cCs |jdS)N)_unload)rrrr __del__eszPlugins.__del__c Cs~xx|jD]n}yt||Wqtjjk r6Yqtk rttj\}}}tj |||}t j dj |YqXqWdS)N) r.getattrrrErrorrsysexc_info tracebackformat_exceptionloggerZcriticaljoin)rmethodpluginexc_type exc_value exc_tracebackZ except_listrrr _callerhs zPlugins._callercsxxr|jddD]`}|jtfdd|Dr2q|j|}|jdo^|jddo^|jdd }|r|jj|qWdS)zwChecks whether plugins are enabled or disabled in configuration files and removes disabled plugins from listNc3s|]}tj|VqdS)N)fnmatch)r pattern)r rr xsz)Plugins._check_enabled..mainZenabled)r-r anyrZ has_sectionZ has_optionZ getbooleanremove)rrenable_pluginsZplug_clsrZdisabledr)r r _check_enabledss   zPlugins._check_enabledcCsttjkrtdtjjttjt<}g|_t|j ||}t ||t dd|_ |j ||t|j dkrtdd|j D}tjtddj|dS)z)Dynamically load relevant plugin modules.zload_plugins() called twiceNrcss|] }|jVqdS)N)r )r r;rrr rBsz Plugins._load..zLoaded plugins: %sz, )DYNAMIC_PACKAGEr4modules RuntimeErrorrZpycomp ModuleType__path___get_plugins_filesZ pluginpath_import_modules_plugin_classesr-rGlensortedr8debugrr9)rrZskipsrFpackagernamesrrr _loads   z Plugins._loadcCs|jddS)Nr!)r?)rrrr _run_pre_configszPlugins._run_pre_configcCs|jddS)Nr")r?)rrrr _run_configszPlugins._run_configNcCs*x$|jD]}|||}|jj|qWdS)N)r-r.append)rrrZp_clsr;rrr _run_inits  zPlugins._run_initcCs|jddS)Nr$)r?)rrrr run_sackszPlugins.run_sackcCs|jddS)Nr#)r?)rrrr run_resolvedszPlugins.run_resolvedcCs|jddS)Nr%)r?)rrrr run_pre_transactionszPlugins.run_pre_transactioncCs|jddS)Nr&)r?)rrrr run_transactionszPlugins.run_transactioncCs&ttjkr"tjtjjdtjt=dS)NzPlugins were unloaded.)rHr4rIr8logrloggingZDDEBUG)rrrr r/s zPlugins._unloadcCs|js dSt}x|jD]}||tj|j<qWt|j}t}x |jD]}|j|j |j qJW|sldSx|j D]}|j |j qtWx|D]}|jj ||qWdS)zH Unload plugins that were removed in the `transaction`. N)Z remove_setdictr.inspectZgetfile __class__setkeysupdate intersectionrZ install_setdifference_updaterE)rr&r.r;Z plugin_filesZerased_plugin_filesZpkgZ plugin_filerrr unload_removed_pluginss     zPlugins.unload_removed_plugins)N)r'r(r)r r0r?rGrUrVrWrYrZr[r\r]r/rhrrrr r,`s  r,cCstjS)N)r__subclasses__rrrr rOsrOcCsx|D]}tjj|\}}|jj|tjj|\}}d|j|f}ytj|}Wqt k r}z,t j t d||t j tjjdddWYdd}~XqXqWdS)Nz%s.%szFailed loading plugin "%s": %sr1T)r5)rr splitrLrXsplitextr' importlib import_modulerr8errorrr^rr_ZSUBDEBUG)rSZpy_filesfnr moduleZextr rrrr rNs  rNcCsJg}t|}t|}t}t}x|D]}xtjd|D]}tjjtjj|\}} d} d} xN|D]F} t|| rd|j| d} x$|D]} t|| rd} |j| qWd} qdW| sx |D]} t|| r|j| qW| r:|j|q:Wq&W|j |}|rt j t dj djt||j |}|rFt j t dj djt||S)Nz%s/*.pyTFz=No matches found for the following enable plugin patterns: {}z, z>No matches found for the following disable plugin patterns: {})rcglobrr rkbasename_plugin_name_matches_patternaddrX differencer8Zwarningrformatr9rQ)pathsZdisable_pluginsrFr.Zpattern_enable_foundZpattern_disable_foundpro plugin_nameZdummyZmatchedZenable_pattern_testedZ pattern_skipZpattern_enableZenable_not_foundZdisable_not_foundrrr rMsD            rMcs*t||jddf}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|]}tj|VqdS)N)r@)r r )rArr rB sz/_plugin_name_matches_pattern..)rcreplacerD)ryrAZ try_namesr)rAr rss rscs<fdd}ttjdtjf|jdd}|_S)z5A class decorator for automatic command registration.cs|r|jdS)N)register_command)rrr) command_classrr r sz"register_command..__init__rr)r r )typerr'rraliasesZ_plugin)r}r Z plugin_classr)r}r r|s r|)Z __future__rrrr@rqrlrar_operatorrr4r6rZ dnf.loggingrZ dnf.pycompZdnf.utilZdnf.i18nrZ getLoggerr8rHobjectrr,rOrNrMrsr|rrrr s2     2k %