[yum-cvs] yum/yum __init__.py, 1.208, 1.209 config.py, 1.98, 1.99 plugins.py, 1.26, 1.27

Menno Smits mjs at linux.duke.edu
Thu Jun 15 09:59:16 UTC 2006


Update of /home/groups/yum/cvs/yum/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv24269/yum

Modified Files:
	__init__.py config.py plugins.py 
Log Message:
Clean up recent changes to config setup API:
- removed doStartupConfig()
- doConfigSetup() now sets up plugins and logging at the right time via 
  external (overridable) methods
- don't keep startupconf hanging around in base object (removed all references)


Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.208
retrieving revision 1.209
diff -u -r1.208 -r1.209
--- __init__.py	14 Jun 2006 18:04:28 -0000	1.208
+++ __init__.py	15 Jun 2006 09:59:14 -0000	1.209
@@ -89,26 +89,61 @@
         """do a default setup for all the normal/necessary yum components,
            really just a shorthand for testing"""
         
-        self.doStartupConfig()
-        self.doConfigSetup()
+        self.doConfigSetup(init_plugins=False)
         self.conf.cache = cache
         self.doTsSetup()
         self.doRpmDBSetup()
         self.doRepoSetup()
         self.doSackSetup()
-        
-    def doStartupConfig(self, fn='/etc/yum.conf', root='/'):
-        '''Read up configuration options required early during startup.
+       
+    def doConfigSetup(self, fn='/etc/yum.conf', root='/', init_plugins=True,
+            plugin_types=None, optparser=None, debuglevel=None,
+            errorlevel=None):
         '''
-        self.startupconf = config.readStartupConfig(fn, root)
-        
-    def doConfigSetup(self):
-        """basic stub function for doing configuration setup"""
-      
-        self.conf = config.readMainConfig(self.startupconf)
+        Parse and load Yum's configuration files and call hooks initialise
+        plugins and logging.
+
+        @param fn: Path to main configuration file to parse (yum.conf).
+        @param root: Filesystem root to use.
+        @param init_plugins: If False, plugins will not be loaded here. If
+            True, plugins will be loaded if the "plugins" option is enabled in
+            the configuration file.
+        @param plugin_types: As per doPluginSetup()
+        @param optparser: As per doPluginSetup()
+        @param debuglevel: Debug level to use for logging. If None, the debug
+            level will be read from the configuration file.
+        @param errorlevel: Error level to use for logging. If None, the debug
+            level will be read from the configuration file.
+        '''
+        startupconf = config.readStartupConfig(fn, root)
+     
+        if debuglevel != None:
+            startupconf.debuglevel = debuglevel
+        if errorlevel != None:
+            startupconf.errorlevel = errorlevel
+    
+        self.doLoggingSetup(startupconf.debuglevel, startupconf.errorlevel)
+
+        if init_plugins and startupconf.plugins:
+            self.doPluginSetup(optparser, plugin_types, startupconf.pluginpath,
+                    startupconf.pluginconfpath)
+
+        self.conf = config.readMainConfig(startupconf)
         self.yumvar = self.conf.yumvar
         self.getReposFromConfig()
 
+    def doLoggingSetup(self, debuglevel, errorlevel):
+        '''
+        Perform logging related setup.
+
+        Subclasses should override this to initialise logging functionality as
+        required.
+
+        @param debuglevel: Debug logging level to use.
+        @param errorlevel: Error logging level to use.
+        '''
+        pass
+
     def getReposFromConfig(self):
         """read in repositories from config main and .repo files"""
 
@@ -165,23 +200,30 @@
         '''
         self.plugins = plugins.DummyYumPlugins()
     
-    def doPluginSetup(self, optparser=None, types=None):
+    def doPluginSetup(self, optparser=None, plugin_types=None, searchpath=None,
+            confpath=None):
         '''Initialise and enable yum plugins. 
 
-        This should be called after doStartupConfig() has been called but
-        before doConfigSetup() so that plugins can modify Yum's configuration
-        option definitions.
+        Note: doConfigSetup() will initialise plugins if instructed to. Only
+        call this method directly if not calling doConfigSetup() or calling
+        doConfigSetup(init_plugins=False).
 
         @param optparser: The OptionParser instance for this run (optional)
-        @param types: A sequence specifying the types of plugins to load.
+        @param plugin_types: 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.
+        @param searchpath: A list of directories to look in for plugins. A
+            default will be used if no value is specified.
+        @param confpath: A list of directories to look in for plugin
+            configuration files. A default will be used if no value is
+            specified.
         '''
-        self.plugins = plugins.YumPlugins(self, self.startupconf.pluginpath,
-                optparser, types)
+        if isinstance(plugins, plugins.YumPlugins):
+            raise RuntimeError("plugins already initialised")
 
-        # Initialise plugins
+        self.plugins = plugins.YumPlugins(self, searchpath, optparser,
+                plugin_types, confpath)
         self.plugins.run('init')
 
     def doTsSetup(self):

Index: config.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/config.py,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- config.py	4 Jun 2006 19:48:37 -0000	1.98
+++ config.py	15 Jun 2006 09:59:14 -0000	1.99
@@ -487,7 +487,6 @@
 
     Note: see also options inherited from StartupConf
     '''
-
     retries = IntOption(10)
     recent = IntOption(7)
 

Index: plugins.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/plugins.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- plugins.py	4 Jun 2006 19:56:28 -0000	1.26
+++ plugins.py	15 Jun 2006 09:59:14 -0000	1.27
@@ -101,7 +101,8 @@
     Manager class for Yum plugins.
     '''
 
-    def __init__(self, base, searchpath, optparser=None, types=None):
+    def __init__(self, base, searchpath, optparser=None, types=None, 
+            pluginconfpath=None):
         '''Initialise the instance.
 
         @param base: The
@@ -111,9 +112,14 @@
         @param types: 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.
+        @param pluginconfpath: A list of paths to look for plugin configuration
+            files. Defaults to "/etc/yum/pluginconf.d".
         '''
+        if not pluginconfpath:
+            pluginconfpath = ['/etc/yum/pluginconf.d']
 
         self.searchpath = searchpath
+        self.pluginconfpath = pluginconfpath
         self.base = base
         self.optparser = optparser
         self.cmdline = (None, None)
@@ -233,7 +239,7 @@
         IncludingConfigParser instance representing it. Returns None if there
         was an error reading or parsing the configuration file.
         '''
-        for dir in self.base.startupconf.pluginconfpath:
+        for dir in self.pluginconfpath:
             conffilename = os.path.join(dir, modname + ".conf")
             if os.access(conffilename, os.R_OK):
                 # Found configuration file




More information about the Yum-cvs-commits mailing list