def _load_configuration(self): if self._config_exists: # If read ok read_result = self._config.read(self._filepath) if len(read_result) > 0 and os.path.basename(read_result[0]) == self._filename: # Populate the classes with the appropriate values for section in self._config.sections(): #print "Reading Config Section: " + section for option in self._config.options(section): value_type = "str" # If the section has been defined in the default settings if Settings.has_section(section): value_type = Settings.get(section, option).__class__.__name__ # Else use a manual technique to figure this out. else: value = self._config.get(section, option) value_type = self._check_type( value ) if value_type == "str": Settings.set(section, option, self._config.get(section, option) ) elif value_type == "int": Settings.set(section, option, self._config.getint(section, option) ) elif value_type == "float": Settings.set(section, option, self._config.getfloat(section, option) ) elif value_type == "bool": Settings.set(section, option, self._config.getboolean(section, option) ) elif value_type == "list": # If the item is a list get it as a string and process it as appropriate # only lists containing homogeneous values are supported list_value = self._config.get(section, option) # If the section has already been defined in the default settings if Settings.has_section(section): #assuming that the list has more than one value... list_type = Settings.get(section, option)[0].__class__.__name__ # Otherwise extract the type else: #Extract the first list element # Default to a single element list list_element = list_value[1:-1] #Check for more and adjust as necessary if list_value.find(',') > 0: list_element = list_value[1:list_value.find(',')] # Get the element_type list_type = self._check_type( list_element ) # In place of python's lack of a switch statement, defaulting to str if None cast_func = { 'int' : int, 'float' : float, 'bool' : bool, 'str' : str, 'NoneType' : str }[list_type] # Generate a list from the string Settings.set(section, option, [cast_func(value) for value in list_value[1:-1].split(',')] ) value = self._config.get(section, option) # print "Reading property class: %s name: %s value: %s" % ( section, option, str(value) ) # print "Class value class: %s name: %s value: %s valuetype: %s" % ( section, option, str(Settings.get(section, option)), Settings.get(section, option).__class__ ) else: print "Can't find configuration file: %s " % self._filename