Beispiel #1
0
 def setUp(self):
     self._mpt = SetMultiPointerTrack()
     self._a = DummyType(1 + 2)
     self._b = DummyType(2 + 2)
     self._c = DummyType(1 + 2)
     self._d = DummyType(1 + 1)
     self._e = DummyType(2 + 1)
     self._f = DummyType(3 + 4)
Beispiel #2
0
    def reset(self, agentsOnly=False, trackOnly=False):
        """
        Resets database structures

        .. WARNING::
           This erases any agents and contents in the MPT
        """
        if not trackOnly:
            self._agents = mapping.PersistentMapping()
        if not agentsOnly:
            self._track = SetMultiPointerTrack()
Beispiel #3
0
 def setUp(self):
     self._mpt = SetMultiPointerTrack()
     self._a = DummyType(1  + 2)
     self._b = DummyType(2  + 2)
     self._c = DummyType(1  + 2)
     self._d = DummyType(1  + 1)
     self._e = DummyType(2  + 1)
     self._f = DummyType(3  + 4)
Beispiel #4
0
    def reset(self, agentsOnly=False, trackOnly=False):
        """
        Resets database structures

        .. WARNING::
           This erases any agents and contents in the MPT
        """
        if not trackOnly:
            self._agents = mapping.PersistentMapping()
        if not agentsOnly:
            self._track = SetMultiPointerTrack()
Beispiel #5
0
    def setUp(self):

        from ZODB import DB
        db = DB(TestMemStorage('test'))

        self._tm1 = transaction.TransactionManager()
        self._tm2 = transaction.TransactionManager()

        self._c1 = db.open(transaction_manager=self._tm1)

        self._r1 = self._c1.root()
        self._qmpt1 = self._r1["queue"] = SetMultiPointerTrack()
        self._tm1.commit()

        self._c2 = db.open(transaction_manager=self._tm2)
        self._r2 = self._c2.root()
        self._qmpt2 = self._r2["queue"]

        self._a = DummyType(1)
        self._b = DummyType(2)
        self._c = DummyType(3)
Beispiel #6
0
class SyncManager(Persistent):
    """
    Stores live sync configuration parameters and "agents". It is  basically an
    "Agent Manager"
    """
    def __init__(self, granularity=MPT_GRANULARITY):
        """
        :param granularity: integer, number of seconds per MPT entry
        """
        self._granularity = granularity
        self.reset()

    def getGranularity(self):
        """
        Returns the granularity that is set for the MPT
        """
        return self._granularity

    @classmethod
    def getDBInstance(cls):
        """
        Returns the instance of SyncManager currently in the DB
        """
        storage = getPluginType().getStorage()
        if 'agent_manager' in storage:
            return storage['agent_manager']
        else:
            root = DBMgr.getInstance().getDBConnection()
            updateDBStructures(root)

    def reset(self, agentsOnly=False, trackOnly=False):
        """
        Resets database structures

        .. WARNING::
           This erases any agents and contents in the MPT
        """
        if not trackOnly:
            self._agents = mapping.PersistentMapping()
        if not agentsOnly:
            self._track = SetMultiPointerTrack()

    def registerNewAgent(self, agent):
        """
        Registers the agent, placing it in a mapping structure
        """
        self._agents[agent.getId()] = agent

        # create a new pointer in the track
        self._track.addPointer(agent.getId())

        # impose myself as its manager
        agent.setManager(self)

    def removeAgent(self, agent):
        """
        Removes an agent
        """
        self._track.removePointer(agent.getId())
        del self._agents[agent.getId()]

    def query(self, agentId=None, till=None):
        """
        Queries the agent for a given timespan
        """

        # TODO: Add more criteria! (for now this will do)

        if agentId == None:
            raise QueryException("No criteria specified!")

        return self._track.pointerIterItems(agentId, till=till)

    def advance(self, agentId, newLastTS):
        """
        Advances the agent "pointer" to the specified timestamp
        """
        self._track.movePointer(agentId, newLastTS)

    def add(self, timestamp, action):
        """
        Adds a specific action to the specified timestamp
        """
        self._track.add(timestamp / self._granularity, action)

    def getTrack(self):
        """
        Rerturns the MPT
        """
        return self._track

    def getAllAgents(self):
        """
        Returns the agent dictionary
        """
        return self._agents

    def objectExcluded(self, obj):
        """
        Decides whether a particular object should be ignored or not
        """
        excluded = getPluginType().getOption('excludedCategories').getValue()

        if isinstance(obj, conference.SessionSlot):
            return True
        elif isinstance(obj, conference.Category):
            return obj.getId() in excluded
        elif isinstance(obj, conference.Conference):
            owner = obj.getOwner()
            if owner:
                return owner.getId() in excluded
        elif obj.getParent():
            conf = obj.getConference()
            if conf:
                owner = conf.getOwner()
                if owner:
                    return owner.getId() in excluded

        return False
Beispiel #7
0
class SyncManager(Persistent):
    """
    Stores live sync configuration parameters and "agents". It is  basically an
    "Agent Manager"
    """

    def __init__(self, granularity=MPT_GRANULARITY):
        """
        :param granularity: integer, number of seconds per MPT entry
        """
        self._granularity = granularity
        self.reset()

    def getGranularity(self):
        """
        Returns the granularity that is set for the MPT
        """
        return self._granularity

    @classmethod
    def getDBInstance(cls):
        """
        Returns the instance of SyncManager currently in the DB
        """
        storage = getPluginType().getStorage()
        if 'agent_manager' in storage:
            return storage['agent_manager']
        else:
            root = DBMgr.getInstance().getDBConnection()
            updateDBStructures(root)

    def reset(self, agentsOnly=False, trackOnly=False):
        """
        Resets database structures

        .. WARNING::
           This erases any agents and contents in the MPT
        """
        if not trackOnly:
            self._agents = mapping.PersistentMapping()
        if not agentsOnly:
            self._track = SetMultiPointerTrack()

    def registerNewAgent(self, agent):
        """
        Registers the agent, placing it in a mapping structure
        """
        self._agents[agent.getId()] = agent

        # create a new pointer in the track
        self._track.addPointer(agent.getId())

        # impose myself as its manager
        agent.setManager(self)

    def removeAgent(self, agent):
        """
        Removes an agent
        """
        self._track.removePointer(agent.getId())
        del self._agents[agent.getId()]

    def query(self, agentId=None, till=None):
        """
        Queries the agent for a given timespan
        """

        # TODO: Add more criteria! (for now this will do)

        if agentId == None:
            raise QueryException("No criteria specified!")

        return self._track.pointerIterItems(agentId, till=till)

    def advance(self, agentId, newLastTS):
        """
        Advances the agent "pointer" to the specified timestamp
        """
        self._track.movePointer(agentId,
                                newLastTS)

    def add(self, timestamp, action):
        """
        Adds a specific action to the specified timestamp
        """
        self._track.add(timestamp / self._granularity, action)

    def getTrack(self):
        """
        Rerturns the MPT
        """
        return self._track

    def getAllAgents(self):
        """
        Returns the agent dictionary
        """
        return self._agents

    def objectExcluded(self, obj):
        """
        Decides whether a particular object should be ignored or not
        """
        excluded = getPluginType().getOption('excludedCategories').getValue()
        if isinstance(obj, conference.Category):
            return obj.getId() in excluded
        elif isinstance(obj, conference.Conference):
            owner = obj.getOwner()
            if owner:
                return owner.getId() in excluded
        elif obj.getParent():
            conf = obj.getConference()
            if conf:
                owner = conf.getOwner()
                if owner:
                    return owner.getId() in excluded

        return False
Beispiel #8
0
class TestSetMultiPointerTrack(IndicoTestCase):

    def _val(self, iter):
        return list(e._value for e in iter)

    def setUp(self):
        super(TestSetMultiPointerTrack, self).setUp()
        self._mpt = SetMultiPointerTrack()
        self._a = DummyType(1  + 2)
        self._b = DummyType(2  + 2)
        self._c = DummyType(1  + 2)
        self._d = DummyType(1  + 1)
        self._e = DummyType(2  + 1)
        self._f = DummyType(3  + 4)

    def _addSome(self):
        self._mpt.add(1, self._a)
        self._mpt.add(2, self._b)
        self._mpt.add(1, self._c)
        self._mpt.add(1, self._d)
        self._mpt.add(2, self._e)
        self._mpt.add(3, self._f)

    def testOrdering(self):
        self._addSome()

        self.assertEqual(
            list(e._value for ts, e in self._mpt),
            [7, 3, 4, 2, 3, 3])

    def testPointerIterator(self):
        self._addSome()

        self._mpt.addPointer("foo")
        self._mpt.addPointer("bar", 2)

        self.assertEqual(self._val(self._mpt.pointerIterValues("foo")),
                         [7, 3, 4, 2, 3, 3])

        self.assertEqual(self._val(self._mpt.pointerIterValues("bar")),
                         [7])

    def testPointerIteratorTill(self):
        """
        Iterate till a certain timestamp
        """
        self._addSome()

        self._mpt.addPointer("foo")

        self.assertEqual(self._val(self._mpt.pointerIterValues("foo", till=2 )),
                         [3, 4, 2, 3, 3])