def initialize(self, args = []): # process args configParser = ConfigParser.ConfigParser() setattr(configParser, 'optionxform' , str) if len(args) > 2: for arg in args[2:]: configPair = arg.strip().split('=') if len(configPair) == 2: key = configPair[0].strip() val = configPair[1].strip() if len(key) > 2 and key[0] == '-' and key[1] == '-': key = key[2:] keyPair = key.strip().split('.') if len(keyPair) == 2: section = keyPair[0].strip() option = keyPair[1].strip() if not configParser.has_section(section): configParser.add_section(section) configParser.set(section, option, val) else: print "no key-pair: %s" % (keyPair) else: print "no config-pair: %s" % (configPair) # check op if len(args[1]) > 0 and args[1][0] == '_': raise Exception, "Error: illegal op: %s" % args[1] # default self.setConfig(defaultConfig()) # load config if configParser.has_option('file', 'cfg'): self.setConfig(self.loadConfig(configParser.get('file', 'cfg'))) # override with arg-conf self.setConfig(configParser) # check config self.checkConfig()
def defaultConfigAsArgString(self): return self.configAsArgString(defaultConfig())