def __call__(self, id): """ Retrieve a job by id. """ this_id = id t = type(this_id) if t is int: try: return _wrap(self.objects[this_id]) except KeyError: if self.name == 'templates': raise RegistryKeyError('Template %d not found' % this_id) else: raise RegistryKeyError('Job %d not found' % this_id) elif t is tuple: ids = this_id elif t is str: if this_id.isdigit(): try: return _wrap(self.objects[int(this_id)]) except KeyError: if self.name == 'templates': raise RegistryKeyError('Template %d not found' % this_id) else: raise RegistryKeyError('Job %d not found' % this_id) elif this_id.count('.') == 1 and id.split('.')[0].isdigit() and this_id.split('.')[1].isdigit(): ids = this_id.split(".") else: import fnmatch jlist = [j for j in self.objects if fnmatch.fnmatch(j.name, this_id)] if len(jlist) == 1: return _wrap(jlist[0]) return jobSlice(jlist) else: raise RegistryAccessError('Expected a job id: int, (int,int), or "int.int"') if not len(ids) in [1, 2]: raise RegistryAccessError('Too many ids in the access tuple, 2-tuple (job,subjob) only supported') try: ids = [int(this_id) for this_id in ids] except TypeError: raise RegistryAccessError('Expeted a job id: int, (int,int), or "int.int"') except ValueError: raise RegistryAccessError('Expected a job id: int, (int,int), or "int.int"') try: j = self.objects[ids[0]] except KeyError: if self.name == 'templates': raise RegistryKeyError('Template %d not found' % ids[0]) else: raise RegistryKeyError('Job %d not found' % ids[0]) if len(ids) > 1: try: return _wrap(j.subjobs[ids[1]]) except IndexError: raise RegistryKeyError('Subjob %s not found' % ('.'.join([str(_id) for _id in ids]))) else: return _wrap(j)
def __getitem__(self, x): """Retrieve the job object from the registry: registry[x]. If 'x' is a job id (int) then a single job object is returned or IndexError. If 'x' is a name (string) then a unique same name is returned, otherwise []. If 'x' is a job object then it is returned if it belongs to the registry, otherwise None. If 'x' is not of any of the types above, raise TypeError. or by name. If retrieved by name then the job must be unique, otherwise the RegistryKeyError is raised. If the input is incorrect, RegistryAccessError is raised. """ if isinstance(x, int): try: return addProxy(self.objects[x]) except IndexError: raise RegistryIndexError('list index out of range') if isinstance(x, str): ids = [] for i in self.objects.keys(): j = self.objects[i] if j.name == x: ids.append(j.id) if len(ids) > 1: raise RegistryKeyError('object "%s" not unique' % x) if len(ids) == 0: raise RegistryKeyError('object "%s" not found' % x) return addProxy(self.objects[ids[0]]) raise RegistryAccessError('Expected int or string (job name).')
def __call__(self, id): """ Retrieve a job by id. """ t = type(id) if t is int: try: return self.objects[id] except KeyError: raise RegistryKeyError('Task id=%d not found' % id) elif t is tuple: ids = id elif t is list: ids = id.split(".") else: raise RegistryAccessError( 'Expected a job id: int, (int,int), or "int.int"') if not len(ids) in [1, 2]: raise RegistryAccessError( 'Too many ids in the access tuple, 2-tuple (job,subjob) only supported' ) try: ids = [int(id) for id in ids] except TypeError: raise RegistryAccessError( 'Expeted a job id: int, (int,int), or "int.int"') except ValueError: raise RegistryAccessError( 'Expected a job id: int, (int,int), or "int.int"') try: j = self.objects[ids[0]] except KeyError: raise RegistryKeyError('Task %d not found' % ids[0]) if len(ids) > 1: try: return j.transforms[ids[1]] except IndexError: raise RegistryKeyError('Transform %s not found' % ('.'.join([str(id) for id in ids]))) else: return j