Commit 317c71fc authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add dep subcommand to handle dependencies.

parent b9c7ed1d
...@@ -10,6 +10,7 @@ from PrettyPrinter import pretty_print ...@@ -10,6 +10,7 @@ from PrettyPrinter import pretty_print
import Sorter import Sorter
import TodoFile import TodoFile
import TodoList import TodoList
import View
def print_iterable(p_iter): def print_iterable(p_iter):
""" Prints an iterable to the standard output, one item per line. """ """ Prints an iterable to the standard output, one item per line. """
...@@ -74,6 +75,58 @@ class Application(object): ...@@ -74,6 +75,58 @@ class Application(object):
self.dirty = True self.dirty = True
def dep(self):
""" Handles dependencies between todos. """
def handle_add_rm(operation):
""" Handles the add and rm subsubcommands. """
from_todonumber = convert_number(argument(3))
to_todonumber = argument(4)
if to_todonumber == 'to':
to_todonumber = convert_number(argument(5))
else:
to_todonumber = convert_number(to_todonumber)
if operation == 'add':
self.todolist.add_dependency(from_todonumber, to_todonumber)
else:
self.todolist.remove_dependency(from_todonumber, to_todonumber)
self.dirty = True
def handle_ls():
""" Handles the ls subsubcommand. """
arg1 = argument(3)
arg2 = argument(4)
todos = []
if arg2 == 'to':
# dep ls 1 to ...
todos = self.todolist.children(convert_number(arg1))
elif arg1 == 'to':
# dep ls ... to 1
todos = self.todolist.parents(convert_number(arg2))
else:
usage()
if todos:
sorter = Sorter.Sorter(Config.SORT_STRING)
view = View.View(sorter, [], todos)
print view.pretty_print()
subsubcommand = argument(2)
if subsubcommand == 'add' or \
subsubcommand == 'rm' or subsubcommand == 'del':
handle_add_rm(subsubcommand)
elif subsubcommand == 'clean' or subsubcommand == 'gc':
self.todolist.clean_dependencies()
self.dirty = True
elif subsubcommand == 'ls':
handle_ls()
else:
usage()
def do(self): def do(self):
number = convert_number(argument(2)) number = convert_number(argument(2))
todo = self.todolist.todo(number) todo = self.todolist.todo(number)
...@@ -127,6 +180,8 @@ class Application(object): ...@@ -127,6 +180,8 @@ class Application(object):
self.add() self.add()
elif subcommand == 'app' or subcommand == 'append': elif subcommand == 'app' or subcommand == 'append':
self.append() self.append()
elif subcommand == 'dep':
self.dep()
elif subcommand == 'do': elif subcommand == 'do':
self.do() self.do()
elif subcommand == 'ls': elif subcommand == 'ls':
......
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