Beispiel #1
0
 def deptree(self, owner, cube, field, oids, date, level):
     self.cube_exists(owner, cube)
     self.requires_owner_read(owner, cube)
     if level and level <= 0:
         self._raise(400, 'level must be >= 1')
     oids = self.parse_oids(oids)
     checked = set(oids)
     fringe = oids
     loop_k = 0
     pql_date = date_pql_string(date)
     while len(fringe) > 0:
         if level and loop_k == abs(level):
             break
         spec = pql.find(
             '_oid in %s and %s != None and %s' % (fringe, field, pql_date))
         _cube = self.timeline(owner, cube)
         fields = {'_id': -1, '_oid': 1, field: 1}
         docs = _cube.find(spec, fields=fields)
         fringe = set([oid for doc in docs for oid in doc[field]])
         fringe = filter(lambda oid: oid not in checked, fringe)
         checked |= set(fringe)
         loop_k += 1
     return sorted(checked)
Beispiel #2
0
    def deptree(self, owner, cube, field, oids, date, level):
        '''
        Dependency tree builder. Recursively fetchs objects that
        are children of the initial set of parent object ids provided.

        :param cube: cube name
        :param owner: username of cube owner
        :param field: Field that contains the 'parent of' data
        :param oids: Object oids to build depedency tree for
        :param date: date (metrique date range) that should be queried.
                    If date==None then the most recent versions of the
                    objects will be queried.
        :param level: limit depth of recursion
        '''
        self.requires_read(owner, cube)
        if level and level <= 0:
            self._raise(400, 'level must be >= 1')
        if isinstance(oids, basestring):
            oids = [s.strip() for s in oids.split(',')]
        checked = set(oids)
        fringe = oids
        loop_k = 0
        pql_date = date_pql_string(date)
        while len(fringe) > 0:
            if level and loop_k == abs(level):
                break
            spec = pql.find(
                '_oid in %s and %s != None and %s' % (fringe, field, pql_date))
            _cube = self.timeline(owner, cube)
            fields = {'_id': -1, '_oid': 1, field: 1}
            docs = _cube.find(spec, fields=fields)
            fringe = set([oid for doc in docs for oid in doc[field]])
            fringe = filter(lambda oid: oid not in checked, fringe)
            checked |= set(fringe)
            loop_k += 1
        return sorted(checked)