r159 - branches/rewrite/src
Otavio Salvador
partial-mirror-devel@lists.alioth.debian.org
Sun, 04 Jul 2004 13:49:34 -0600
Author: otavio
Date: Sun Jul 4 13:49:34 2004
New Revision: 159
Modified:
branches/rewrite/src/Config.py
Log:
Initial working to get right types of options.
Modified: branches/rewrite/src/Config.py
==============================================================================
--- branches/rewrite/src/Config.py (original)
+++ branches/rewrite/src/Config.py Sun Jul 4 13:49:34 2004
@@ -97,6 +97,19 @@
'name',
]
+ # if not included here, it's string
+ options_with_type = {
+ 'architectures': 'list',
+ 'backends': 'list',
+ 'distributions': 'list',
+ 'filter': 'dict',
+ 'filter_@BACKEND@': 'dict',
+ 'get_provides': 'boolean',
+ 'get_recommends': 'boolean',
+ 'get_suggests': 'boolean',
+ 'sections': 'list',
+ }
+
def __init__(self, filename):
ConfigParser.__init__(self)
self.read(filename)
@@ -163,15 +176,35 @@
debug("no config section called [%s]." % (section))
raise InvalidSection(section)
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.confs['GLOBAL'][option]
+ conf = self.confs[section][option]
+ else:
+ if section != 'GLOBAL':
+ debug("[%s] is not present in section [%s]. Fallback to global section." % (option, section))
+ try:
+ self.getOption(option, 'GLOBAL')
+ except InvalidOption, msg:
+ debug("[%s] is not present in section [%s]." % (option, section))
+ raise InvalidOption(section, msg.option)
+ except InvalidSection, msg:
+ raise InvalidSection(msg.section)
+ else:
+ debug("[%s] is not present in section [%s]." % (option, section))
+ raise InvalidOption(section, option)
+
+ if option in self.options_with_type:
+ if self.options_with_type[option] == 'list':
+ return conf.split()
+ elif self.options_with_type[option] == 'boolean':
+ return bool(conf)
+# elif self.options_with_type[option] == 'dict':
+# return map(conf.split())
+ else:
+ return conf
+
def dump(self):
for section, options in self.confs.items():
- print section
+ print '\n' + section
for item, value in options.items():
- print " %s = %s" %(item, value)
+ print " %s = %s" %(item, self.getOption(item, section))