[yum-cvs] yum/yum __init__.py,1.119,1.120 plugins.py,1.13,1.14
Menno Smits
mjs at login.linux.duke.edu
Tue Jun 7 11:34:46 UTC 2005
Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv21303/yum
Modified Files:
__init__.py plugins.py
Log Message:
Plugin type support:
- plugins can specify what type they are via the plugin_type attribute
- the type(s) of plugin to load can be specified when calling
doPluginSetup()
Updated plugin TODO.
Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -r1.119 -r1.120
--- __init__.py 2 Jun 2005 15:33:52 -0000 1.119
+++ __init__.py 7 Jun 2005 11:34:44 -0000 1.120
@@ -137,14 +137,21 @@
'''
self.plugins = plugins.DummyYumPlugins()
- def doPluginSetup(self, optparser=None):
+ def doPluginSetup(self, optparser=None, typefilter=None):
'''Initialise and enable yum plugins.
If plugins are going to be used, this should be called soon after
doConfigSetup() has been called.
+
+ @param optparser: The OptionParser instance for this run (optional)
+ @param typefilter: A sequence specifying the types of plugins to load.
+ This should be sequnce containing one or more of the
+ yum.plugins.TYPE_... constants. If None (the default), all plugins
+ will be loaded.
'''
# Load plugins first as they make affect available config options
- self.plugins = plugins.YumPlugins(self, self.conf.pluginpath, optparser)
+ self.plugins = plugins.YumPlugins(self, self.conf.pluginpath,
+ optparser, typefilter)
# Process options registered by plugins
self.plugins.parseopts(self.conf, self.repos.findRepos('*'))
Index: plugins.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/plugins.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- plugins.py 2 Jun 2005 15:33:52 -0000 1.13
+++ plugins.py 7 Jun 2005 11:34:44 -0000 1.14
@@ -32,10 +32,6 @@
# TODO: allow plugins to define new repository types
-# TODO: allow a plugin to signal that the remainder of the calling function
-# should be skipped so that the plugin can override the caller?
-# - there may be a better way to do this
-
# TODO: check for *_hook methods that aren't supported
# TODO "log" slot? To allow plugins to do customised logging/history (say to a
@@ -87,6 +83,11 @@
# then the minor number must be incremented.
API_VERSION = '2.1'
+# Plugin types
+TYPE_CORE = 0
+TYPE_INTERFACE = 1
+ALL_TYPES = (TYPE_CORE, TYPE_INTERFACE)
+
SLOTS = (
'config', 'init',
'predownload', 'postdownload',
@@ -103,13 +104,31 @@
class YumPlugins:
- def __init__(self, base, searchpath, optparser=None):
+ '''
+ Manager class for Yum plugins.
+ '''
+
+ def __init__(self, base, searchpath, optparser=None, typefilter=None):
+ '''Initialise the instance.
+
+ @param base: The
+ @param searchpath: A list of paths to look for plugin modules.
+ @param optparser: The OptionParser instance for this run (optional).
+ Use to allow plugins to extend command line options.
+ @param typefilter: A sequence specifying the types of plugins to load.
+ This should be sequnce containing one or more of the TYPE_...
+ constants. If None (the default), all plugins will be loaded.
+ '''
+
self.searchpath = searchpath
self.base = base
self.optparser = optparser
self.cmdline = (None, None)
+ if not typefilter:
+ typefilter = ALL_TYPES
+
+ self._importplugins(typefilter)
- self._importplugins()
self.opts = {}
self.cmdlines = {}
@@ -150,7 +169,9 @@
_, conf = self._plugins[modname]
func(conduitcls(self, self.base, conf, **kwargs))
- def _importplugins(self):
+ def _importplugins(self, typefilter):
+ '''Load plugins matching the given types.
+ '''
# Initialise plugin dict
self._plugins = {}
@@ -163,9 +184,9 @@
if not os.path.isdir(dir):
continue
for modulefile in glob.glob('%s/*.py' % dir):
- self._loadplugin(modulefile)
+ self._loadplugin(modulefile, typefilter)
- def _loadplugin(self, modulefile):
+ def _loadplugin(self, modulefile, typefilter):
'''Attempt to import a plugin module and register the hook methods it
uses.
'''
@@ -177,8 +198,6 @@
self.base.log(3, '"%s" plugin is disabled' % modname)
return
- self.base.log(2, 'Loading "%s" plugin' % modname)
-
fp, pathname, description = imp.find_module(modname, [dir])
module = imp.load_module(modname, fp, pathname, description)
@@ -195,6 +214,19 @@
API_VERSION,
))
+ # Check plugin type against filter
+ plugintypes = getattr(module, 'plugin_type', ALL_TYPES)
+ if not isinstance(plugintypes, (list, tuple)):
+ plugintypes = (plugintypes,)
+
+ if len(plugintypes) < 1:
+ return
+ for plugintype in plugintypes:
+ if plugintype not in typefilter:
+ return
+
+ self.base.log(2, 'Loading "%s" plugin' % modname)
+
# Store the plugin module and its configuration file
if not self._plugins.has_key(modname):
self._plugins[modname] = (module, conf)
More information about the Yum-cvs-commits
mailing list