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

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

            if text:
                todo = self.todolist.todo(number)
                new_text_parsed = parse_line(text)
                new_tags = new_text_parsed['tags']
                for tag in (config().tag_start(), config().tag_due()):
                    if tag in new_tags:
                        todo.remove_tag(tag)
                self.todolist.append(todo, text)
                self.postprocess_input_todo(todo)

                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.")
Esempio n. 2
0
    def _execute_multi_specific(self):
        self.printer.add_filter(PrettyPrinterNumbers(self.todolist))

        temp_todos = self._todos_to_temp()
        orig_mtime = _get_file_mtime(temp_todos)

        if not self._open_in_editor(temp_todos.name):
            new_todos = EditCommand._todos_from_temp(temp_todos)

            if _is_edited(orig_mtime, temp_todos):
                modified = list(zip(self.todos, new_todos))
                for (todo, new_todo) in modified:
                    self.todolist.modify_todo(todo, new_todo.src)
                    self.out(self.printer.print_todo(todo))

                for todo in self.todos[len(modified):]:
                    self.todolist.delete(todo, p_leave_tags=True)

                for todo in new_todos[len(modified):]:
                    self.todolist.add_todo(todo)
                    self.out(self.printer.print_todo(todo))
            else:
                self.error('Editing aborted. Nothing to do.')
        else:
            self.error(self.usage())

        os.unlink(temp_todos.name)
Esempio n. 3
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))
Esempio n. 4
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
Esempio n. 5
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:
            try:
                offset = _get_offset(todo)
            except ValueError:
                self.error("Postponing todo item failed: invalid due date.")
                break

            new_due = relative_date_to_date(pattern, offset)

            if new_due:
                if self.move_start_date and todo.start_date():
                    length = todo.length()
                    new_start = new_due - timedelta(length)
                    # pylint: disable=E1103
                    todo.set_tag(config().tag_start(), new_start.isoformat())
                elif self.move_start_date and not todo.start_date():
                    self.error(
                        "Warning: todo item has no (valid) start date, therefore it was not adjusted."
                    )

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

                self.todolist.dirty = True
                self.out(self.printer.print_todo(todo))
            else:
                self.error("Invalid date pattern given.")
                break
Esempio n. 6
0
    def execute(self):
        """ Adds a todo item to the list. """
        if not super().execute():
            return False

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

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

                for todo in new_todos:
                    self._add_todo(todo)
            except (IOError, OSError):
                self.error('File not found: ' + self.from_file)
        else:
            if self.text:
                self._add_todo(self.text)
            else:
                self.error(self.usage())
Esempio n. 7
0
    def _execute_multi_specific(self):
        def normalize_priority(p_priority):
            match = re.search(r'\b([A-Z])\b', p_priority.upper())
            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.")
Esempio n. 8
0
 def _print_list(self, p_todos):
     printer = PrettyPrinter()
     printer.add_filter(PrettyPrinterNumbers(self.todolist))
     self.out(printer.print_list(p_todos))
Esempio n. 9
0
 def _print(self):
     self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
     self.out(self.printer.print_todo(self.todo))