r133 - branches/rewrite/src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Fri, 02 Jul 2004 09:12:09 -0600


Author: otavio
Date: Fri Jul  2 09:12:08 2004
New Revision: 133

Modified:
   branches/rewrite/src/Config.py
Log:
Some more code clenup and better exception handle.

Modified: branches/rewrite/src/Config.py
==============================================================================
--- branches/rewrite/src/Config.py	(original)
+++ branches/rewrite/src/Config.py	Fri Jul  2 09:12:08 2004
@@ -33,6 +33,17 @@
         self.section = section
         self.option = option
 
+class InvalidSection(Exception):
+    """
+    Exception called when a invalid section is found in configuration
+    file.
+
+    Attributes:
+        section -- The wrong section name.
+    """
+    def __init__(self, section):
+        self.section = section
+
 class Config(dict):
     """
     Store the configurations used by our system.
@@ -88,7 +99,6 @@
 			if allowed_key.find('@') != -1:
 			    left_length = allowed_key.find('@')
 			    right_length = allowed_key[left_length+1:].find('@') + left_length + 2
-                            print allowed_key[:left_length], item[:left_length]
 			    if (allowed_key[:left_length] == item[:left_length]
                                 and allowed_key[right_length:] == item[right_length:]):
 				# found it!
@@ -98,12 +108,12 @@
                                     if match in conf.sections():
                                         break
                                 else:
-                                    warning("Config value [%s] matches unknown variable [%s].  This is probably a bug in this program, please report it!" % (item, variable))
-                                    # go on anyway, though
-                                    break
+                                    error("You found a bug: [%s] matches unknown variable [%s]! "
+                                          "Please report it." % (item, variable))
+                                    exit(1)
                     else:
 			debug("[%s] is not allowed in a backend section (it was found in [%s])."
-			    % (item, section))
+                              % (item, section))
                         raise InvalidOption(section, item)
 		self[section][item] = value
 
@@ -111,12 +121,12 @@
 	# get a config value for a certain section.  if it's not
 	# specified, fall back to GLOBAL
 	if not self.has_key(section):
-	    error("no config section called [%s]." % (section))
-	    exit(1)
+	    debug("no config section called [%s]." % (section))
+	    raise InvalidSection(section)
 	if self[section].has_key(key):
 	    return self[section][key]
 	if not self['GLOBAL'].has_key(key):
-	    error("[%s] is not present in section [%s] or the global section of config file." % (key, section))
+	    debug("[%s] is not present in section [%s] or the global section of config file." % (key, section))
 	    exit(1)
 	return self['GLOBAL'][key]