Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
a2627d36
Commit
a2627d36
authored
Sep 27, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make separate command for dependencies.
parent
e6d8ab54
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
48 deletions
+79
-48
Command.py
Command.py
+12
-0
DepCommand.py
DepCommand.py
+64
-0
Main.py
Main.py
+3
-48
No files found.
Command.py
View file @
a2627d36
...
...
@@ -6,3 +6,15 @@ class Command(object):
def
execute
(
self
):
""" The command to execute. """
return
False
def
argument
(
self
,
p_number
):
""" Retrieves a value from the argument list. """
try
:
value
=
self
.
args
[
p_number
]
except
IndexError
:
self
.
usage
()
return
value
def
usage
(
self
):
return
""
DepCommand.py
0 → 100644
View file @
a2627d36
import
Command
import
Config
import
Sorter
from
Utils
import
convert_todo_number
import
View
class
DepCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
DepCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
self
.
subsubcommand
=
self
.
argument
(
0
)
def
_handle_add
(
self
):
(
from_todo
,
to_todo
)
=
self
.
_get_todo_numbers
()
self
.
todolist
.
add_dependency
(
from_todo
,
to_todo
)
def
_handle_rm
(
self
):
(
from_todo
,
to_todo
)
=
self
.
_get_todo_numbers
()
self
.
todolist
.
remove_dependency
(
from_todo
,
to_todo
)
def
_get_todo_numbers
(
self
):
from_todonumber
=
convert_todo_number
(
self
.
argument
(
1
))
to_todonumber
=
self
.
argument
(
2
)
if
to_todonumber
==
'to'
:
to_todonumber
=
convert_todo_number
(
self
.
argument
(
3
))
else
:
to_todonumber
=
convert_todo_number
(
to_todonumber
)
return
(
from_todonumber
,
to_todonumber
)
def
_handle_ls
(
self
):
""" Handles the ls subsubcommand. """
arg1
=
self
.
argument
(
1
)
arg2
=
self
.
argument
(
2
)
todos
=
[]
if
arg2
==
'to'
:
# dep ls 1 to ...
todos
=
self
.
todolist
.
children
(
convert_todo_number
(
arg1
))
elif
arg1
==
'to'
:
# dep ls ... to 1
todos
=
self
.
todolist
.
parents
(
convert_todo_number
(
arg2
))
else
:
self
.
usage
()
if
todos
:
sorter
=
Sorter
.
Sorter
(
Config
.
SORT_STRING
)
view
=
View
.
View
(
sorter
,
[],
todos
)
print
view
.
pretty_print
()
# FIXME
def
execute
(
self
):
dispatch
=
{
'add'
:
self
.
_handle_add
,
'rm'
:
self
.
_handle_rm
,
'del'
:
self
.
_handle_rm
,
'ls'
:
self
.
_handle_ls
,
'clean'
:
self
.
todolist
.
clean_dependencies
,
'gc'
:
self
.
todolist
.
clean_dependencies
,
}
dispatch
[
self
.
subsubcommand
]()
if
self
.
subsubcommand
in
dispatch
\
else
self
.
usage
()
return
True
Main.py
View file @
a2627d36
...
...
@@ -5,6 +5,7 @@ import re
import
sys
from
AddCommand
import
AddCommand
from
DepCommand
import
DepCommand
import
Config
import
Filter
from
PrettyPrinter
import
pretty_print
...
...
@@ -13,7 +14,6 @@ import Sorter
import
TodoFile
import
TodoList
from
Utils
import
convert_todo_number
import
View
def
print_iterable
(
p_iter
):
""" Prints an iterable to the standard output, one item per line. """
...
...
@@ -77,53 +77,8 @@ class Application(object): # TODO: rename to CLIApplication
self
.
print_todo
(
number
)
def
dep
(
self
):
""" Handles dependencies between todos. """
def
handle_add_rm
(
operation
):
""" Handles the add and rm subsubcommands. """
from_todonumber
=
convert_todo_number
(
argument
(
3
))
to_todonumber
=
argument
(
4
)
if
to_todonumber
==
'to'
:
to_todonumber
=
convert_todo_number
(
argument
(
5
))
else
:
to_todonumber
=
convert_todo_number
(
to_todonumber
)
if
operation
==
'add'
:
self
.
todolist
.
add_dependency
(
from_todonumber
,
to_todonumber
)
else
:
self
.
todolist
.
remove_dependency
(
from_todonumber
,
to_todonumber
)
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_todo_number
(
arg1
))
elif
arg1
==
'to'
:
# dep ls ... to 1
todos
=
self
.
todolist
.
parents
(
convert_todo_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
()
elif
subsubcommand
==
'ls'
:
handle_ls
()
else
:
usage
()
command
=
DepCommand
(
arguments
(),
self
.
todolist
)
command
.
execute
()
def
do
(
self
):
def
complete_children
(
p_number
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment