r158 - branches/rewrite/src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Sat, 03 Jul 2004 20:49:25 -0600


Author: otavio
Date: Sat Jul  3 20:49:25 2004
New Revision: 158

Modified:
   branches/rewrite/src/Config.py
Log:
Convert to ihenrits from ConfigParser.

Modified: branches/rewrite/src/Config.py
==============================================================================
--- branches/rewrite/src/Config.py	(original)
+++ branches/rewrite/src/Config.py	Sat Jul  3 20:49:25 2004
@@ -57,7 +57,7 @@
     def __init__(self, section):
         self.section = section
 
-class Config(dict):
+class Config(ConfigParser):
     """
     Store the configurations used by our system.
     """
@@ -98,38 +98,39 @@
         ]
 
     def __init__(self, filename):
-        conf = ConfigParser()
-        conf.read(filename)
+        ConfigParser.__init__(self)
+        self.read(filename)
 
 	# Read the global section.
-        self['GLOBAL'] = {}
+        self.confs = {}
+        self.confs['GLOBAL'] = {}
         global_items = self.allowed_in_global + self.required_in_global
-        for item, value in conf.items('GLOBAL'):
+        for item, value in self.items('GLOBAL'):
             if item not in global_items:
                 debug("[%s] is not allowed in global section." % (item))
                 raise InvalidOption('GLOBAL', item)
-            self['GLOBAL'][item] = value
+            self.confs['GLOBAL'][item] = value
 
         for item in self.required_in_global:
-            if not self['GLOBAL'].has_key(item):
+            if not self.confs['GLOBAL'].has_key(item):
                 debug("Required option [%s] not found in global section." % (item))
                 raise RequiredOptionMissing('GLOBAL', item)
 
-	for section in conf.sections():
+	for section in self.sections():
             if section == 'GLOBAL': continue
-	    self[section] = {}
+	    self.confs[section] = {}
 
             ###HACK.  Split this out later into subclasses.
             # detect which config type this is
-            if 'backends' in conf.options(section):
+            if 'backends' in self.options(section):
                 allowed_in_section = self.allowed_in_merge_backend
-            elif 'server' in conf.options(section):
+            elif 'server' in self.options(section):
                 allowed_in_section = self.allowed_in_mirror_backend
             else:
                 debug("Unknown section type in section [%s]." % (section))
                 raise InvalidSection(section)
             
-	    for item, value in conf.items(section):
+	    for item, value in self.items(section):
 		if item not in allowed_in_section:
 		    for allowed_key in allowed_in_section:
 			# check the allowed_in_backend keys with
@@ -143,7 +144,7 @@
                                 variable = allowed_key[left_length:right_length]
                                 match = item[left_length:len(item)-(len(allowed_key)-right_length)]
                                 if variable == '@BACKEND@':
-                                    if match in conf.sections():
+                                    if match in self.sections():
                                         break
                                 else:
                                     print("You found a bug: [%s] matches unknown variable [%s]! "
@@ -153,23 +154,23 @@
 			debug("[%s] is not allowed in a backend section (it was found in [%s])."
                               % (item, section))
                         raise InvalidOption(section, item)
-		self[section][item] = value
+		self.confs[section][item] = value
 
     def getOption(self, option, section='GLOBAL'):
 	# get a config value for a certain section.  if it's not
 	# specified, fall back to GLOBAL
-	if not self.has_key(section):
+	if not self.confs.has_key(section):
 	    debug("no config section called [%s]." % (section))
 	    raise InvalidSection(section)
-	if self[section].has_key(option):
-	    return self[section][option]
-	if not self['GLOBAL'].has_key(option):
+	if self.confs[section].has_key(option):
+	    return self.confs[section][option]
+	if not self.confs['GLOBAL'].has_key(option):
 	    debug("[%s] is not present in section [%s] nor the global section of config file." % (option, section))
 	    raise InvalidOption(section, option)
-	return self['GLOBAL'][option]
+	return self.confs['GLOBAL'][option]
 
     def dump(self):
-        for section, options in self.items():
+        for section, options in self.confs.items():
             print section
             for item, value in options.items():
                 print "  %s = %s" %(item, value)