コード例 #1
0
    def execute(self):
        if not super(PriorityCommand, self).execute():
            return False

        number = None
        priority = None
        try:
            number = self.argument(0)
            priority = self.argument(1)
            todo = self.todolist.todo(number)

            if is_valid_priority(priority):
                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.")
        except InvalidCommandArgument:
            self.error(self.usage())
        except (InvalidTodoException):
            if number and priority:
                self.error("Invalid todo number given.")
            else:
                self.error(self.usage())
コード例 #2
0
ファイル: TodoBase.py プロジェクト: MinchinWeb/topydo
    def set_priority(self, p_priority):
        """
        Sets the priority of the todo. Must be a single capital letter [A-Z],
        or None to unset the priority.
        Priority remains unchanged when an invalid priority is given, or when
        the task was completed.
        """
        if not self.is_completed() and (p_priority is None or is_valid_priority(p_priority)):
            self.fields["priority"] = p_priority

            priority_str = "" if p_priority is None else "(" + p_priority + ") "
            self.src = re.sub(r"^(\([A-Z]\) )?", priority_str, self.src)
コード例 #3
0
ファイル: TodoBase.py プロジェクト: wzel/topydo
    def set_priority(self, p_priority):
        """
        Sets the priority of the todo. Must be a single capital letter [A-Z],
        or None to unset the priority.
        Priority remains unchanged when an invalid priority is given, or when
        the task was completed.
        """
        if not self.is_completed() and (p_priority is None or
                                        is_valid_priority(p_priority)):
            self.fields['priority'] = p_priority

            priority_str = '' if p_priority is None else '(' + p_priority + ') '
            self.src = re.sub(r'^(\([A-Z]\) )?', priority_str, self.src)
コード例 #4
0
ファイル: TodoBase.py プロジェクト: netimen/topydo
    def set_priority(self, p_priority):
        """
        Sets the priority of the todo. Must be a single capital letter [A-Z],
        or None to unset the priority.
        Priority remains unchanged when an invalid priority is given, or when
        the task was completed.
        """

        if not self.is_completed() and \
            (p_priority == None or is_valid_priority(p_priority)):

            self.fields['priority'] = p_priority

            priority_str = '' if p_priority == None else '(' + p_priority + ') '
            self.src = re.sub(r'^(\([A-Z]\) )?', priority_str, self.src)
コード例 #5
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.")
コード例 #6
0
ファイル: PriorityCommand.py プロジェクト: rtvb/topydo
    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.")