def engineList(self, targets): """Parse the targets argument into a list of valid engine objects. :Parameters: targets : int, list of ints or 'all' The targets argument to be parsed. :Returns: List of engine objects. :Exception: InvalidEngineID If targets is not valid or if an engine is not registered. """ if isinstance(targets, int): if targets not in self.engines.keys(): log.msg("Engine with id %i is not registered" % targets) raise error.InvalidEngineID("Engine with id %i is not registered" % targets) else: return [self.engines[targets]] elif isinstance(targets, (list, tuple)): for id in targets: if id not in self.engines.keys(): log.msg("Engine with id %r is not registered" % id) raise error.InvalidEngineID("Engine with id %r is not registered" % id) return map(self.engines.get, targets) elif targets == 'all': eList = self.engines.values() if len(eList) == 0: msg = """There are no engines registered. Check the logs in ~/.ipython/log if you think there should have been.""" raise error.NoEnginesRegistered(msg) else: return eList else: raise error.InvalidEngineID("targets argument is not an int, list of ints or 'all': %r"%targets)
def create_targets(ids): if isinstance(targets, int): engines = [targets] elif targets=='all': engines = ids elif isinstance(targets, (list, tuple)): engines = targets for t in engines: if not t in ids: raise error.InvalidEngineID("engine with id %r does not exist"%t) return engines