def __init__(self, **kwargs): """Creates a new instance of ConfigReader.""" self._configs = ArgsUtils.get('configs', dict(), kwargs) self._filenames = ArgsUtils.get('filenames', None, kwargs) self._configPath = ArgsUtils.get( 'rootConfigPath', CadenceEnvironment.getConfigPath(), kwargs ) if self._filenames: for n,v in self._filenames.iteritems(): if not v: continue path = os.path.join(self._configPath, v) if not path.endswith('.cfg'): path += '.cfg' parser = ConfigParser.ConfigParser() if os.path.exists(path): parser.read(path) else: raise Exception, path + ' config file does not exist!' self._configs[n] = self._configParserToDict(parser) self._overrides = dict() self.setOverrides(ArgsUtils.get('overrides', None, kwargs))
import os import sys import random from cadence.CadenceEnvironment import CadenceEnvironment from cadence.config.ConfigReader import ConfigReader from cadence.generator.gait.GaitGenerator import GaitGenerator from cadence.shared.io.CadenceData import CadenceData #--------------------------------------------------------------------------------------------------- # GET CONFIG FILE configPath = CadenceEnvironment.getConfigPath('gait') cfgs = [] for f in os.listdir(configPath): path = os.path.join(configPath, f) if not os.path.isfile(path) or not f.endswith(ConfigReader.EXTENSION): continue cfgs.append(os.path.join('gait', f)) configFile = str(cfgs[random.randint(0,len(cfgs) - 1)]) print 'INITIALIZING Config file: ' + configFile #--------------------------------------------------------------------------------------------------- # GET CONFIG FILE g = GaitGenerator(gaitConfig=configFile) if g.run(): print 'SUCCESS: GaitGenerator.run()' g.echo() else: print 'FAILED: GaitGenerator.run()' sys.exit(1)