def loaddriver(): """Create new driver based on Robot configuration options. Example of relevant configuration options: [Robot] Driver_Run = ['submit', 30, 'extract', 'report'] Driver_Repeat = False Driver_Action_submit = GangaRobot.Lib.Core.CoreSubmitter.CoreSubmitter Driver_Action_extract = GangaRobot.Lib.Core.CoreExtractor.CoreExtractor Driver_Action_report = GangaRobot.Lib.Core.CoreReporter.CoreReporter """ KEY_RUN = 'Driver_Run' KEY_REPEAT = 'Driver_Repeat' KEY_ACTION_PREFIX = 'Driver_Action_' config = Utility.getconfig() run = config[KEY_RUN] repeat = config[KEY_REPEAT] actions = {} #load action classes for key in config: if key.startswith(KEY_ACTION_PREFIX): action = key[len(KEY_ACTION_PREFIX):] fqcn = config[key] try: actions[action] = _loadclass(fqcn) except Exception as e: raise ApplicationConfigurationError( "Cannot load class '%s'. Exception: '%s'" % (fqcn, e)) #check actions exist for run for action in run: if not action in actions: try: int(action) except ValueError as e: raise ApplicationConfigurationError( "Unknown action '%s'. Exception: '%s'" % (action, e)) return Driver(run=run, actions=actions, repeat=repeat)
def loaddriver(): """Create new driver based on Robot configuration options. Example of relevant configuration options: [Robot] Driver_Run = ['submit', 30, 'extract', 'report'] Driver_Repeat = False Driver_Action_submit = GangaRobot.Lib.Core.CoreSubmitter.CoreSubmitter Driver_Action_extract = GangaRobot.Lib.Core.CoreExtractor.CoreExtractor Driver_Action_report = GangaRobot.Lib.Core.CoreReporter.CoreReporter """ KEY_RUN = 'Driver_Run' KEY_REPEAT = 'Driver_Repeat' KEY_ACTION_PREFIX = 'Driver_Action_' config = Utility.getconfig() run = config[KEY_RUN] repeat = config[KEY_REPEAT] actions = {} #load action classes for key in config: if key.startswith(KEY_ACTION_PREFIX): action = key[len(KEY_ACTION_PREFIX):] fqcn = config[key] try: actions[action] = _loadclass(fqcn) except Exception as e: raise ApplicationConfigurationError(e, "Cannot load class '%s'." % fqcn) #check actions exist for run for action in run: if not action in actions: try: int(action) except ValueError as e: raise ApplicationConfigurationError(e, "Unknown action '%s'." % action) return Driver(run = run, actions = actions, repeat = repeat)
def getoption(self, key): """Return the configuration option value. If the instance has an attribute 'options' containing the given key, then the corresponding value is returned, otherwise the value is retrieved from the [Robot] section of the global configuration. This provides a single point of access to configuration options and allows users the possibility to override options programmatically for a given instance. Example: c = CoreFinisher() c.options = {'BaseFinisher_Timeout':3600} """ if hasattr(self, 'options') and key in self.options: return self.options[key] else: try: return Utility.getconfig()[key] except ConfigError: return ''