Example #1
0
    def __init__(self, parameters):
        """
        See GenericBackend for an explanation of this function.
        """
        super(GenericTomboy, self).__init__(parameters)
        # loading the saved state of the synchronization, if any
        self.data_path = os.path.join('backends/tomboy/',
                                      "sync_engine-" + self.get_id())
        self.sync_engine = self._load_pickled_file(self.data_path,
                                                   SyncEngine())
        # if the backend is being tested, we connect to a different DBus
        # interface to avoid clashing with a running instance of Tomboy
        if TestingMode().get_testing_mode():
            # just used for testing purposes
            self.BUS_ADDRESS = \
                self._parameters["use this fake connection instead"]
        else:
            self.BUS_ADDRESS = self._BUS_ADDRESS
        # we let some time pass before considering a tomboy task for importing,
        # as the user may still be editing it. Here, we store the Timer objects
        # that will execute after some time after each tomboy signal.
        # NOTE: I'm not sure if this is the case anymore (but it shouldn't hurt
        #      anyway). (invernizzi)
        self._tomboy_setting_timers = {}

        # We need to tell dbus-glib to initialize libdbus' thread locks.
        # Removing this call will result in random segfaults and crashes
        # on enabling GNote and Tomboy (Bug #1264684) - parinporecha
        dbus.mainloop.glib.threads_init()
Example #2
0
 def __init__(self, parameters):
     """
     See GenericBackend for an explanation of this function.
     Re-loads the saved state of the synchronization
     """
     super().__init__(parameters)
     # loading the saved state of the synchronization, if any
     self.data_path = os.path.join('mantis', 'sync_engine-' + self.get_id())
     self.sync_engine = self._load_pickled_file(self.data_path,
                                                SyncEngine())
Example #3
0
 def __init__(self, params):
     """ Constructor of the object """
     super(Backend, self).__init__(params)
     self._sync_tasks = set()
     self._changed_locally = set()
     self._changed_remotely = set()
     # loading the saved state of the synchronization, if any
     self.data_path = os.path.join('backends/gtgonline/',
                                   "sync_engine-" + self.get_id())
     self.sync_engine = self._load_pickled_file(self.data_path,
                                                SyncEngine())
 def __init__(self, parameters):
     '''
     See GenericBackend for an explanation of this function.
     Re-loads the saved state of the synchronization
     '''
     super(Backend, self).__init__(parameters)
     # loading the saved state of the synchronization, if any
     self.data_path = os.path.join('backends/launchpad/',
                                   "sync_engine-" + self.get_id())
     self.sync_engine = self._load_pickled_file(self.data_path,
                                                SyncEngine())
Example #5
0
 def __init__(self, parameters):
     '''
     See GenericBackend for an explanation of this function.
     Loads the saved state of the sync, if any
     '''
     super(Backend, self).__init__(parameters)
     # loading the saved state of the synchronization, if any
     self.sync_engine_path = os.path.join('backends/evolution/',
                                          "sync_engine-" + self.get_id())
     self.sync_engine = self._load_pickled_file(self.sync_engine_path,
                                                SyncEngine())
     # sets up the connection to the evolution api
     task_personal = evolution.ecal.list_task_sources()[0][1]
     self._evolution_tasks = evolution.ecal.open_calendar_source(
         task_personal, evolution.ecal.CAL_SOURCE_TYPE_TODO)
Example #6
0
 def __init__(self, parameters):
     '''
     See GenericBackend for an explanation of this function.
     Loads the saved state of the sync, if any
     '''
     super().__init__(parameters)
     # loading the saved state of the synchronization, if any
     self.sync_engine_path = os.path.join('rtm',
                                          'sync_engine-' + self.get_id())
     self.sync_engine = self._load_pickled_file(self.sync_engine_path,
                                                SyncEngine())
     # reloading the oauth authentication token, if any
     self.token_path = os.path.join('rtm', 'auth_token-' + self.get_id())
     self.token = self._load_pickled_file(self.token_path, None)
     self.enqueued_start_get_task = False
     self.login_event = threading.Event()
     self._this_is_the_first_loop = True
Example #7
0
    def __init__(self, parameters):
        """
        See GenericBackend for an explanation of this function.
        """
        super().__init__(parameters)
        # loading the saved state of the synchronization, if any
        self.data_path = os.path.join('tomboy', 'sync_engine-' + self.get_id())
        self.sync_engine = self._load_pickled_file(self.data_path,
                                                   SyncEngine())
        # we let some time pass before considering a tomboy task for importing,
        # as the user may still be editing it. Here, we store the Timer objects
        # that will execute after some time after each tomboy signal.
        # NOTE: I'm not sure if this is the case anymore (but it shouldn't hurt
        #      anyway). (invernizzi)
        self._tomboy_setting_timers = {}

        # We need to tell dbus-glib to initialize libdbus' thread locks.
        # Removing this call will result in random segfaults and crashes
        # on enabling GNote and Tomboy (Bug #1264684) - parinporecha
        dbus.mainloop.glib.threads_init()
Example #8
0
 def setUp(self):
     self.ftp_local = FakeTaskProvider()
     self.ftp_remote = FakeTaskProvider()
     self.sync_engine = SyncEngine()
Example #9
0
class TestSyncEngine(unittest.TestCase):
    """ Tests for the SyncEngine object. """

    def setUp(self):
        self.ftp_local = FakeTaskProvider()
        self.ftp_remote = FakeTaskProvider()
        self.sync_engine = SyncEngine()

    def test_analyze_element_and_record_and_break_relationship(self):
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id,
        record_relationship, break_relationship """
        # adding a new local task
        has_local_task = self.ftp_local.has_task
        has_remote_task = self.ftp_remote.has_task
        local_id = uuid.uuid4()
        self.ftp_local.fake_add_task(local_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.ADD, None))
        # creating the related remote task
        remote_id = uuid.uuid4()
        self.ftp_remote.fake_add_task(remote_id)
        # informing the sync_engine about that
        self.sync_engine.record_relationship(local_id, remote_id, object())
        # verifying that it understood that
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.UPDATE, remote_id))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task),
                         (SyncEngine.UPDATE, local_id))
        # and not the reverse
        self.assertEqual(self.sync_engine.analyze_remote_id(local_id,
                                                            has_local_task,
                                                            has_remote_task),
                         (SyncEngine.ADD, None))
        self.assertEqual(self.sync_engine.analyze_local_id(remote_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.ADD, None))
        # now we remove the remote task
        self.ftp_remote.fake_remove_task(remote_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.REMOVE, None))
        self.sync_engine.break_relationship(local_id=local_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.ADD, None))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task),
                         (SyncEngine.ADD, None))
        # we add them back and remove giving the remote id as key to find
        # what to delete
        self.ftp_local.fake_add_task(local_id)
        self.ftp_remote.fake_add_task(remote_id)
        self.ftp_remote.fake_remove_task(remote_id)
        self.sync_engine.record_relationship(local_id, remote_id, object)
        self.sync_engine.break_relationship(remote_id=remote_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.ADD, None))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task),
                         (SyncEngine.ADD, None))

    def test_syncability(self):
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id.
        Checks that the is_syncable parameter is used correctly """
        # adding a new local task unsyncable
        has_local_task = self.ftp_local.has_task
        has_remote_task = self.ftp_remote.has_task
        local_id = uuid.uuid4()
        self.ftp_local.fake_add_task(local_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           False),
                         (None, None))
        # adding a new local task, syncable
        local_id = uuid.uuid4()
        self.ftp_local.fake_add_task(local_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task),
                         (SyncEngine.ADD, None))
        # creating the related remote task
        remote_id = uuid.uuid4()
        self.ftp_remote.fake_add_task(remote_id)
        # informing the sync_engine about that
        self.sync_engine.record_relationship(local_id, remote_id, object())
        # checking that it behaves correctly with established relationships
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           True),
                         (SyncEngine.UPDATE, remote_id))
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           False),
                         (SyncEngine.LOST_SYNCABILITY, remote_id))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task,
                                                            True),
                         (SyncEngine.UPDATE, local_id))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task,
                                                            False),
                         (SyncEngine.LOST_SYNCABILITY, local_id))
        # now we remove the remote task
        self.ftp_remote.fake_remove_task(remote_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           True),
                         (SyncEngine.REMOVE, None))
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           False),
                         (SyncEngine.REMOVE, None))
        self.sync_engine.break_relationship(local_id=local_id)
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           True),
                         (SyncEngine.ADD, None))
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
                                                           has_local_task,
                                                           has_remote_task,
                                                           False),
                         (None, None))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task,
                                                            True),
                         (SyncEngine.ADD, None))
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
                                                            has_local_task,
                                                            has_remote_task,
                                                            False),
                         (None, None))
Example #10
0
 def setUp(self):
     self.ftp_local = FakeTaskProvider()
     self.ftp_remote = FakeTaskProvider()
     self.sync_engine = SyncEngine()
Example #11
0
class TestSyncEngine(unittest.TestCase):
    """ Tests for the SyncEngine object. """
    def setUp(self):
        self.ftp_local = FakeTaskProvider()
        self.ftp_remote = FakeTaskProvider()
        self.sync_engine = SyncEngine()

    def test_analyze_element_and_record_and_break_relationship(self):
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id,
        record_relationship, break_relationship """
        # adding a new local task
        has_local_task = self.ftp_local.has_task
        has_remote_task = self.ftp_remote.has_task
        local_id = uuid.uuid4()
        self.ftp_local.fake_add_task(local_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.ADD, None))
        # creating the related remote task
        remote_id = uuid.uuid4()
        self.ftp_remote.fake_add_task(remote_id)
        # informing the sync_engine about that
        self.sync_engine.record_relationship(local_id, remote_id, object())
        # verifying that it understood that
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.UPDATE, remote_id))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task),
            (SyncEngine.UPDATE, local_id))
        # and not the reverse
        self.assertEqual(
            self.sync_engine.analyze_remote_id(local_id, has_local_task,
                                               has_remote_task),
            (SyncEngine.ADD, None))
        self.assertEqual(
            self.sync_engine.analyze_local_id(remote_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.ADD, None))
        # now we remove the remote task
        self.ftp_remote.fake_remove_task(remote_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.REMOVE, None))
        self.sync_engine.break_relationship(local_id=local_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.ADD, None))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task),
            (SyncEngine.ADD, None))
        # we add them back and remove giving the remote id as key to find
        # what to delete
        self.ftp_local.fake_add_task(local_id)
        self.ftp_remote.fake_add_task(remote_id)
        self.ftp_remote.fake_remove_task(remote_id)
        self.sync_engine.record_relationship(local_id, remote_id, object)
        self.sync_engine.break_relationship(remote_id=remote_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.ADD, None))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task),
            (SyncEngine.ADD, None))

    def test_syncability(self):
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id.
        Checks that the is_syncable parameter is used correctly """
        # adding a new local task unsyncable
        has_local_task = self.ftp_local.has_task
        has_remote_task = self.ftp_remote.has_task
        local_id = uuid.uuid4()
        self.ftp_local.fake_add_task(local_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, False),
            (None, None))
        # adding a new local task, syncable
        local_id = uuid.uuid4()
        self.ftp_local.fake_add_task(local_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task),
            (SyncEngine.ADD, None))
        # creating the related remote task
        remote_id = uuid.uuid4()
        self.ftp_remote.fake_add_task(remote_id)
        # informing the sync_engine about that
        self.sync_engine.record_relationship(local_id, remote_id, object())
        # checking that it behaves correctly with established relationships
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, True),
            (SyncEngine.UPDATE, remote_id))
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, False),
            (SyncEngine.LOST_SYNCABILITY, remote_id))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task, True),
            (SyncEngine.UPDATE, local_id))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task, False),
            (SyncEngine.LOST_SYNCABILITY, local_id))
        # now we remove the remote task
        self.ftp_remote.fake_remove_task(remote_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, True),
            (SyncEngine.REMOVE, None))
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, False),
            (SyncEngine.REMOVE, None))
        self.sync_engine.break_relationship(local_id=local_id)
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, True),
            (SyncEngine.ADD, None))
        self.assertEqual(
            self.sync_engine.analyze_local_id(local_id, has_local_task,
                                              has_remote_task, False),
            (None, None))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task, True),
            (SyncEngine.ADD, None))
        self.assertEqual(
            self.sync_engine.analyze_remote_id(remote_id, has_local_task,
                                               has_remote_task, False),
            (None, None))