Commit 6638beb1 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Move priority to its own Command class.

parent b5a3dfea
#!/usr/bin/env python #!/usr/bin/env python
""" Entry file for the Python todo.txt CLI. """ """ Entry file for the Python todo.txt CLI. """
import re
import sys import sys
from AddCommand import AddCommand from AddCommand import AddCommand
from AppendCommand import AppendCommand from AppendCommand import AppendCommand
from DepCommand import DepCommand from DepCommand import DepCommand
from DoCommand import DoCommand
import Config import Config
from DoCommand import DoCommand
import Filter import Filter
from PrettyPrinter import pretty_print from PrettyPrinter import pretty_print
from PriorityCommand import PriorityCommand
import Sorter import Sorter
import TodoFile import TodoFile
import TodoList import TodoList
...@@ -82,21 +82,8 @@ class Application(object): # TODO: rename to CLIApplication ...@@ -82,21 +82,8 @@ class Application(object): # TODO: rename to CLIApplication
command.execute() command.execute()
def pri(self): def pri(self):
number = convert_todo_number(argument(2)) command = PriorityCommand(arguments(), self.todolist)
priority = argument(3) command.execute()
if re.match('^[A-Z]$', priority):
todo = self.todolist.todo(number)
if todo:
old_priority = todo.priority()
todo.set_priority(priority)
print "Priority changed from %s to %s" \
% (old_priority, priority)
self.print_todo(number)
else:
error("Invalid priority given.")
def list(self): def list(self):
sorter = Sorter.Sorter(Config.SORT_STRING) sorter = Sorter.Sorter(Config.SORT_STRING)
......
import re
import Command
from Utils import convert_todo_number
class PriorityCommand(Command.Command):
def __init__(self, p_args, p_todolist):
super(PriorityCommand, self).__init__(p_args, p_todolist)
self.number = convert_todo_number(self.argument(0))
self.todo = self.todolist.todo(self.number)
self.priority = self.argument(1)
def execute(self):
if re.match('^[A-Z]$', self.priority):
old_priority = self.todo.priority()
self.todolist.set_priority(self.number, self.priority)
print "Priority changed from %s to %s" \
% (old_priority, self.priority) # FIXME
# self.print_todo(number) # FIXME
else:
# error("Invalid priority given.") # TODO
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment