- def load(self, config_file):
- try:
- execfile(config_file, self.__dict__)
- self.config_file = config_file
- self.config_path = os.path.dirname(config_file)
- except IOError, e:
- raise IOError, "Could not find the configuration file: %s" % config_file
+ def load(self, filename):
+ if filename:
+ if filename.endswith('.xml'):
+ try:
+ self.load_xml(filename)
+ except:
+ raise
+ self.config.read(filename)
+ else:
+ self.config.read(filename)
+ self.set_attributes()
+
+ def load_xml(self, filename):
+ xml = XML(filename)
+ categories = xml.xpath('//configuration/variables/category')
+ for category in categories:
+ section_name = category.get('id')
+ if not self.config.has_section(section_name):
+ self.config.add_section(section_name)
+ options = category.xpath('./variablelist/variable')
+ for option in options:
+ option_name = option.get('id')
+ value = option.xpath('./value')[0].text
+ if not value:
+ value = ""
+ self.config.set(section_name, option_name, value)
+