[yum-cvs] yum/yum __init__.py,1.115,1.116 plugins.py,1.9,1.10

Menno Smits mjs at login.linux.duke.edu
Thu May 5 10:35:21 UTC 2005


Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv17067/yum

Modified Files:
	__init__.py plugins.py 
Log Message:
- Converted command line option parsing from getopt to optparse module
- Allow plugins to modify command line options and query parsed command line


Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -r1.115 -r1.116
--- __init__.py	15 Apr 2005 04:02:20 -0000	1.115
+++ __init__.py	5 May 2005 10:35:19 -0000	1.116
@@ -57,9 +57,9 @@
         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()
-    
+        # Start with plugins disabled
+        self.disablePlugins()
+
     def log(self, value, msg):
         """dummy log stub"""
         print msg
@@ -130,14 +130,19 @@
                 self.errorlog(2, e)
                 continue
 
-    def doPluginSetup(self):
-        '''Initialise yum plugins. 
+    def disablePlugins(self):
+        '''Disable yum plugins
+        '''
+        self.plugins = plugins.DummyYumPlugins()
+    
+    def doPluginSetup(self, optparser=None):
+        '''Initialise and enable 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)
+        self.plugins = plugins.YumPlugins(self, optparser)
 
         # 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- plugins.py	21 Apr 2005 21:58:40 -0000	1.9
+++ plugins.py	5 May 2005 10:35:19 -0000	1.10
@@ -25,6 +25,12 @@
 # TODO: cmdline option to disable plugins "--noplugins" (for support problems)
 #   - document
 
+# TODO: should plugin searchpath be affected by installroot option?
+
+# TODO: better handling of PluginYumExit
+
+# TODO: consistent case of YumPlugins methods
+
 # TODO: expose progress bar interface
 
 # TODO: allow plugins to define new repository types
@@ -45,7 +51,7 @@
 
 # TODO: allow plugins to extend shell commands
 
-# TODO: allow plugins to extend command line options and commands
+# TODO: allow plugins to commands
 
 # TODO: plugins should be able to specify convertor functions for config vars
 
@@ -82,7 +88,7 @@
 # API, the major version number must be incremented and the minor version number
 # reset to 0. If a change is made that doesn't break backwards compatibility,
 # then the minor number must be incremented.
-API_VERSION = '1.0'
+API_VERSION = '1.1'
 
 SLOTS = (
         'config', 'init', 
@@ -99,13 +105,16 @@
 
 class YumPlugins:
 
-    def __init__(self, base):
+    def __init__(self, base, optparser=None):
         self.enabled = base.conf.plugins
         self.searchpath = base.conf.pluginpath
         self.base = base
+        self.optparser = optparser
+        self.cmdline = (None, None)
 
         self._importplugins()
         self.opts = {}
+        self.cmdlines = {}
 
         # Call close handlers when yum exit's
         atexit.register(self.run, 'close')
@@ -272,6 +281,12 @@
             if where in (targetwhere, PLUG_OPT_WHERE_ALL):
                 setfunc(name, typetofunc[vtype](section, name, default))
 
+    def setCmdLine(self, opts, commands):
+        '''Set the parsed command line options so that plugins can access them
+        '''
+        self.cmdline = (opts, commands)
+
+
 class DummyYumPlugins:
     '''
     This class provides basic emulation of the YumPlugins class. It exists so
@@ -303,6 +318,23 @@
         import yum
         return yum.__version__
 
+    def getOptParser(self):
+        '''Return the optparse.OptionParser instance for this execution of Yum
+
+        In the "config" and "init" slots a plugin may add extra options to this
+        instance to extend the command line options that Yum exposes.
+
+        In all other slots a plugin may only read the OptionParser instance.
+        Any modification of the instance at this point will have no effect. 
+        
+        See the getCmdLine() method for details on how to retrieve the parsed
+        values of command line options.
+
+        @return: the global optparse.OptionParser instance used by Yum. May be
+            None if an OptionParser isn't in use.
+        '''
+        return self._parent.optparser
+
     def confString(self, section, opt, default=None):
         '''Read a string value from the plugin's own configuration file
         '''
@@ -326,8 +358,13 @@
 class ConfigPluginConduit(PluginConduit):
 
     def registerOpt(self, *args, **kwargs):
+        '''Register a yum configuration file option.
+
+        Arguments are as for YumPlugins.registeropt().
+        '''
         self._parent.registeropt(*args, **kwargs)
 
+
 class InitPluginConduit(PluginConduit):
 
     def getConf(self):
@@ -335,6 +372,13 @@
 
 class RepoSetupPluginConduit(InitPluginConduit):
 
+    def getCmdLine(self):
+        '''Return parsed command line options.
+
+        @return: (options, commands) as returned by OptionParser.parse_args()
+        '''
+        return self._parent.cmdline
+
     def getRepo(self, repoid):
         '''Return a repository object by its id
         '''




More information about the Yum-cvs-commits mailing list