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
79de0979
Commit
79de0979
authored
Oct 12, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let caller ship functions to show output, errors and prompt for input.
parent
063e623f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
83 additions
and
39 deletions
+83
-39
AddCommand.py
AddCommand.py
+5
-2
AppendCommand.py
AppendCommand.py
+5
-2
Command.py
Command.py
+33
-11
DepCommand.py
DepCommand.py
+5
-2
DoCommand.py
DoCommand.py
+9
-5
ListCommand.py
ListCommand.py
+5
-2
ListContextCommand.py
ListContextCommand.py
+5
-2
ListProjectCommand.py
ListProjectCommand.py
+5
-2
Main.py
Main.py
+6
-9
PriorityCommand.py
PriorityCommand.py
+5
-2
No files found.
AddCommand.py
View file @
79de0979
...
...
@@ -7,8 +7,11 @@ from PrettyPrinter import pretty_print, pp_number
from
RelativeDate
import
relative_date_to_date
class
AddCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
AddCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
AddCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
text
=
' '
.
join
(
p_args
)
def
_preprocess_input_todo
(
self
):
...
...
AppendCommand.py
View file @
79de0979
...
...
@@ -3,8 +3,11 @@ from PrettyPrinter import pretty_print, pp_number
from
Utils
import
convert_todo_number
class
AppendCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
AppendCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
AppendCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
=
lambda
a
:
None
)
def
execute
(
self
):
number
=
convert_todo_number
(
self
.
argument
(
0
))
...
...
Command.py
View file @
79de0979
class
Command
(
object
):
def
__init__
(
self
,
p_args
,
p_todolist
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
"""
Sets up the basic properties for executing a subcommand.
p_args is a list of arguments that can be passed to this subcommand.
These can be retrieved with argument(), or the existence of an argument
using argumentShift().
p_todolist is a reference to the todolist instance to operate on.
p_out is a function to be called to print (standard) output. Defaults
to a noop.
p_err is a function to be called to print errors. Defaults to a noop.
p_prompt is a function that accepts a prompt string as its own argument
and returns the answer to that prompt (normally entered by the user in
some way). The default is a noop prompt.
"""
self
.
args
=
p_args
self
.
todolist
=
p_todolist
self
.
output
=
[]
self
.
errors
=
[]
# inputs and outputs
self
.
out
=
p_out
self
.
error
=
p_err
self
.
prompt
=
p_prompt
def
execute
(
self
):
""" The command to execute. """
return
(
False
,
None
,
None
)
"""
Execute the command.
Returns True when the command succeeded or False on failure.
"""
return
False
def
argument
(
self
,
p_number
):
""" Retrieves a value from the argument list. """
""" Retrieves a value from the argument list
at the given position
. """
try
:
value
=
self
.
args
[
p_number
]
except
IndexError
:
...
...
@@ -32,8 +59,3 @@ class Command(object):
def
usage
(
self
):
return
"No usage text defined for this command."
def
out
(
self
,
p_text
):
# TODO: make private
self
.
output
.
append
(
p_text
)
def
error
(
self
,
p_text
):
# TODO: make private
self
.
errors
.
append
(
p_text
)
DepCommand.py
View file @
79de0979
...
...
@@ -5,8 +5,11 @@ 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
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
DepCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
subsubcommand
=
self
.
argument
(
0
)
def
_handle_add
(
self
):
...
...
DoCommand.py
View file @
79de0979
...
...
@@ -6,17 +6,20 @@ 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
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
DoCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
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
()]
children
=
[
t
for
t
in
self
.
todolist
.
children
(
self
.
number
)
if
not
t
.
is_completed
()]
if
children
:
pretty_print_list
(
children
,
[
pp_number
]
)
self
.
out
(
"
\
n
"
.
join
(
pretty_print_list
(
children
,
[
pp_number
]))
)
confirmation
=
raw_input
(
"Also mark subtasks as done? [n] "
);
# FIXME
confirmation
=
self
.
prompt
(
"Also mark subtasks as done? [n] "
)
if
re
.
match
(
'^y(es)?$'
,
confirmation
,
re
.
I
):
for
child
in
children
:
...
...
@@ -34,3 +37,4 @@ class DoCommand(Command.Command):
self
.
_complete_children
()
self
.
_handle_recurrence
()
self
.
todolist
.
set_todo_completed
(
self
.
number
)
self
.
out
(
pretty_print
(
self
.
todo
))
ListCommand.py
View file @
79de0979
...
...
@@ -4,8 +4,11 @@ import Filter
import
Sorter
class
ListCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
ListCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
ListCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
def
execute
(
self
):
showAll
=
self
.
argumentShift
(
"-x"
)
...
...
ListContextCommand.py
View file @
79de0979
import
Command
class
ListContextCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
ListContextCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
ListContextCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
def
execute
(
self
):
for
context
in
sorted
(
self
.
todolist
.
contexts
()):
...
...
ListProjectCommand.py
View file @
79de0979
import
Command
class
ListProjectCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
ListProjectCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
ListProjectCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
def
execute
(
self
):
for
project
in
sorted
(
self
.
todolist
.
projects
()):
...
...
Main.py
View file @
79de0979
...
...
@@ -66,16 +66,13 @@ class Application(object): # TODO: rename to CLIApplication
}
if
subcommand
in
subcommand_map
:
command
=
subcommand_map
[
subcommand
](
arguments
(),
self
.
todolist
)
command
.
execute
()
command
=
subcommand_map
[
subcommand
](
arguments
(),
self
.
todolist
,
lambda
o
:
sys
.
stdout
.
write
(
o
+
"
\
n
"
),
lambda
e
:
sys
.
stderr
.
write
(
e
+
"
\
n
"
),
raw_input
)
if
len
(
command
.
errors
):
text
=
"
\
n
"
.
join
(
command
.
errors
)
sys
.
stderr
.
write
(
text
+
'
\
n
'
)
exit
(
1
)
elif
len
(
command
.
output
):
text
=
"
\
n
"
.
join
(
command
.
output
)
sys
.
stdout
.
write
(
text
+
'
\
n
'
)
if
not
command
.
execute
():
exit
(
1
)
else
:
usage
()
...
...
PriorityCommand.py
View file @
79de0979
...
...
@@ -3,8 +3,11 @@ from PrettyPrinter import pretty_print
from
Utils
import
convert_todo_number
,
is_valid_priority
class
PriorityCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
):
super
(
PriorityCommand
,
self
).
__init__
(
p_args
,
p_todolist
)
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
PriorityCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
number
=
convert_todo_number
(
self
.
argument
(
0
))
self
.
todo
=
self
.
todolist
.
todo
(
self
.
number
)
self
.
priority
=
self
.
argument
(
1
)
...
...
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