예제 #1
0
    def test_persist_task_mapping(self):
        expected = TaskMap()
        tasks = [MockTask(_id=i) for i in range(4)]
        expected.map(tasks[0], tasks[1])
        expected.map(tasks[2], tasks[3])
        filename = NamedTemporaryFile(suffix='.pickle')
        expected.persist(filename.name)
        actual = TaskMap(filename.name)

        assert actual.get_dst_id(tasks[0].id) == tasks[1].id
        assert actual.get_dst_id(tasks[2].id) == tasks[3].id
        assert actual.get_src_id(tasks[1].id) == tasks[0].id
        assert actual.get_src_id(tasks[3].id) == tasks[2].id
예제 #2
0
    def test_persist_task_mapping(self):
        expected = TaskMap()
        tasks = [
            MockTask(_id='aaa'),
            MockTask(_id='bbb'),
            MockTask(_id='ccc'),
            MockTask(_id='ddd')]
        expected.map(tasks[0], tasks[1])
        expected.map(tasks[2], tasks[3])
        filename = NamedTemporaryFile(suffix='.tm')
        expected.persist(filename.name)
        actual = TaskMap(filename.name)

        assert actual.get_dst_id(tasks[0].id) == tasks[1].id
        assert actual.get_dst_id(tasks[2].id) == tasks[3].id
        assert actual.get_src_id(tasks[1].id) == tasks[0].id
        assert actual.get_src_id(tasks[3].id) == tasks[2].id
예제 #3
0
    def test_persist_task_mapping(self):
        expected = TaskMap()
        tasks = [
            MockTask(_id='aaa'),
            MockTask(_id='bbb'),
            MockTask(_id='ccc'),
            MockTask(_id='ddd')
        ]
        expected.map(tasks[0], tasks[1])
        expected.map(tasks[2], tasks[3])
        filename = NamedTemporaryFile(suffix='.tm')
        expected.persist(filename.name)
        actual = TaskMap(filename.name)

        assert actual.get_dst_id(tasks[0].id) == tasks[1].id
        assert actual.get_dst_id(tasks[2].id) == tasks[3].id
        assert actual.get_src_id(tasks[1].id) == tasks[0].id
        assert actual.get_src_id(tasks[3].id) == tasks[2].id
예제 #4
0
    def update(self):
        """ This update method will be called once on every update cycle,
        with the frequency determined by the value returned from
        `update_interval_minutes()`.

        If a plugin implements a single-shot function, then update should
        return `False`.

        Returns: bool: True if further updates are required; False if the plugin
        is finished and the application should shut down.
        """
        # retrieve the boards to sync
        boards = self.__tc.list_boards(board_filter='open')
        sync_boards = [
            b for b in boards if b.name in self.__boards]

        self.__ensure_labels_exist(sync_boards)

        # Build a list of sync lists by matching the sync
        # list names in each board
        sync_lists = []
        done_lists = []
        for b in sync_boards:
            for l in b.open_lists():
                if l.name in self._config.trello_lists:
                    sync_lists.append(l)
                elif l.name in self._config.trello_done_lists:
                    done_lists.append(l)

        # some additional information on the source boards and lists
        message = 'Syncing the following lists'
        for l in sync_lists:
            message += '\n   {0}.{1}'.format(l.board.name, l.name)
        message += '\nTreating cards in the following lists as completed'
        for l in done_lists:
            message += '\n   {0}.{1}'.format(l.board.name, l.name)
        logging.getLogger(__name__).debug(message)

        # Load the task map from disk
        task_map = TaskMap(self.__task_map_file)

        # Create the services
        source_service = TrelloTaskService(
            self.__tc,
            sync_lists,
            done_lists,
            self.__boards)

        # synchronise
        sync = TaskSync(
            source_service,
            self.__habitica_task_service,
            task_map,
            last_sync=self.__data.last_sync,
            sync_description=self._config.trello_sync_description)

        stats = sync.synchronise(clean_orphans=False)

        self.__notify(stats)

        # Checkpoint the sync data
        self.__data.last_sync = sync.last_sync
        if not self.dry_run:
            task_map.persist(self.__task_map_file)
            self.__save_persistent_data()

        # return False if finished, and True to be updated again.
        return True