Commit f79f683c authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add command for 'do'.

parent c2037fc8
import re
import Command
from Recurrence import advance_recurring_todo
from Utils import convert_todo_number
class DoCommand(Command.Command):
def __init__(self, p_args, p_todolist):
super(DoCommand, self).__init__(p_args, p_todolist)
self.number = convert_todo_number(self.argument(0))
self.todo = self.todolist.todo(self.number)
def _complete_children(self):
children = [t.attributes['number'] for t in self.todolist.children(self.number) if not t.is_completed()]
if children:
for child in children:
# self.print_todo(child) # FIXME
pass
confirmation = raw_input("Also mark subtasks as done? [n] "); # FIXME
if re.match('^y(es)?$', confirmation, re.I):
for child in children:
self.todolist.set_todo_completed(child)
# self.print_todo(child) # FIXME
def _handle_recurrence(self):
if self.todo.has_tag('rec'):
new_todo = advance_recurring_todo(self.todo)
self.todolist.add_todo(new_todo)
# self.print_todo(self.todolist.count()) # FIXME
def execute(self):
if self.todo and not self.todo.is_completed():
self._complete_children()
self._handle_recurrence()
self.todolist.set_todo_completed(self.number)
......@@ -7,10 +7,10 @@ import sys
from AddCommand import AddCommand
from AppendCommand import AppendCommand
from DepCommand import DepCommand
from DoCommand import DoCommand
import Config
import Filter
from PrettyPrinter import pretty_print
from Recurrence import advance_recurring_todo
import Sorter
import TodoFile
import TodoList
......@@ -78,34 +78,8 @@ class Application(object): # TODO: rename to CLIApplication
command.execute()
def do(self):
def complete_children(p_number):
children = [t.attributes['number'] for t in self.todolist.children(p_number) if not t.is_completed()]
if children:
for child in children:
self.print_todo(child)
confirmation = raw_input("Also mark subtasks as done? [n] ");
if re.match('^y(es)?$', confirmation, re.I):
for child in children:
self.todolist.todo(child).set_completed()
self.print_todo(child)
def handle_recurrence(todo):
if todo.has_tag('rec'):
new_todo = advance_recurring_todo(todo)
self.todolist.add_todo(new_todo)
self.print_todo(self.todolist.count())
number = convert_todo_number(argument(2))
todo = self.todolist.todo(number)
if todo and not todo.is_completed():
complete_children(number)
handle_recurrence(todo)
todo.set_completed()
self.print_todo(number)
command = DoCommand(arguments(), self.todolist)
command.execute()
def pri(self):
number = convert_todo_number(argument(2))
......
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