[yum-cvs] yum cli.py,1.210,1.211

Menno Smits mjs at linux.duke.edu
Sun Jun 4 19:48:39 UTC 2006


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

Modified Files:
	cli.py 
Log Message:
Allow plugins to add and manipulate Yum's configuration file options in the
same way as they are defined in Yum. This means that plugin option defines are
far more flexible and powerful than before. The old API (registerOpt) still
exists but is deprecated (with a saner implementation). I will update the wiki
with info on how plugins can now define their own options.

This cleans up a lot of plugin related code but changes the Yum API slightly
wrt to initialisation. Documentation about this to come on yum-devel.

This commit also includes Misa's (misa+yum at redhat.com) patch to add a config
option for specifying the directories to look in for plugin configuration
files.


Index: cli.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/cli.py,v
retrieving revision 1.210
retrieving revision 1.211
diff -u -r1.210 -r1.211
--- cli.py	9 May 2006 07:55:50 -0000	1.210
+++ cli.py	4 Jun 2006 19:48:37 -0000	1.211
@@ -162,45 +162,54 @@
             sys.exit(1)
         opts = self.optparser.parse_args(args=args)[0]
 
-        try: 
-            # If the conf file is inside the  installroot - use that.
-            # otherwise look for it in the normal root
-            if opts.installroot:
-                if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
-                    opts.conffile = opts.installroot+'/'+opts.conffile
-                root=opts.installroot
-            else:
-                root = '/'
-                    
-            # Parse the configuration file
-            try:
-                self.doConfigSetup(fn=opts.conffile, root=root)
-            except yum.Errors.ConfigError, e:
-                self.errorlog(0, _('Config Error: %s') % e)
-                sys.exit(1)
-                
-            # Initialise logger object
-            self.log=Logger(threshold=self.conf.debuglevel,
-                    file_object=sys.stdout)
-
-            # Setup debug and error levels
-            if opts.debuglevel is not None:
-                self.log.threshold=opts.debuglevel
-                self.conf.debuglevel = opts.debuglevel
-
-            if opts.errorlevel is not None:
-                self.errorlog.threshold=opts.errorlevel
-                self.conf.errorlevel = opts.errorlevel
-
+        # If the conf file is inside the  installroot - use that.
+        # otherwise look for it in the normal root
+        if opts.installroot:
+            if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
+                opts.conffile = opts.installroot+'/'+opts.conffile
+            root=opts.installroot
+        else:
+            root = '/'
+       
+        # Do read of config options required during initialisation
+        try:
+            self.doStartupConfig(opts.conffile, root)
+        except yum.Errors.ConfigError, e:
+            self.errorlog(0, _('Config Error: %s') % e)
+            sys.exit(1)
         except ValueError, e:
             self.errorlog(0, _('Options Error: %s') % e)
             self.usage()
             sys.exit(1)
 
-        # Initialise plugins if cmd line and config file say these should be in
-        # use (this may add extra command line options)
-        if not opts.noplugins and self.conf.plugins:
+        # Initialise logger object
+        self.log = Logger(threshold=self.startupconf.debuglevel,
+                file_object=sys.stdout)
+
+        # Setup debug and error levels
+        if opts.debuglevel is not None:
+            self.log.threshold = opts.debuglevel
+            self.startupconf.debuglevel = opts.debuglevel
+        if opts.errorlevel is not None:
+            self.errorlog.threshold = opts.errorlevel
+            self.startupconf.errorlevel = opts.errorlevel
+    
+        # Initialise plugins if cmd line and config file say they should be in
+        # use. In this step plugins may add extra command line options or
+        # configuration file options.
+        if not opts.noplugins and self.startupconf.plugins:
             self.doPluginSetup(self.optparser)
+            
+        # Parse the configuration file
+        try: 
+            self.doConfigSetup()
+        except yum.Errors.ConfigError, e:
+            self.errorlog(0, _('Config Error: %s') % e)
+            sys.exit(1)
+        except ValueError, e:
+            self.errorlog(0, _('Options Error: %s') % e)
+            self.usage()
+            sys.exit(1)
 
         # Now parse the command line for real
         (opts, self.cmds) = self.optparser.parse_args()




More information about the Yum-cvs-commits mailing list