[yum-git] Branch 'yum-3_2_X' - 2 commits - cli.py yum/__init__.py yum/packageSack.py yum/plugins.py

James Antill james at linux.duke.edu
Mon Jul 28 03:25:57 UTC 2008


 cli.py             |    9 +++++++--
 yum/__init__.py    |   10 ++++++----
 yum/packageSack.py |   22 ++++++++++++----------
 yum/plugins.py     |   46 +++++++++++++++++++++++++++++++++++++---------
 4 files changed, 62 insertions(+), 25 deletions(-)

New commits:
commit 4bc761f70c4b8a504dd27cffead0d21207dfc200
Author: James Antill <james at and.org>
Date:   Sun Jul 27 23:17:13 2008 -0400

    Add --enableplugin option

diff --git a/cli.py b/cli.py
index d40e4b6..4dda42c 100644
--- a/cli.py
+++ b/cli.py
@@ -180,7 +180,8 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
                     optparser=self.optparser,
                     debuglevel=opts.debuglevel,
                     errorlevel=opts.errorlevel,
-                    disabled_plugins=self.optparser._splitArg(opts.disableplugins))
+                    disabled_plugins=self.optparser._splitArg(opts.disableplugins),
+                    enabled_plugins=self.optparser._splitArg(opts.enableplugins))
                     
         except yum.Errors.ConfigError, e:
             self.logger.critical(_('Config Error: %s'), e)
@@ -991,7 +992,8 @@ class YumOptionParser(OptionParser):
         try:
             args = _filtercmdline(
                         ('--noplugins','--version','-q', '-v', "--quiet", "--verbose"), 
-                        ('-c', '-d', '-e', '--installroot','--disableplugin'), 
+                        ('-c', '-d', '-e', '--installroot',
+                         '--disableplugin', '--enableplugin'), 
                         args)
         except ValueError, arg:
             self.base.usage()
@@ -1176,6 +1178,9 @@ class YumOptionParser(OptionParser):
         self.add_option("", "--disableplugin", dest="disableplugins", default=[], 
                 action="append", help=_("disable plugins by name"),
                 metavar='[plugin]')
+        self.add_option("", "--enableplugin", dest="enableplugins", default=[], 
+                action="append", help=_("enable plugins by name"),
+                metavar='[plugin]')
         self.add_option("--skip-broken", action="store_true", dest="skipbroken",
                 help=_("skip packages with depsolving problems"))
 
diff --git a/yum/__init__.py b/yum/__init__.py
index 760fc85..b2dc186 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -136,7 +136,7 @@ class YumBase(depsolve.Depsolve):
         
     def _getConfig(self, fn='/etc/yum/yum.conf', root='/', init_plugins=True,
             plugin_types=(plugins.TYPE_CORE,), optparser=None, debuglevel=None,
-            errorlevel=None,disabled_plugins=None):
+            errorlevel=None,disabled_plugins=None,enabled_plugins=None):
         '''
         Parse and load Yum's configuration files and call hooks initialise
         plugins and logging.
@@ -153,6 +153,7 @@ class YumBase(depsolve.Depsolve):
         @param errorlevel: Error level to use for logging. If None, the debug
             level will be read from the configuration file.
         @param disabled_plugins: Plugins to be disabled    
+        @param enabled_plugins: Plugins to be enabled
         '''
 
         if self._conf:
@@ -178,7 +179,7 @@ class YumBase(depsolve.Depsolve):
 
         if init_plugins and startupconf.plugins:
             self.doPluginSetup(optparser, plugin_types, startupconf.pluginpath,
-                    startupconf.pluginconfpath,disabled_plugins)
+                    startupconf.pluginconfpath,disabled_plugins,enabled_plugins)
 
         self._conf = config.readMainConfig(startupconf)
 
@@ -317,7 +318,7 @@ class YumBase(depsolve.Depsolve):
         self.plugins = plugins.DummyYumPlugins()
     
     def doPluginSetup(self, optparser=None, plugin_types=None, searchpath=None,
-            confpath=None,disabled_plugins=None):
+            confpath=None,disabled_plugins=None,enabled_plugins=None):
         '''Initialise and enable yum plugins. 
 
         Note: _getConfig() will initialise plugins if instructed to. Only
@@ -335,12 +336,13 @@ class YumBase(depsolve.Depsolve):
             configuration files. A default will be used if no value is
             specified.
         @param disabled_plugins: Plugins to be disabled    
+        @param enabled_plugins: Plugins to be enabled
         '''
         if isinstance(self.plugins, plugins.YumPlugins):
             raise RuntimeError(_("plugins already initialised"))
 
         self.plugins = plugins.YumPlugins(self, searchpath, optparser,
-                plugin_types, confpath, disabled_plugins)
+                plugin_types, confpath, disabled_plugins, enabled_plugins)
 
     
     def doRpmDBSetup(self):
diff --git a/yum/plugins.py b/yum/plugins.py
index 9e094ed..7b8070a 100644
--- a/yum/plugins.py
+++ b/yum/plugins.py
@@ -115,7 +115,7 @@ class YumPlugins:
     '''
 
     def __init__(self, base, searchpath, optparser=None, types=None, 
-            pluginconfpath=None,disabled=None):
+            pluginconfpath=None,disabled=None,enabled=None):
         '''Initialise the instance.
 
         @param base: The
@@ -138,6 +138,7 @@ class YumPlugins:
         self.cmdline = (None, None)
         self.verbose_logger = logging.getLogger("yum.verbose.YumPlugins")
         self.disabledPlugins = disabled
+        self.enabledPlugins  = enabled
         if types is None:
             types = ALL_TYPES
         if not isinstance(types, (list, tuple)):
@@ -186,6 +187,7 @@ class YumPlugins:
 
         # Import plugins 
         self._used_disable_plugin = set()
+        self._used_enable_plugin  = set()
         for dir in self.searchpath:
             if not os.path.isdir(dir):
                 continue
@@ -207,6 +209,26 @@ class YumPlugins:
                     self.verbose_logger.log(logginglevels.INFO_2,
                                             _("No plugin match for: %s") % wc)
         del self._used_disable_plugin
+        if self.enabledPlugins:
+            for wc in self.enabledPlugins:
+                if wc not in self._used_enable_plugin:
+                    self.verbose_logger.log(logginglevels.INFO_2,
+                                            _("No plugin match for: %s") % wc)
+        del self._used_enable_plugin
+
+    @staticmethod
+    def _plugin_cmdline_match(modname, plugins, used):
+        """ Check if this plugin has been temporary enabled/disabled. """
+        if plugins is None:
+            return False
+
+        for wc in plugins:
+            if fnmatch.fnmatch(modname, wc):
+                used.add(wc)
+                return True
+
+        return False
+
 
     def _loadplugin(self, modulefile, types):
         '''Attempt to import a plugin module and register the hook methods it
@@ -216,8 +238,11 @@ class YumPlugins:
         modname = modname.split('.py')[0]
 
         conf = self._getpluginconf(modname)
-        if not conf or not config.getOption(conf, 'main', 'enabled', 
-                config.BoolOption(False)):
+        if (not conf or
+            (not config.getOption(conf, 'main', 'enabled',
+                                  config.BoolOption(False)) and
+             not self._plugin_cmdline_match(modname, self.enabledPlugins,
+                                            self._used_enable_plugin))):
             self.verbose_logger.debug(_('"%s" plugin is disabled'), modname)
             return
 
@@ -256,12 +281,15 @@ class YumPlugins:
 
             if plugintype not in types:
                 return
-        # Check if this plugin has been temporary disabled
-        if self.disabledPlugins:
-            for wc in self.disabledPlugins:
-                if fnmatch.fnmatch(modname, wc):
-                    self._used_disable_plugin.add(wc)
-                    return
+
+        #  This should really work like enable/disable repo. and be based on the
+        # cmd line order ... but the API doesn't really allow that easily.
+        # FIXME: Fix for 4.*
+        if (self._plugin_cmdline_match(modname, self.disabledPlugins,
+                                       self._used_disable_plugin) and
+            not self._plugin_cmdline_match(modname, self.enabledPlugins,
+                                           self._used_enable_plugin)):
+            return
 
         self.verbose_logger.log(logginglevels.DEBUG_3, _('Loading "%s" plugin'),
                                 modname)
commit 60ff79687a4010ef6b81b9f25bacb7a83ce573a1
Author: James Antill <james at and.org>
Date:   Sun Jul 27 23:12:49 2008 -0400

    Minor cleanup for obsoletes processing

diff --git a/yum/packageSack.py b/yum/packageSack.py
index 4bb57bf..f3d2a4d 100644
--- a/yum/packageSack.py
+++ b/yum/packageSack.py
@@ -332,9 +332,12 @@ class MetaSack(PackageSackBase):
         
         # go through each of the keys of the obs dict and see if it is in the
         # sack of newest pkgs - if it is not - remove the entry
-        for obstup in obsdict.keys():
+        togo = []
+        for obstup in obsdict:
             if obstup not in newest_tups:
-                del obsdict[obstup]
+                togo.append(obstup)
+        for obstup in togo:
+            del obsdict[obstup]
         
         return obsdict
         
@@ -606,11 +609,7 @@ class PackageSack(PackageSackBase):
         for po in self.returnPackages():
             if len(po.obsoletes) == 0:
                 continue
-
-            if not obs.has_key(po.pkgtup):
-                obs[po.pkgtup] = po.obsoletes
-            else:
-                obs[po.pkgtup].extend(po.obsoletes)
+            obs.setdefault(po.pkgtup, []).extend(po.obsoletes)
 
         if not newest:
             return obs
@@ -621,9 +620,12 @@ class PackageSack(PackageSackBase):
 
         # go through each of the keys of the obs dict and see if it is in the
         # sack of newest pkgs - if it is not - remove the entry
-        for obstup in obs.keys():
-            if obstup not in  newest_tups:
-                del obs[obstup]
+        togo = []
+        for obstup in obs:
+            if obstup not in newest_tups:
+                togo.append(obstup)
+        for obstup in togo:
+            del obs[obstup]
             
         return obs
         



More information about the Yum-cvs-commits mailing list