def createConfigFile(): configuration = classes.configObject() outputFile = open("ucambuilder_auto.conf", 'w') lineString = "# This file has been automatically genereated by 'ultracamutils.py'.\n" outputFile.write(lineString) attributes = [a for a in dir(configuration) if not a.startswith('__') and not callable(getattr(configuration,a))] print attributes for key in attributes: lineString = str(key) + "\t" + str(configuration[key]) + "\n" outputFile.write(lineString) outputFile.close()
def readConfigFile(filename): """ Reads the config file name ucambuilder.conf and returns a configObject """ configuration = classes.configObject() try: configfile = open(filename, "r") except IOError: print "Warning: Cannot find the config file %s ... will use default values"%filename return configuration for line in configfile: if(line[0]!="#"): # Ignore lines that are comments if len(line.split())>=2: option = line.split()[0] value = line.split()[1] configuration[option] = value configfile.close() return configuration