Пример #1
0
    def _execute_multi_specific(self):
        def _get_offset(p_todo):
            offset = p_todo.tag_value(config().tag_due(),
                                      date.today().isoformat())
            offset_date = date_string_to_date(offset)

            if offset_date < date.today():
                offset_date = date.today()

            return offset_date

        pattern = self.args[-1]
        self.printer.add_filter(PrettyPrinterNumbers(self.todolist))

        for todo in self.todos:
            offset = _get_offset(todo)
            new_due = relative_date_to_date(pattern, offset)

            if new_due:
                if self.move_start_date and todo.has_tag(config().tag_start()):
                    length = todo.length()
                    new_start = new_due - timedelta(length)
                    # pylint: disable=E1103
                    todo.set_tag(config().tag_start(), new_start.isoformat())

                # pylint: disable=E1103
                todo.set_tag(config().tag_due(), new_due.isoformat())

                self.todolist.set_dirty()
                self.out(self.printer.print_todo(todo))
            else:
                self.error("Invalid date pattern given.")
                break
Пример #2
0
    def _execute_multi_specific(self):
        self.printer.add_filter(PrettyPrinterNumbers(self.todolist))

        for todo in self.todos:
            if todo.priority() != None:
                self.todolist.set_priority(todo, None)
                self.out("Priority removed.")
                self.out(self.printer.print_todo(todo))
Пример #3
0
    def pretty_print(self, p_pp_filters=None):
        """ Pretty prints the view. """
        p_pp_filters = p_pp_filters or []

        # since we're using filters, always use PrettyPrinter
        printer = PrettyPrinter()
        printer.add_filter(PrettyPrinterNumbers(self._todolist))
        printer.add_filter(PrettyPrinterColorFilter())

        for ppf in p_pp_filters:
            printer.add_filter(ppf)

        return printer.print_list(self._viewdata)
Пример #4
0
    def execute(self):
        """ Adds a todo item to the list. """
        if not super(AddCommand, self).execute():
            return False

        if self.text:
            self._preprocess_input_todo()
            self.todo = self.todolist.add(self.text)
            self._postprocess_input_todo()

            self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
            self.out(self.printer.print_todo(self.todo))
        else:
            self.error(self.usage())
Пример #5
0
def pretty_printer_factory(p_todolist, p_additional_filters=None):
    """ Returns a pretty printer suitable for the ls and dep subcommands. """

    p_additional_filters = p_additional_filters or []

    printer = PrettyPrinter()
    printer.add_filter(PrettyPrinterNumbers(p_todolist))

    for ppf in p_additional_filters:
        printer.add_filter(ppf)

    # apply colors at the last step, the ANSI codes may confuse the
    # preceding filters.
    printer.add_filter(PrettyPrinterColorFilter())

    return printer
Пример #6
0
    def _handle_recurrence(self, p_todo):
        if p_todo.has_tag('rec'):
            try:
                if self.strict_recurrence:
                    new_todo = strict_advance_recurring_todo(p_todo,
                        self.completion_date)
                else:
                    new_todo = advance_recurring_todo(p_todo,
                        self.completion_date)

                self.todolist.add_todo(new_todo)

                printer = PrettyPrinter()
                printer.add_filter(PrettyPrinterNumbers(self.todolist))
                self.out(printer.print_todo(new_todo))
            except NoRecurrenceException:
                self.error("Warning: todo item has an invalid recurrence pattern.")
Пример #7
0
    def execute(self):
        """ Adds a todo item to the list. """
        if not super(AddCommand, self).execute():
            return False

        self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
        self._process_flags()

        if self.from_file:
            new_todos = self.get_todos_from_file()

            for todo in new_todos:
                self._add_todo(todo)
        else:
            if self.text:
                self._add_todo(self.text)
            else:
                self.error(self.usage())
Пример #8
0
    def _execute_multi_specific(self):
        self.printer.add_filter(PrettyPrinterNumbers(self.todolist))

        temp_todos = self._todos_to_temp()

        if not self._open_in_editor(temp_todos.name):
            new_todos = self._todos_from_temp(temp_todos)
            if len(new_todos) == len(self.todos):
                for todo in self.todos:
                    BASE_TODOLIST(self.todolist).delete(todo)

                for todo in new_todos:
                    self.todolist.add_todo(todo)
                    self.out(self.printer.print_todo(todo))
            else:
                self.error('Number of edited todos is not equal to '
                            'number of supplied todo IDs.')
        else:
            self.error(self.usage())
Пример #9
0
    def execute(self):
        if not super(AppendCommand, self).execute():
            return False

        try:
            number = self.argument(0)
            text = " ".join(self.args[1:])

            if text:
                todo = self.todolist.todo(number)
                self.todolist.append(todo, text)

                self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
                self.out(self.printer.print_todo(todo))
            else:
                self.error(self.usage())
        except InvalidCommandArgument:
            self.error(self.usage())
        except InvalidTodoException:
            self.error("Invalid todo number given.")
Пример #10
0
    def execute(self):
        def _get_offset(p_todo):
            offset = p_todo.tag_value(config().tag_due(),
                                      date.today().isoformat())
            offset_date = date_string_to_date(offset)

            if offset_date < date.today():
                offset_date = date.today()

            return offset_date

        if not super(PostponeCommand, self).execute():
            return False

        self._process_flags()

        try:
            todo = self.todolist.todo(self.argument(0))
            pattern = self.argument(1)

            offset = _get_offset(todo)
            new_due = relative_date_to_date(pattern, offset)

            if new_due:
                if self.move_start_date and todo.has_tag(config().tag_start()):
                    length = todo.length()
                    new_start = new_due - timedelta(length)
                    todo.set_tag(config().tag_start(), new_start.isoformat())

                todo.set_tag(config().tag_due(), new_due.isoformat())

                self.todolist.set_dirty()
                self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
                self.out(self.printer.print_todo(todo))
            else:
                self.error("Invalid date pattern given.")

        except InvalidCommandArgument:
            self.error(self.usage())
        except (InvalidTodoException):
            self.error("Invalid todo number given.")
Пример #11
0
    def _execute_multi_specific(self):
        def normalize_priority(p_priority):
            match = re.search(r'\b([A-Z])\b', p_priority)
            return match.group(1) if match else p_priority

        priority = normalize_priority(self.args[-1])
        self.printer.add_filter(PrettyPrinterNumbers(self.todolist))

        if is_valid_priority(priority):
            for todo in self.todos:
                old_priority = todo.priority()
                self.todolist.set_priority(todo, priority)

                if old_priority and priority and old_priority != priority:
                    self.out("Priority changed from {} to {}".format(
                        old_priority, priority))
                elif not old_priority:
                    self.out("Priority set to {}.".format(priority))

                self.out(self.printer.print_todo(todo))
        else:
            self.error("Invalid priority given.")
Пример #12
0
 def _print(self):
     self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
     self.out(self.printer.print_todo(self.todo))
Пример #13
0
 def _print_list(self, p_todos):
     printer = PrettyPrinter()
     printer.add_filter(PrettyPrinterNumbers(self.todolist))
     self.out(printer.print_list(p_todos))