[yum-cvs] yum/yum __init__.py, 1.107, 1.108 config.py, 1.57, 1.58 plugins.py, 1.5, 1.6
Menno Smits
mjs at login.linux.duke.edu
Sun Mar 27 11:51:39 UTC 2005
Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv19575/yum
Modified Files:
__init__.py config.py plugins.py
Log Message:
More plugin related updates:
- rearranged plugin initialisation:
- YumBase.doPluginSetup() now exists and must be called to initialise
plugins.
- Yum's config and command line args are now parsed before plugins are
initialised. This fixes the problems with the debug level being
ignored for early plugin related output.
- refactored the plugin config registration stuff so its handled
outside of config.py (much cleaner).
- because yum config is parsed before plugin initialisation, a separate
plugin.conf is no longer required. Moved plugin settings to [main] of
yum.conf.
- cleaned up YumPlugins.run() (return code not used anymore)
- fixed up the levels on some plugin related log output
Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- __init__.py 27 Mar 2005 08:46:28 -0000 1.107
+++ __init__.py 27 Mar 2005 11:51:37 -0000 1.108
@@ -56,6 +56,9 @@
self.repos = repos.RepoStorage() # class of repositories
if (not self.repos.sqlite):
self.log(1,"Warning, could not load sqlite, falling back to pickle")
+
+ # Use a dummy object until plugins are initialised
+ self.plugins = plugins.DummyYumPlugins()
def log(self, value, msg):
"""dummy log stub"""
@@ -71,16 +74,9 @@
def doConfigSetup(self, fn='/etc/yum.conf', root='/'):
"""basic stub function for doing configuration setup"""
- # Load plugins first as they make affect available config options
- self.plugins = plugins.YumPlugins(self)
-
- self.conf = config.yumconf(configfile=fn, root=root,
- plugins=self.plugins)
+ self.conf = config.yumconf(configfile=fn, root=root)
self.getReposFromConfig()
- # Initialise plugins
- self.plugins.run('init')
-
def getReposFromConfig(self):
"""read in repositories from config main and .repo files"""
@@ -134,6 +130,21 @@
self.errorlog(2, e)
continue
+ def doPluginSetup(self):
+ '''Initialise yum plugins.
+
+ If plugins are going to be used, this should be called soon after
+ doConfigSetup() has been called.
+ '''
+ # Load plugins first as they make affect available config options
+ self.plugins = plugins.YumPlugins(self)
+
+ # Process options registered by plugins
+ self.plugins.parseopts(self.conf, self.repos.findRepos('*'))
+
+ # Initialise plugins
+ self.plugins.run('init')
+
def doTsSetup(self):
"""setup all the transaction set storage items we'll need
This can't happen in __init__ b/c we don't know our installroot
Index: config.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/config.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- config.py 27 Mar 2005 03:21:57 -0000 1.57
+++ config.py 27 Mar 2005 11:51:37 -0000 1.58
@@ -33,8 +33,6 @@
import urlgrabber.grabber
from repos import variableReplace, Repository
-from constants import *
-
class CFParser(ConfigParser.ConfigParser):
"""wrapper around ConfigParser to provide two simple but useful functions:
@@ -173,7 +171,7 @@
class yumconf(object):
"""primary config class for yum"""
- def __init__(self, configfile = '/etc/yum.conf', root='/', plugins=None):
+ def __init__(self, configfile = '/etc/yum.conf', root='/'):
self.cfg = CFParser()
configh = confpp(configfile)
try:
@@ -183,7 +181,6 @@
except ConfigParser.ParsingError, e:
raise Errors.ConfigError, str(e)
- self.plugins = plugins
self.configdata = {} # dict to hold all the data goodies
@@ -209,6 +206,7 @@
('proxy', None),
('proxy_username', None),
('proxy_password', None),
+ ('pluginpath', ['/usr/lib/yum-plugins']),
('installonlypkgs', ['kernel', 'kernel-bigmem',
'kernel-enterprise','kernel-smp',
'kernel-debug', 'kernel-unsupported',
@@ -232,6 +230,7 @@
('obsoletes', 'False'),
('showdupesfromrepos', 'False'),
('enabled', 'True'),
+ ('plugins', 'False'),
('enablegroups', 'True')]
# not being set from the config file
@@ -323,20 +322,24 @@
# weird ones
- for option in ['commands', 'installonlypkgs', 'kernelpkgnames', 'exclude',
- 'reposdir', 'exactarchlist']:
- self.configdata[option] = variableReplace(self.yumvar, self.configdata[option])
+ for option in ['commands', 'installonlypkgs', 'kernelpkgnames',
+ 'exclude', 'reposdir', 'exactarchlist', 'pluginpath']:
+ self.configdata[option] = variableReplace(self.yumvar,
+ self.configdata[option])
setattr(self, option, self.configdata[option])
# make our lists into lists. :)
for option in ['exclude', 'installonlypkgs', 'kernelpkgnames',
- 'tsflags', 'reposdir', 'exactarchlist']:
+ 'tsflags', 'reposdir', 'exactarchlist', 'pluginpath']:
self.configdata[option] = parseList(self.configdata[option])
setattr(self, option, self.configdata[option])
- # Process options from plugins
- dopluginopts(self.plugins, self.cfg, 'main', PLUG_OPT_WHERE_MAIN,
- self.setConfigOption)
+ # Check that plugin paths are all absolute
+ for path in self.pluginpath:
+ if path[:1] != '/':
+ raise Errors.ConfigError(
+ "All plugin search paths must be absolute")
+
def listConfigOptions(self):
"""return list of options available for global config"""
@@ -422,6 +425,7 @@
"""
thisrepo = Repository(section)
+ thisrepo.cfgparser = cfgparser
thisrepo.set('yumvar', yumconfig.yumvar)
for keyword in ['proxy_username', 'proxy', 'proxy_password',
@@ -480,10 +484,6 @@
thisrepo.set('pkgdir', pkgdir)
thisrepo.set('hdrdir', hdrdir)
- # Process options from plugins
- dopluginopts(yumconfig.plugins, cfgparser, section, PLUG_OPT_WHERE_REPO,
- thisrepo.set)
-
return thisrepo
@@ -504,19 +504,6 @@
listvalue = value.split()
return listvalue
-def dopluginopts(plugins, cfgparser, section, where, setfunc):
- '''Process options from plugins
- '''
- if plugins:
- typetofunc = {
- PLUG_OPT_STRING: cfgparser._getoption,
- PLUG_OPT_INT: cfgparser._getint,
- PLUG_OPT_BOOL: cfgparser._getboolean,
- PLUG_OPT_FLOAT: cfgparser._getfloat,
- }
- for name, vtype, default in plugins.getopts(where):
- setfunc(name, typetofunc[vtype](section, name, default))
-
class confpp:
"""
Index: plugins.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/plugins.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- plugins.py 27 Mar 2005 07:58:53 -0000 1.5
+++ plugins.py 27 Mar 2005 11:51:37 -0000 1.6
@@ -8,17 +8,14 @@
import config
import Errors
-# TODO: fix log() during yum init: early calls to log() (before Logger instance
-# is created) mean that all output goes to stdout regardless of the log settings.
-# - peek at debuglevel option?
+# TODO: update yum.conf man page with plugin related opts
# TODO: better documentation of how the whole thing works (esp. addition of
# config options)
# - document from user perspective in yum man page
# - PLUGINS.txt for developers
-# TODO: require an explicit call to load plugins so that software using yum as
-# a library doesn't get nasty suprises
+# TODO: test the API by implementing some crack from bugzilla
# TODO: check for *_hook methods that aren't supported
@@ -27,7 +24,7 @@
# TODO: multiversion plugin support
-# TODO: cmd line options to disable plugins (all or specific)
+# TODO: cmdline options to disable/enable plugins (all or specific)
# TODO: cmdline option to override/specify additional plugin directories
@@ -59,7 +56,6 @@
# then the minor number must be incremented.
API_VERSION = '0.2'
-PLUGINS_CONF = '/etc/yum/plugins.conf'
SLOTS = ('config', 'init', 'reposetup', 'exclude', 'pretrans', 'posttrans',
'close')
@@ -70,11 +66,10 @@
class YumPlugins:
def __init__(self, base):
- self.enabled = 0
- self.searchpath = ['/usr/lib/yum-plugins']
+ self.enabled = base.conf.plugins
+ self.searchpath = base.conf.pluginpath
self.base = base
- self._getglobalconf()
self._importplugins()
self.opts = {}
@@ -84,38 +79,11 @@
# Let plugins register custom config file options
self.run('config')
- def _getglobalconf(self):
- '''Read global plugin configuration
- '''
- parser = config.CFParser()
- try:
- fin = open(PLUGINS_CONF, 'rt')
- parser.readfp(fin)
- fin.close()
- except ConfigParser.Error, e:
- raise Errors.ConfigError("Couldn't parse %s: %s" % (PLUGINS_CONF,
- str(e)))
-
- except IOError, e:
- self.base.log(3, "Couldn't read %s: plugins disabled" % PLUGINS_CONF)
- return
-
- self.enabled = parser._getboolean('main', 'enabled', 0)
- searchpath = parser._getoption('main', 'searchpath', '')
- if searchpath:
- self.searchpath = config.parseList(searchpath)
- # Ensure that all search paths are absolute
- for path in self.searchpath:
- if path[0] != '/':
- raise Errors.ConfigError(
- "All plugin search paths must be absolute")
-
def run(self, slotname):
'''Run all plugin functions for the given slot.
- Returns true if yum needs to quit, false otherwise.
'''
if not self.enabled:
- return 0
+ return
# Determine handler class to use
if slotname in ('config'):
@@ -133,16 +101,11 @@
for modname, func in self._pluginfuncs[slotname]:
- self.base.log(4, 'Running %s handler for %s plugin' % (
+ self.base.log(3, 'Running "%s" handler for "%s" plugin' % (
slotname, modname))
_, conf = self._plugins[modname]
- result = func(conduitcls(self, self.base, conf))
- if result:
- # Plugin said we need to terminate
- self.base.log(2, "Exiting due to '%s' plugin." % modname)
- return result
- return 0
+ func(conduitcls(self, self.base, conf))
def _importplugins(self):
@@ -171,7 +134,7 @@
conf = self._getpluginconf(modname)
if not conf or not conf._getboolean('main', 'enabled', 0):
- self.base.log(2, '"%s" plugin is disabled' % modname)
+ self.base.log(3, '"%s" plugin is disabled' % modname)
return
self.base.log(2, 'Loading "%s" plugin' % modname)
@@ -242,19 +205,42 @@
)
self.opts[name] = (valuetype, where, default)
- def getopts(self, targetwhere):
- '''Retrieve plugin defined options for the given part of the
- configuration file.
-
- targetwhere: the type of option wanted. Should be
- PLUG_OPT_WHERE_MAIN, PLUG_OPT_WHERE_REPO or PLUG_OPT_WHERE_ALL
- return: A list of (name, value_type, default) tuples.
+ def parseopts(self, conf, repos):
+ '''Parse any configuration options registered by plugins
+
+ conf: the yumconf instance holding Yum's global options
+ repos: a list of all repository objects
'''
- out = []
- for name, (valuetype, where, default) in self.opts.iteritems():
- if where == targetwhere or where == PLUG_OPT_WHERE_ALL:
- out.append((name, valuetype, default))
- return out
+
+ # Process [main] options first
+ self._do_opts(conf.cfg, 'main', PLUG_OPT_WHERE_MAIN,
+ conf.setConfigOption)
+
+ # Process repository level options
+ for repo in repos:
+ self._do_opts(repo.cfgparser, repo.id, PLUG_OPT_WHERE_REPO,
+ repo.set)
+
+ def _do_opts(self, cfgparser, section, targetwhere, setfunc):
+ '''Process registered plugin options for one config file section
+ '''
+ typetofunc = {
+ PLUG_OPT_STRING: cfgparser._getoption,
+ PLUG_OPT_INT: cfgparser._getint,
+ PLUG_OPT_BOOL: cfgparser._getboolean,
+ PLUG_OPT_FLOAT: cfgparser._getfloat,
+ }
+ for name, (vtype, where, default) in self.opts.iteritems():
+ if where in (targetwhere, PLUG_OPT_WHERE_ALL):
+ setfunc(name, typetofunc[vtype](section, name, default))
+
+class DummyYumPlugins:
+ '''
+ This class provides basic emulation of the YumPlugins class. It exists so
+ that calls to plugins.run() don't fail if plugins aren't in use.
+ '''
+ def run(self, *args, **kwargs):
+ pass
class PluginConduit:
def __init__(self, parent, base, conf):
More information about the Yum-cvs-commits
mailing list