Exemple #1
0
    def loadChange(self, objid, revision, deleted):
        try:
            obj = self.mapper_manager.find(objid)
            change = change_factory.create(obj, revision, deleted)

            if change.getChangeType() == CHANGETYPE.DELETE:
                # object deleted
                if isinstance(change, ChangeModelObject):
                    obj_parent = obj.getParent()
                    if obj_parent:
                        obj_parent.deleteChild(obj.getID())
                self.mapper_manager.remove(objid)
            elif change.getChangeType() == CHANGETYPE.UPDATE:
                # object edited
                self.mapper_manager.reload(objid)
            elif change.getChangeType() == CHANGETYPE.ADD:
                if isinstance(change, ChangeModelObject):
                    # The child has a parent, but the parent doesn't
                    # have the child yet...
                    if obj.getParent():
                        obj.getParent().addChild(obj)

            if isinstance(change, ChangeModelObject):
                self._notify_model_object_change(change, obj)
            model.guiapi.notification_center.changeFromInstance(change)
        except:
            getLogger(self).debug("Change couldn't be processed")
Exemple #2
0
    def loadChange(self, objid, revision, deleted):
        try:
            obj = self.mapper_manager.find(objid)
            change = change_factory.create(obj, revision, deleted)

            if change.getChangeType() == CHANGETYPE.DELETE:
                # object deleted
                if isinstance(change, ChangeModelObject):
                    obj_parent = obj.getParent()
                    if obj_parent:
                        obj_parent.deleteChild(obj.getID())
                self.mapper_manager.remove(objid)
            elif change.getChangeType() == CHANGETYPE.UPDATE:
                # object edited
                self.mapper_manager.reload(objid)
            elif change.getChangeType() == CHANGETYPE.ADD:
                if isinstance(change, ChangeModelObject):
                    # The child has a parent, but the parent doesn't
                    # have the child yet...
                    if obj.getParent():
                        obj.getParent().addChild(obj)

            if isinstance(change, ChangeModelObject):
                self._notify_model_object_change(change, obj)
            model.guiapi.notification_center.changeFromInstance(change)
        except:
            getLogger(self).debug(
                "Change couldn't be processed")
Exemple #3
0
 def waitForDBChange(self, db_name, since=0, timeout=15000):
     """ Be warned this will return after the database has a change, if
     there was one before call it will return immediatly with the changes
     done"""
     changes = []
     last_seq = max(self.getLastChangeSeq(db_name), since)
     db = self._getDb(db_name)
     with ChangesStream(db,
                        feed="longpoll",
                        since=last_seq,
                        timeout=timeout) as stream:
         for change in stream:
             if change['seq'] > self.getLastChangeSeq(db_name):
                 self.setLastChangeSeq(db_name, change['seq'])
                 if not change['id'].startswith('_design'):
                     #fake doc type for deleted objects
                     doc = {
                         'type': 'unknown',
                         '_deleted': 'False',
                         '_rev': [0]
                     }
                     if not change.get('deleted'):
                         doc = self.getDocument(db_name, change['id'])
                     changes.append(change_factory.create(doc))
     if len(changes):
         getLogger(self).debug("Changes from another instance")
     return changes
Exemple #4
0
 def waitForDBChange(self, db_name, since = 0, timeout = 15000):
     """ Be warned this will return after the database has a change, if
     there was one before call it will return immediatly with the changes
     done"""
     changes = []
     last_seq = max(self.getLastChangeSeq(db_name), since)
     db = self._getDb(db_name)
     with ChangesStream(db, feed="longpoll", since=last_seq, timeout=timeout) as stream:
         for change in stream:
             if change['seq'] > self.getLastChangeSeq(db_name):
                 self.setLastChangeSeq(db_name, change['seq'])
                 if not change['id'].startswith('_design'):
                     #fake doc type for deleted objects
                     doc = {'type': 'unknown', '_deleted': 'False', '_rev':[0]}
                     if not change.get('deleted'):
                         doc = self.getDocument(db_name, change['id'])
                     changes.append(change_factory.create(doc))
     if len(changes):
         getLogger(self).debug("Changes from another instance")
     return changes