r141 - branches/rewrite/src

Nat Budin partial-mirror-devel@lists.alioth.debian.org
Sat, 03 Jul 2004 14:48:36 -0600


Author: natbudin-guest
Date: Sat Jul  3 14:48:36 2004
New Revision: 141

Modified:
   branches/rewrite/src/Config.py
Log:
Required options now really required.


Modified: branches/rewrite/src/Config.py
==============================================================================
--- branches/rewrite/src/Config.py	(original)
+++ branches/rewrite/src/Config.py	Sat Jul  3 14:48:36 2004
@@ -33,6 +33,19 @@
         self.section = section
         self.option = option
 
+class RequiredOptionMissing(Exception):
+    """
+    Exception called when a required option in the config file is not
+    present.
+
+    Attributes:
+        section -- Where the invalid option was set;
+        option -- The name of invalid option.
+    """
+    def __init__(self, section, option):
+        self.section = section
+        self.option = option
+
 class InvalidSection(Exception):
     """
     Exception called when a invalid section is found in configuration
@@ -59,6 +72,10 @@
         'get_provides',
         ]
 
+    allowed_in_global = [
+        'debug',
+        ]
+
     allowed_in_backend = [
         'server',
         'architectures',
@@ -82,12 +99,18 @@
 
 	# Read the global section.
         self['GLOBAL'] = {}
+        global_items = self.allowed_in_global + self.required_in_global
         for item, value in conf.items('GLOBAL'):
-            if item not in self.required_in_global:
+            if item not in global_items:
                 debug("[%s] is not allowed in global section." % (item))
                 raise InvalidOption('GLOBAL', item)
             self['GLOBAL'][item] = value
 
+        for item in self.required_in_global:
+            if not self['GLOBAL'].has_key(item):
+                debug("Required option [%s] not found in global section." % (item))
+                raise RequiredOptionMissing('GLOBAL', item)
+
 	for section in conf.sections():
             if section == 'GLOBAL': continue
 	    self[section] = {}