Exemplo n.º 1
0
    def execute(self):
        if not super().execute():
            return False

        try:
            expression = self.argument(0)
        except InvalidCommandArgument:
            expression = config().sort_string()

        sorter = Sorter(expression)  # TODO: validate
        sorted_todos = sorter.sort(self.todolist.todos())

        self.todolist.replace(sorted_todos)
Exemplo n.º 2
0
    def execute(self):
        if not super().execute():
            return False

        try:
            expression = self.argument(0)
        except InvalidCommandArgument:
            expression = config().sort_string()

        sorter = Sorter(expression)  # TODO: validate
        sorted_todos = sorter.sort(self.todolist.todos())

        self.todolist.replace(sorted_todos)
Exemplo n.º 3
0
 def test_sort3(self):
     """
     Descendingly sorted by priority. Also checks stableness of the
     sort.
     """
     sorter = Sorter('desc:prio')
     self.sort_file('test/data/SorterTest3.txt', 'test/data/SorterTest3-result.txt', sorter)
Exemplo n.º 4
0
    def execute(self):
        if not super(SortCommand, self).execute():
            return False

        try:
            expression = self.argument(0)
        except InvalidCommandArgument:
            expression = config().sort_string()

        sorter = Sorter(expression)  # TODO: validate
        sorted_todos = sorter.sort(self.todolist.todos())

        self.todolist.erase()

        for todo in sorted_todos:
            self.todolist.add_todo(todo)
Exemplo n.º 5
0
 def test_sort9(self):
     """
     Sort on multiple levels: first descending importance, then
     ascending priority.
     """
     sorter = Sorter('desc:importance,priority')
     self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9-result.txt', sorter)
Exemplo n.º 6
0
    def _handle_ls(self):
        """ Handles the ls subsubcommand. """
        try:
            arg1 = self.argument(1)
            arg2 = self.argument(2)

            todos = []
            if arg2 == 'to':
                # dep ls 1 to ...
                number = arg1
                todo = self.todolist.todo(number)
                todos = self.todolist.children(todo)
            elif arg1 == 'to':
                # dep ls ... to 1
                number = arg2
                todo = self.todolist.todo(number)
                todos = self.todolist.parents(todo)
            else:
                self.error(self.usage())

            if todos:
                sorter = Sorter(config().sort_string())
                instance_filter = Filter.InstanceFilter(todos)
                view = View(sorter, [instance_filter], self.todolist)
                self.out(self.printer.print_list(view.todos))
        except InvalidTodoException:
            self.error("Invalid todo number given.")
        except InvalidCommandArgument:
            self.error(self.usage())
Exemplo n.º 7
0
 def test_sort02a(self):
     """
     Ascendingly sorted by priority. Also checks stableness of the sort.
     """
     sorter = Sorter('prio')
     self.sort_file('test/data/SorterTest2.txt',
                    'test/data/SorterTest2-result.txt', sorter)
Exemplo n.º 8
0
    def test_sort18(self):
        """
        Check sorting by context.
        """
        sorter = Sorter('context')

        self.sort_file('test/data/SorterTest13.txt',
                       'test/data/SorterTest13-result-context.txt', sorter)
Exemplo n.º 9
0
    def test_sort14(self):
        sorter = Sorter('desc:importance-average')

        todolist = load_file_to_todolist('test/data/SorterTest10.txt')
        view = todolist.view(sorter, [])
        result = load_file('test/data/SorterTest10-result.txt')

        self.assertEqual(print_view(view), todolist_to_string(result))
Exemplo n.º 10
0
    def test_sort17(self):
        """
        Check sorting by project.
        """
        sorter = Sorter('project')

        self.sort_file('test/data/SorterTest13.txt',
                       'test/data/SorterTest13-result-project.txt', sorter)
Exemplo n.º 11
0
    def test_sort19(self):
        """
        Check sorting by length.
        """
        sorter = Sorter('length,text')

        self.sort_file('test/data/SorterTest14.txt',
                       'test/data/SorterTest14-result.txt', sorter)
Exemplo n.º 12
0
    def test_sort13(self):
        """
        Descendingly sorted by average importance.

        Reusing input and output for normal importance test, since without
        dependencies the average importance should be equal.
        """
        sorter = Sorter('desc:importance-avg')
        self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9-result.txt', sorter)
Exemplo n.º 13
0
    def test_sort16(self):
        """
        Check sort of low priority tasks (D or lower) with non-priority tasks.
        """
        sorter = Sorter('desc:importance,desc:prio')

        todolist = load_file_to_todolist('test/data/SorterTest12.txt')
        view = todolist.view(sorter, [])
        result = load_file('test/data/SorterTest12-result.txt')

        self.assertEqual(print_view(view), todolist_to_string(result))
Exemplo n.º 14
0
    def test_view(self):
        """ Check filters and printer for views. """
        todofile = TodoFile('test/data/FilterTest1.txt')
        ref = load_file('test/data/ViewTest1-result.txt')

        todolist = TodoList(todofile.read())
        sorter = Sorter('text')
        todofilter = Filter.GrepFilter('+Project')
        view = todolist.view(sorter, [todofilter])

        self.assertEqual(print_view(view), todolist_to_string(ref))
Exemplo n.º 15
0
    def test_sort15(self):
        """
        Test that own importance is used when average turns out to be
        lower.
        """
        sorter = Sorter('desc:importance-average')

        todolist = load_file_to_todolist('test/data/SorterTest11.txt')
        view = todolist.view(sorter, [])
        result = load_file('test/data/SorterTest11-result.txt')

        self.assertEqual(print_view(view), todolist_to_string(result))
Exemplo n.º 16
0
    def _viewdata_to_view(self, p_data):
        """
        Converts a dictionary describing a view to an actual UIView instance.
        """
        sorter = Sorter(p_data['sortexpr'], p_data['groupexpr'])
        filters = []

        if not p_data['show_all']:
            filters.append(DependencyFilter(self.todolist))
            filters.append(RelevanceFilter())
            filters.append(HiddenTagFilter())

        filters += get_filter_list(p_data['filterexpr'].split())

        return UIView(sorter, filters, self.todolist, p_data)
Exemplo n.º 17
0
 def test_sort5(self):
     """ Descendingly sorted by due date """
     sorter = Sorter('desc:due')
     self.sort_file('test/data/SorterTest5.txt', 'test/data/SorterTest5-result.txt', sorter)
Exemplo n.º 18
0
 def test_sort12(self):
     """ Deal with garbage input. """
     sorter = Sorter('desc:importance,,priority')
     self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9-result.txt', sorter)
Exemplo n.º 19
0
 def test_sort10(self):
     """ Deal with garbage input. """
     sorter = Sorter('')
     self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9.txt', sorter)
Exemplo n.º 20
0
 def test_sort1(self):
     """ Alphabetically sorted """
     sorter = Sorter('text')
     self.sort_file('test/data/SorterTest1.txt', 'test/data/SorterTest1-result.txt', sorter)
Exemplo n.º 21
0
 def test_sort8(self):
     """ Descendingly sorted by importance """
     sorter = Sorter('desc:importance')
     self.sort_file('test/data/SorterTest8.txt', 'test/data/SorterTest8-result.txt', sorter)
Exemplo n.º 22
0
 def test_sort7(self):
     """ Ascendingly sorted by completion date. """
     sorter = Sorter('completion')
     self.sort_file('test/data/SorterTest7.txt', 'test/data/SorterTest7-result.txt', sorter)
Exemplo n.º 23
0
 def test_sort6(self):
     """ Ascendingly sorted by creation date """
     sorter = Sorter('creation')
     self.sort_file('test/data/SorterTest6.txt', 'test/data/SorterTest6-result.txt', sorter)
Exemplo n.º 24
0
def sorted_todos_by_project(cfg, todo_cfg=None):
    """
    Takes our todo list, and returns two dictionaries of where the keys equal
    to the project name, and the value is a list of todo items under that
    project.

    - Note that a todo item may be appended to multiple second level HTML lists
        if the item is listed under multiple projects.
    - Note that todo items without a project are discarded.
    - Note that completed items beyond `completion_cutoff` (measured in days)
        are discarded.

    todo_cfg is called to topydo.config directs as the path of the test
        configuration. Setting this to None will use the normal configuration.
    """
    '''
    print(type(cfg))
    print(cfg)
    print(type(cfg['todo']), cfg['todo'])
    print(type(cfg['todo']['completion_cutoff']), cfg['todo']['completion_cutoff'])
    '''
    completion_range = timestring.Range('last {!s} days'.format(cfg['todo']['completion_cutoff']))

    my_sorter = Sorter(p_sortstring=cfg['todo']['sort_string'])

    todofile = TodoFile.TodoFile(topydo_config(todo_cfg).todotxt())
    # print('Loaded todo file from {}'.format(todofile.path))
    todotodos = TodoList.TodoList(todofile.read())
    # todolist = my_sorter.sort(todolist)            # in topydo v0.10
    # json_str = JsonPrinter().print_list(todolist)  # in topydo v0.10
    todolist = my_sorter.sort(todotodos.todos())    # sort before filters
    # filters return a list, so apply them all at once?
    todolist = HiddenTagFilter().filter(todolist)
    todo_json_str = JsonPrinter().print_list(todolist)
    todo_json = json.loads(todo_json_str)

    donefile = TodoFile.TodoFile(topydo_config(todo_cfg).archive())
    # print('Loaded done file from {}'.format(donefile.path))
    donetodos = TodoList.TodoList(donefile.read())
    donelist = my_sorter.sort(donetodos.todos())
    donelist = HiddenTagFilter().filter(donelist)
    done_json_str = JsonPrinter().print_list(donelist)
    done_json = json.loads(done_json_str)

    active_todos = {}
    completed_todos = {}

    for my_json in [todo_json, done_json]:
        for todo in my_json:
            if not todo['completed']:
                for project in todo['projects']:
                    try:
                        active_todos[project].append(todo['source'])
                    except KeyError:
                        active_todos[project] = [todo['source']]
            else:
                completion_date = timestring.Date(todo['completion_date'])
                if completion_date in completion_range:
                    for project in todo['projects']:
                        try:
                            completed_todos[project].append(todo['source'])
                        except KeyError:
                            completed_todos[project] = [todo['source']]

    return active_todos, completed_todos
Exemplo n.º 25
0
    def _view(self):
        sorter = Sorter(self.sort_expression)
        filters = self._filters()

        return View(sorter, filters, self.todolist)
Exemplo n.º 26
0
 def test_sort4(self):
     """ Ascendingly sorted by due date """
     sorter = Sorter(config().tag_due())
     self.sort_file('test/data/SorterTest4.txt', 'test/data/SorterTest4-result.txt', sorter)