Exemple #1
0
 def unset(self, *names):
     if names:
         result = self.store.driver.ctx_remove(
             self.store.session, query._and(query.address(self.id), query.attribute(*names))
         )
     else:
         result = self.store.driver.ctx_remove(self.store.session, query._and(query.address(self.id)))
     return result
Exemple #2
0
 def unset(self, *names):
     if names:
         result = self.store.driver.ctx_remove(
             self.store.session,
             query._and(query.address(self.id), query.attribute(*names)))
     else:
         result = self.store.driver.ctx_remove(
             self.store.session, query._and(query.address(self.id)))
     return result
Exemple #3
0
 def get(self, *names):
     if names:
         result = self.store.driver.con_select(
             self.store.session,
             query._and(query.context(self.context.id), query.address(self.id), query.attribute(*names)),
         )
     else:
         result = self.store.driver.con_select(
             self.store.session, query._and(query.context(self.context.id), query.address(self.id))
         )
     return result[self.id]
Exemple #4
0
 def get(self, *names):
     if names:
         result = self.store.driver.con_select(
             self.store.session,
             query._and(query.context(self.context.id),
                        query.address(self.id), query.attribute(*names)))
     else:
         result = self.store.driver.con_select(
             self.store.session,
             query._and(query.context(self.context.id),
                        query.address(self.id)))
     return result[self.id]
Exemple #5
0
 def select(self, *q):
     '''return a subview with the given query on a function's context'''
     result = type(self)(self.store, self.watch)
     if self.node:
         nodes = tuple(k for k in self.node.iterkeys())
         result.extend(query.address(*nodes))
     return result
Exemple #6
0
 def iterkeys(self):
     return self.store.driver.con_select(
         self.store.session,
         query._and(query.context(self.context.id),
                    query.address(self.id)))[self.id].iterkeys()
Exemple #7
0
 def iterkeys(self):
     return self.store.driver.ctx_select(self.store.session,
                                         query.address(
                                             self.id))[self.id].iterkeys()
Exemple #8
0
 def iterkeys(self):
     return self.store.driver.con_select(
         self.store.session, query._and(query.context(self.context.id), query.address(self.id))
     )[self.id].iterkeys()
Exemple #9
0
 def iterkeys(self):
     return self.store.driver.ctx_select(self.store.session, query.address(self.id))[self.id].iterkeys()
Exemple #10
0
    def update(self):
        ''' call this every once in a while '''
        # context
        if not self.watch:
            logging.info('refusing to update due to an empty tag list')
            return {}

        # query all contexts and update nodes
        result = {}
        for k,v in self.store.select(query.newer(self.__age),query.attribute(*self.watch),query.address(*self.node.keys())).iteritems():
            if not v:
                continue
            self.node[k].update(v)
            result[k] = v

        # execute callback for all nodes
        for address,updates in result.iteritems():
            node = self.node[address]
            if self.trigger.execute(node.id, node, updates):
                logging.warning('callback for %x returned non-zero value')
            continue

        completed = set(result.keys())

        # now for content
        for address in self.node:
            result = self.store.select_content(query.newer(self.__age),query.attribute(*self.watch),query.context(address))

            node = self.node[address]
            names = set()

            # collect names for updates
            for ea,d in result.iteritems():
                names.update(d.keys())

            # callbacks for content
            for n in names:
                r = ((ea,d[n]) for ea,d in result.iteritems() if n in d)
                self.trigger.execute((node.id,n), (node,n), dict(r))

            node.content.update(result)

        self.__age = datetime.now()
        return completed