示例#1
0
    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).')
示例#2
0
 def __call__(self, id):
     """
     Retrieve an object by id.
     """
     if isinstance(id, str):
         if id.isdigit():
             id = int(id)
         else:
             matches = [
                 o for o in self.objects if fnmatch.fnmatch(o.name, id)]
             if len(matches) > 1:
                 logger.error(
                     'Multiple Matches: Wildcards are allowed for ease of matching, however')
                 logger.error(
                     '                  to keep a uniform response only one item may be matched.')
                 logger.error(
                     '                  If you wanted a slice, please use the select method')
                 raise RegistryKeyError(
                     "Multiple matches for id='%s':%s" % (id, str(map(lambda x: x.name, matches))))
             if len(matches) < 1:
                 return _wrap(TransientRegistrySlice(self.name))
             return matches[0]
     try:
         return self.objects[id]
     except KeyError:
         raise RegistryKeyError('Object id=%d not found' % id)
示例#3
0
    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)
示例#4
0
 def __getitem__(self, id):
     if isinstance(id, str):
         for o in self.objects:
             if o._getRegistry()._getName(o) == id:
                 return o
         raise RegistryKeyError(
             "No object with name '%s' found in the box!" % id)
     else:
         return super(BoxRegistrySlice, self).__getitem__(id)
示例#5
0
    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
示例#6
0
 def __call__(self, this_id):
     """ Retrieve an object by id.
     """
     if isinstance(this_id, str):
         if this_id.isdigit():
             this_id = int(this_id)
         else:
             matches = [
                 o for o in self.objects
                 if fnmatch.fnmatch(o._getRegistry()._getName(o), this_id)
             ]
             if len(matches) > 1:
                 logger.error(
                     'Multiple Matches: Wildcards are allowed for ease of matching, however'
                 )
                 logger.error(
                     '                  to keep a uniform response only one item may be matched.'
                 )
                 logger.error(
                     '                  If you wanted a slice, please use the select method'
                 )
                 raise RegistryKeyError(
                     "Multiple matches for id='%s':%s" %
                     (this_id,
                      str(
                          map(lambda x: x._getRegistry()._getName(x),
                              matches))))
             if len(matches) < 1:
                 return
             return addProxy(matches[0])
     try:
         return addProxy(self.objects[this_id])
     except KeyError as err:
         logger.debug('Object id=%d not found' % this_id)
         logger.deubg("%s" % str(err))
         raise RegistryKeyError('Object id=%d not found' % this_id)