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
ebbf3954
Commit
ebbf3954
authored
Jun 11, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #44 from mruwek/expressions-in-multicommand
Expression-mode for del, depri, do, pri, postpone.
parents
9d33afef
a842cb2c
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
457 additions
and
187 deletions
+457
-187
test/DeleteCommandTest.py
test/DeleteCommandTest.py
+60
-6
test/DepriCommandTest.py
test/DepriCommandTest.py
+47
-0
test/DoCommandTest.py
test/DoCommandTest.py
+51
-9
test/EditCommandTest.py
test/EditCommandTest.py
+20
-2
test/PostponeCommandTest.py
test/PostponeCommandTest.py
+50
-0
test/PriorityCommandTest.py
test/PriorityCommandTest.py
+46
-0
topydo/commands/DeleteCommand.py
topydo/commands/DeleteCommand.py
+1
-1
topydo/commands/DepriCommand.py
topydo/commands/DepriCommand.py
+8
-14
topydo/commands/DoCommand.py
topydo/commands/DoCommand.py
+6
-2
topydo/commands/EditCommand.py
topydo/commands/EditCommand.py
+46
-63
topydo/commands/PostponeCommand.py
topydo/commands/PostponeCommand.py
+26
-33
topydo/commands/PriorityCommand.py
topydo/commands/PriorityCommand.py
+19
-22
topydo/lib/DCommand.py
topydo/lib/DCommand.py
+5
-20
topydo/lib/ExpressionCommand.py
topydo/lib/ExpressionCommand.py
+10
-1
topydo/lib/MultiCommand.py
topydo/lib/MultiCommand.py
+62
-14
No files found.
test/DeleteCommandTest.py
View file @
ebbf3954
...
@@ -35,6 +35,8 @@ class DeleteCommandTest(CommandTest):
...
@@ -35,6 +35,8 @@ class DeleteCommandTest(CommandTest):
todos
=
[
todos
=
[
"Foo id:1"
,
"Foo id:1"
,
"Bar p:1"
,
"Bar p:1"
,
"a @test with due:2015-06-03"
,
"a @test with +project"
,
]
]
self
.
todolist
=
TodoList
(
todos
)
self
.
todolist
=
TodoList
(
todos
)
...
@@ -62,7 +64,7 @@ class DeleteCommandTest(CommandTest):
...
@@ -62,7 +64,7 @@ class DeleteCommandTest(CommandTest):
command
.
execute
()
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
todolist
.
count
(),
0
)
self
.
assertEqual
(
self
.
todolist
.
count
(),
2
)
self
.
assertEqual
(
self
.
output
,
"| 2| Bar p:1
\
n
Removed: Bar
\
n
Removed: Foo
\
n
"
)
self
.
assertEqual
(
self
.
output
,
"| 2| Bar p:1
\
n
Removed: Bar
\
n
Removed: Foo
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
...
@@ -71,7 +73,7 @@ class DeleteCommandTest(CommandTest):
...
@@ -71,7 +73,7 @@ class DeleteCommandTest(CommandTest):
command
.
execute
()
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
todolist
.
count
(),
1
)
# force won't delete subtasks
self
.
assertEqual
(
self
.
todolist
.
count
(),
3
)
# force won't delete subtasks
self
.
assertEqual
(
self
.
output
,
"| 2| Bar p:1
\
n
Removed: Foo id:1
\
n
"
)
self
.
assertEqual
(
self
.
output
,
"| 2| Bar p:1
\
n
Removed: Foo id:1
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
...
@@ -80,7 +82,7 @@ class DeleteCommandTest(CommandTest):
...
@@ -80,7 +82,7 @@ class DeleteCommandTest(CommandTest):
command
.
execute
()
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
todolist
.
count
(),
1
)
# force won't delete subtasks
self
.
assertEqual
(
self
.
todolist
.
count
(),
3
)
# force won't delete subtasks
self
.
assertEqual
(
self
.
output
,
"| 2| Bar p:1
\
n
Removed: Foo id:1
\
n
"
)
self
.
assertEqual
(
self
.
output
,
"| 2| Bar p:1
\
n
Removed: Foo id:1
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
...
@@ -116,7 +118,9 @@ class DeleteCommandTest(CommandTest):
...
@@ -116,7 +118,9 @@ class DeleteCommandTest(CommandTest):
command
=
DeleteCommand
([
"8to"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
=
DeleteCommand
([
"8to"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
command
.
execute
()
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
"Foo"
)
result
=
"Foo
\
n
a @test with due:2015-06-03
\
n
a @test with +project"
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
result
)
self
.
assertRaises
(
InvalidTodoException
,
self
.
todolist
.
todo
,
'b0n'
)
self
.
assertRaises
(
InvalidTodoException
,
self
.
todolist
.
todo
,
'b0n'
)
def
test_multi_del1
(
self
):
def
test_multi_del1
(
self
):
...
@@ -124,14 +128,20 @@ class DeleteCommandTest(CommandTest):
...
@@ -124,14 +128,20 @@ class DeleteCommandTest(CommandTest):
command
=
DeleteCommand
([
"1"
,
"2"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
=
DeleteCommand
([
"1"
,
"2"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
.
execute
()
command
.
execute
()
self
.
assertEqual
(
self
.
todolist
.
count
(),
0
)
result
=
"a @test with due:2015-06-03
\
n
a @test with +project"
self
.
assertEqual
(
self
.
todolist
.
count
(),
2
)
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
result
)
def
test_multi_del2
(
self
):
def
test_multi_del2
(
self
):
""" Test deletion of multiple items. """
""" Test deletion of multiple items. """
command
=
DeleteCommand
([
"1"
,
"2"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_yes_prompt
)
command
=
DeleteCommand
([
"1"
,
"2"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_yes_prompt
)
command
.
execute
()
command
.
execute
()
self
.
assertEqual
(
self
.
todolist
.
count
(),
0
)
result
=
"a @test with due:2015-06-03
\
n
a @test with +project"
self
.
assertEqual
(
self
.
todolist
.
count
(),
2
)
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
result
)
def
test_multi_del3
(
self
):
def
test_multi_del3
(
self
):
""" Fail if any of supplied todo numbers is invalid. """
""" Fail if any of supplied todo numbers is invalid. """
...
@@ -160,6 +170,50 @@ class DeleteCommandTest(CommandTest):
...
@@ -160,6 +170,50 @@ class DeleteCommandTest(CommandTest):
self
.
assertEqual
(
self
.
output
,
""
)
self
.
assertEqual
(
self
.
output
,
""
)
self
.
assertEqual
(
self
.
errors
,
u
(
"Invalid todo number given: Fo
\
u00d3
B
\
u0105
r.
\
n
"
))
self
.
assertEqual
(
self
.
errors
,
u
(
"Invalid todo number given: Fo
\
u00d3
B
\
u0105
r.
\
n
"
))
def
test_expr_del1
(
self
):
command
=
DeleteCommand
([
"-e"
,
"@test"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
result
=
"Removed: a @test with due:2015-06-03
\
n
Removed: a @test with +project
\
n
"
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
todolist
.
count
(),
2
)
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_del2
(
self
):
command
=
DeleteCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"Removed: a @test with due:2015-06-03
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_del3
(
self
):
command
=
DeleteCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
,
"+project"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_del4
(
self
):
""" Remove only relevant todo items. """
command
=
DeleteCommand
([
"-e"
,
""
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
result
=
"Foo"
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
todolist
.
count
(),
1
)
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
result
)
def
test_expr_del5
(
self
):
""" Force deleting unrelevant items with additional -x flag. """
command
=
DeleteCommand
([
"-xe"
,
""
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_yes_prompt
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
todolist
.
count
(),
0
)
def
test_empty
(
self
):
def
test_empty
(
self
):
command
=
DeleteCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
=
DeleteCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
command
.
execute
()
...
...
test/DepriCommandTest.py
View file @
ebbf3954
...
@@ -28,6 +28,9 @@ class DepriCommandTest(CommandTest):
...
@@ -28,6 +28,9 @@ class DepriCommandTest(CommandTest):
"(A) Foo"
,
"(A) Foo"
,
"Bar"
,
"Bar"
,
"(B) Baz"
,
"(B) Baz"
,
"(E) a @test with due:2015-06-03"
,
"(Z) a @test with +project p:1"
,
"(D) Bax id:1"
,
]
]
self
.
todolist
=
TodoList
(
todos
)
self
.
todolist
=
TodoList
(
todos
)
...
@@ -69,6 +72,50 @@ class DepriCommandTest(CommandTest):
...
@@ -69,6 +72,50 @@ class DepriCommandTest(CommandTest):
self
.
assertEqual
(
self
.
output
,
"Priority removed.
\
n
| 1| Foo
\
n
Priority removed.
\
n
| 3| Baz
\
n
"
)
self
.
assertEqual
(
self
.
output
,
"Priority removed.
\
n
| 1| Foo
\
n
Priority removed.
\
n
| 3| Baz
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_depri1
(
self
):
command
=
DepriCommand
([
"-e"
,
"@test"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
result
=
"Priority removed.
\
n
| 4| a @test with due:2015-06-03
\
n
Priority removed.
\
n
| 5| a @test with +project p:1
\
n
"
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_depri2
(
self
):
command
=
DepriCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
result
=
"Priority removed.
\
n
| 4| a @test with due:2015-06-03
\
n
"
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_depri3
(
self
):
command
=
DepriCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
,
"+project"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_depri4
(
self
):
""" Don't remove priority from unrelevant todo items. """
command
=
DepriCommand
([
"-e"
,
"Bax"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_depri5
(
self
):
""" Force unprioritizing unrelevant items with additional -x flag. """
command
=
DepriCommand
([
"-xe"
,
"Bax"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"Priority removed.
\
n
| 6| Bax id:1
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_invalid1
(
self
):
def
test_invalid1
(
self
):
command
=
DepriCommand
([
"99"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
=
DepriCommand
([
"99"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
...
...
test/DoCommandTest.py
View file @
ebbf3954
...
@@ -41,6 +41,8 @@ class DoCommandTest(CommandTest):
...
@@ -41,6 +41,8 @@ class DoCommandTest(CommandTest):
"Subtodo of inactive p:2"
,
"Subtodo of inactive p:2"
,
"Strict due:2014-01-01 rec:1d"
,
"Strict due:2014-01-01 rec:1d"
,
"Invalid rec:1"
,
"Invalid rec:1"
,
"a @test with due:2015-06-03"
,
"a @test with +project"
,
]
]
self
.
todolist
=
TodoList
(
todos
)
self
.
todolist
=
TodoList
(
todos
)
...
@@ -123,7 +125,7 @@ class DoCommandTest(CommandTest):
...
@@ -123,7 +125,7 @@ class DoCommandTest(CommandTest):
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
todolist
.
count
(),
1
0
)
self
.
assertEqual
(
self
.
todolist
.
count
(),
1
2
)
def
test_recurrence
(
self
):
def
test_recurrence
(
self
):
self
.
assertFalse
(
self
.
todolist
.
todo
(
4
).
has_tag
(
'due'
))
self
.
assertFalse
(
self
.
todolist
.
todo
(
4
).
has_tag
(
'due'
))
...
@@ -131,7 +133,7 @@ class DoCommandTest(CommandTest):
...
@@ -131,7 +133,7 @@ class DoCommandTest(CommandTest):
self
.
_recurrence_helper
([
"4"
])
self
.
_recurrence_helper
([
"4"
])
self
.
assertTrue
(
self
.
todolist
.
todo
(
4
).
is_completed
())
self
.
assertTrue
(
self
.
todolist
.
todo
(
4
).
is_completed
())
result
=
"| 1
0
| {today} Recurring! rec:1d due:{tomorrow}
\
n
Completed: x {today} Recurring! rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
tomorrow
=
self
.
tomorrow
)
result
=
"| 1
2
| {today} Recurring! rec:1d due:{tomorrow}
\
n
Completed: x {today} Recurring! rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
tomorrow
=
self
.
tomorrow
)
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
output
,
result
)
todo
=
self
.
todolist
.
todo
(
10
)
todo
=
self
.
todolist
.
todo
(
10
)
...
@@ -140,13 +142,13 @@ class DoCommandTest(CommandTest):
...
@@ -140,13 +142,13 @@ class DoCommandTest(CommandTest):
def
test_strict_recurrence1
(
self
):
def
test_strict_recurrence1
(
self
):
self
.
_recurrence_helper
([
"-s"
,
"8"
])
self
.
_recurrence_helper
([
"-s"
,
"8"
])
result
=
"| 1
0
| {today} Strict due:2014-01-02 rec:1d
\
n
Completed: x {today} Strict due:2014-01-01 rec:1d
\
n
"
.
format
(
today
=
self
.
today
)
result
=
"| 1
2
| {today} Strict due:2014-01-02 rec:1d
\
n
Completed: x {today} Strict due:2014-01-01 rec:1d
\
n
"
.
format
(
today
=
self
.
today
)
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
output
,
result
)
def
test_strict_recurrence2
(
self
):
def
test_strict_recurrence2
(
self
):
self
.
_recurrence_helper
([
"--strict"
,
"8"
])
self
.
_recurrence_helper
([
"--strict"
,
"8"
])
result
=
"| 1
0
| {today} Strict due:2014-01-02 rec:1d
\
n
Completed: x {today} Strict due:2014-01-01 rec:1d
\
n
"
.
format
(
today
=
self
.
today
)
result
=
"| 1
2
| {today} Strict due:2014-01-02 rec:1d
\
n
Completed: x {today} Strict due:2014-01-01 rec:1d
\
n
"
.
format
(
today
=
self
.
today
)
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
output
,
result
)
def
test_invalid1
(
self
):
def
test_invalid1
(
self
):
...
@@ -254,7 +256,7 @@ class DoCommandTest(CommandTest):
...
@@ -254,7 +256,7 @@ class DoCommandTest(CommandTest):
command
.
execute
()
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"| 1
0
| {today} Recurring! rec:1d due:{today}
\
n
Completed: x {yesterday} Recurring! rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
yesterday
=
self
.
yesterday
))
self
.
assertEqual
(
self
.
output
,
"| 1
2
| {today} Recurring! rec:1d due:{today}
\
n
Completed: x {yesterday} Recurring! rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
yesterday
=
self
.
yesterday
))
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_do_custom_date6
(
self
):
def
test_do_custom_date6
(
self
):
...
@@ -267,7 +269,7 @@ class DoCommandTest(CommandTest):
...
@@ -267,7 +269,7 @@ class DoCommandTest(CommandTest):
command
.
execute
()
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"| 1
0
| {today} Recurring! rec:1d due:{today}
\
n
Completed: x {yesterday} Recurring! rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
yesterday
=
self
.
yesterday
))
self
.
assertEqual
(
self
.
output
,
"| 1
2
| {today} Recurring! rec:1d due:{today}
\
n
Completed: x {yesterday} Recurring! rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
yesterday
=
self
.
yesterday
))
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_do_custom_date7
(
self
):
def
test_do_custom_date7
(
self
):
...
@@ -279,7 +281,7 @@ class DoCommandTest(CommandTest):
...
@@ -279,7 +281,7 @@ class DoCommandTest(CommandTest):
command
.
execute
()
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"| 1
0
| {today} Strict due:2014-01-02 rec:1d
\
n
Completed: x {yesterday} Strict due:2014-01-01 rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
yesterday
=
self
.
yesterday
))
self
.
assertEqual
(
self
.
output
,
"| 1
2
| {today} Strict due:2014-01-02 rec:1d
\
n
Completed: x {yesterday} Strict due:2014-01-01 rec:1d
\
n
"
.
format
(
today
=
self
.
today
,
yesterday
=
self
.
yesterday
))
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_multi_do1
(
self
):
def
test_multi_do1
(
self
):
...
@@ -320,10 +322,10 @@ class DoCommandTest(CommandTest):
...
@@ -320,10 +322,10 @@ class DoCommandTest(CommandTest):
"""
"""
Check output when all supplied todo numbers are invalid.
Check output when all supplied todo numbers are invalid.
"""
"""
command
=
DoCommand
([
"99"
,
"1
0
"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
=
DoCommand
([
"99"
,
"1
5
"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
.
execute
()
command
.
execute
()
self
.
assertEqual
(
self
.
errors
,
"Invalid todo number given: 99.
\
n
Invalid todo number given: 1
0
.
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
"Invalid todo number given: 99.
\
n
Invalid todo number given: 1
5
.
\
n
"
)
def
test_multi_do6
(
self
):
def
test_multi_do6
(
self
):
""" Throw an error with invalid argument containing special characters. """
""" Throw an error with invalid argument containing special characters. """
...
@@ -333,6 +335,46 @@ class DoCommandTest(CommandTest):
...
@@ -333,6 +335,46 @@ class DoCommandTest(CommandTest):
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
errors
,
u
(
"Invalid todo number given: Fo
\
u00d3
B
\
u0105
r.
\
n
"
))
self
.
assertEqual
(
self
.
errors
,
u
(
"Invalid todo number given: Fo
\
u00d3
B
\
u0105
r.
\
n
"
))
def
test_expr_do1
(
self
):
command
=
DoCommand
([
"-e"
,
"@test"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"Completed: x {t} a @test with due:2015-06-03
\
n
Completed: x {t} a @test with +project
\
n
"
.
format
(
t
=
self
.
today
))
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_do2
(
self
):
command
=
DoCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"Completed: x {} a @test with due:2015-06-03
\
n
"
.
format
(
self
.
today
))
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_do3
(
self
):
command
=
DoCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
,
"+project"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_do4
(
self
):
""" Don't do anything with unrelevant todo items. """
command
=
DoCommand
([
"-e"
,
"Foo"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_do5
(
self
):
""" Force marking unrelevant items as done with additional -x flag. """
command
=
DoCommand
([
"-xe"
,
"Foo"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_yes_prompt
)
command
.
execute
()
result
=
"| 2| Bar p:1
\
n
| 3| Baz p:1
\
n
Completed: x {t} Bar p:1
\
n
Completed: x {t} Baz p:1
\
n
Completed: x {t} Foo id:1
\
n
"
.
format
(
t
=
self
.
today
)
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_invalid_recurrence
(
self
):
def
test_invalid_recurrence
(
self
):
""" Show error message when an item has an invalid recurrence pattern. """
""" Show error message when an item has an invalid recurrence pattern. """
command
=
DoCommand
([
"9"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
command
=
DoCommand
([
"9"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
_no_prompt
)
...
...
test/EditCommandTest.py
View file @
ebbf3954
...
@@ -139,7 +139,7 @@ class EditCommandTest(CommandTest):
...
@@ -139,7 +139,7 @@ class EditCommandTest(CommandTest):
self
.
assertEqual
(
self
.
output
,
expected
)
self
.
assertEqual
(
self
.
output
,
expected
)
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
u
(
"Foo id:1
\
n
Fo
\
u00f3
B
\
u0105
\
u017a
\
n
Lazy Cat
\
n
Lazy Dog"
))
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
u
(
"Foo id:1
\
n
Fo
\
u00f3
B
\
u0105
\
u017a
\
n
Lazy Cat
\
n
Lazy Dog"
))
@
mock
.
patch
(
'topydo.commands.EditCommand.call'
)
@
mock
.
patch
(
'topydo.commands.EditCommand.c
heck_c
all'
)
def
test_edit_archive
(
self
,
mock_call
):
def
test_edit_archive
(
self
,
mock_call
):
""" Edit archive file. """
""" Edit archive file. """
mock_call
.
return_value
=
0
mock_call
.
return_value
=
0
...
@@ -148,11 +148,29 @@ class EditCommandTest(CommandTest):
...
@@ -148,11 +148,29 @@ class EditCommandTest(CommandTest):
os
.
environ
[
'EDITOR'
]
=
editor
os
.
environ
[
'EDITOR'
]
=
editor
archive
=
config
().
archive
()
archive
=
config
().
archive
()
command
=
EditCommand
([
u
(
"-d"
)
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
=
EditCommand
([
"-d"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
command
.
execute
()
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
mock_call
.
assert_called_once_with
([
editor
,
archive
])
mock_call
.
assert_called_once_with
([
editor
,
archive
])
@
mock
.
patch
(
'topydo.commands.EditCommand.check_call'
)
def
test_edit_todotxt
(
self
,
mock_call
):
""" Edit todo file. """
mock_call
.
return_value
=
0
editor
=
'vi'
os
.
environ
[
'EDITOR'
]
=
editor
todotxt
=
config
().
todotxt
()
result
=
self
.
todolist
.
print_todos
()
# copy TodoList content *before* executing command
command
=
EditCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
todolist
.
print_todos
(),
result
)
mock_call
.
assert_called_once_with
([
editor
,
todotxt
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
test/PostponeCommandTest.py
View file @
ebbf3954
...
@@ -37,6 +37,7 @@ class PostponeCommandTest(CommandTest):
...
@@ -37,6 +37,7 @@ class PostponeCommandTest(CommandTest):
"Baz due:{} t:{}"
.
format
(
self
.
today
.
isoformat
(),
self
.
start
.
isoformat
()),
"Baz due:{} t:{}"
.
format
(
self
.
today
.
isoformat
(),
self
.
start
.
isoformat
()),
"Past due:{}"
.
format
(
self
.
past
.
isoformat
()),
"Past due:{}"
.
format
(
self
.
past
.
isoformat
()),
"Future due:{} t:{}"
.
format
(
self
.
future
.
isoformat
(),
self
.
future_start
.
isoformat
()),
"Future due:{} t:{}"
.
format
(
self
.
future
.
isoformat
(),
self
.
future_start
.
isoformat
()),
"FutureStart t:{}"
.
format
(
self
.
future
.
isoformat
())
]
]
self
.
todolist
=
TodoList
(
todos
)
self
.
todolist
=
TodoList
(
todos
)
...
@@ -233,6 +234,55 @@ class PostponeCommandTest(CommandTest):
...
@@ -233,6 +234,55 @@ class PostponeCommandTest(CommandTest):
self
.
assertEqual
(
self
.
output
,
""
)
self
.
assertEqual
(
self
.
output
,
""
)
self
.
assertEqual
(
self
.
errors
,
u
(
"Invalid todo number given: Fo
\
u00d3
B
\
u0105
r.
\
n
"
))
self
.
assertEqual
(
self
.
errors
,
u
(
"Invalid todo number given: Fo
\
u00d3
B
\
u0105
r.
\
n
"
))
def
test_expr_postpone1
(
self
):
command
=
PostponeCommand
([
"-e"
,
"due:tod"
,
"2w"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
due
=
self
.
today
+
timedelta
(
14
)
result
=
"| 2| Bar due:{d}
\
n
| 3| Baz due:{d} t:{s}
\
n
"
.
format
(
d
=
due
.
isoformat
(),
s
=
self
.
start
.
isoformat
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_postpone2
(
self
):
cmd_args
=
[
"-e"
,
"t:{}"
.
format
(
self
.
start
.
isoformat
()),
"due:tod"
,
"1w"
]
command
=
PostponeCommand
(
cmd_args
,
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
due
=
self
.
today
+
timedelta
(
7
)
result
=
"| 3| Baz due:{} t:{}
\
n
"
.
format
(
due
.
isoformat
(),
self
.
start
.
isoformat
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_postpone3
(
self
):
command
=
PostponeCommand
([
"-e"
,
"@test"
,
"due:tod"
,
"+project"
,
"C"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_postpone4
(
self
):
""" Don't postpone unrelevant todo items. """
command
=
PostponeCommand
([
"-e"
,
"FutureStart"
,
"1w"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_postpone5
(
self
):
""" Force postponing unrelevant items with additional -x flag. """
command
=
PostponeCommand
([
"-xe"
,
"FutureStart"
,
"1w"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
due
=
self
.
today
+
timedelta
(
7
)
result
=
"| 6| FutureStart t:{} due:{}
\
n
"
.
format
(
self
.
future
.
isoformat
(),
due
.
isoformat
())
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_help
(
self
):
def
test_help
(
self
):
command
=
PostponeCommand
([
"help"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
=
PostponeCommand
([
"help"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
command
.
execute
()
...
...
test/PriorityCommandTest.py
View file @
ebbf3954
...
@@ -27,6 +27,9 @@ class PriorityCommandTest(CommandTest):
...
@@ -27,6 +27,9 @@ class PriorityCommandTest(CommandTest):
todos
=
[
todos
=
[
"(A) Foo"
,
"(A) Foo"
,
"Bar"
,
"Bar"
,
"(B) a @test with due:2015-06-03"
,
"a @test with +project p:1"
,
"Baz id:1"
,
]
]
self
.
todolist
=
TodoList
(
todos
)
self
.
todolist
=
TodoList
(
todos
)
...
@@ -71,6 +74,49 @@ class PriorityCommandTest(CommandTest):
...
@@ -71,6 +74,49 @@ class PriorityCommandTest(CommandTest):
self
.
assertEqual
(
self
.
output
,
"Priority changed from A to C
\
n
| 1| (C) Foo
\
n
Priority set to C.
\
n
| 2| (C) Bar
\
n
"
)
self
.
assertEqual
(
self
.
output
,
"Priority changed from A to C
\
n
| 1| (C) Foo
\
n
Priority set to C.
\
n
| 2| (C) Bar
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_prio1
(
self
):
command
=
PriorityCommand
([
"-e"
,
"@test"
,
"C"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
result
=
"Priority changed from B to C
\
n
| 3| (C) a @test with due:2015-06-03
\
n
Priority set to C.
\
n
| 4| (C) a @test with +project p:1
\
n
"
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_prio2
(
self
):
command
=
PriorityCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
,
"C"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
result
=
"Priority changed from B to C
\
n
| 3| (C) a @test with due:2015-06-03
\
n
"
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
result
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_expr_prio3
(
self
):
command
=
PriorityCommand
([
"-e"
,
"@test"
,
"due:2015-06-03"
,
"+project"
,
"C"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_prio4
(
self
):
""" Don't prioritize unrelevant todo items. """
command
=
PriorityCommand
([
"-e"
,
"Baz"
,
"C"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
def
test_expr_prio5
(
self
):
""" Force prioritizing unrelevant items with additional -x flag. """
command
=
PriorityCommand
([
"-xe"
,
"Baz"
,
"D"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
None
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEqual
(
self
.
output
,
"Priority set to D.
\
n
| 5| (D) Baz id:1
\
n
"
)
self
.
assertEqual
(
self
.
errors
,
""
)
def
test_invalid1
(
self
):
def
test_invalid1
(
self
):
command
=
PriorityCommand
([
"99"
,
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
=
PriorityCommand
([
"99"
,
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
command
.
execute
()
...
...
topydo/commands/DeleteCommand.py
View file @
ebbf3954
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
topydo.
commands
.DCommand
import
DCommand
from
topydo.
lib
.DCommand
import
DCommand
class
DeleteCommand
(
DCommand
):
class
DeleteCommand
(
DCommand
):
def
__init__
(
self
,
p_args
,
p_todolist
,
def
__init__
(
self
,
p_args
,
p_todolist
,
...
...
topydo/commands/DepriCommand.py
View file @
ebbf3954
...
@@ -25,20 +25,14 @@ class DepriCommand(MultiCommand):
...
@@ -25,20 +25,14 @@ class DepriCommand(MultiCommand):
super
(
DepriCommand
,
self
).
__init__
(
super
(
DepriCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
get_todos
(
self
.
args
)
def
_execute_multi_specific
(
self
):
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
def
execute_multi_specific
(
self
):
try
:
for
todo
in
self
.
todos
:
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
if
todo
.
priority
()
!=
None
:
self
.
todolist
.
set_priority
(
todo
,
None
)
for
todo
in
self
.
todos
:
self
.
out
(
"Priority removed."
)
if
todo
.
priority
()
!=
None
:
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
self
.
todolist
.
set_priority
(
todo
,
None
)
self
.
out
(
"Priority removed."
)
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
except
IndexError
:
self
.
error
(
self
.
usage
())
def
usage
(
self
):
def
usage
(
self
):
return
"""Synopsis: depri <NUMBER1> [<NUMBER2> ...]"""
return
"""Synopsis: depri <NUMBER1> [<NUMBER2> ...]"""
...
...
topydo/commands/DoCommand.py
View file @
ebbf3954
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
from
datetime
import
date
from
datetime
import
date
from
topydo.
commands
.DCommand
import
DCommand
from
topydo.
lib
.DCommand
import
DCommand
from
topydo.lib.PrettyPrinter
import
PrettyPrinter
from
topydo.lib.PrettyPrinter
import
PrettyPrinter
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.Recurrence
import
advance_recurring_todo
,
strict_advance_recurring_todo
,
NoRecurrenceException
from
topydo.lib.Recurrence
import
advance_recurring_todo
,
strict_advance_recurring_todo
,
NoRecurrenceException
...
@@ -36,9 +36,13 @@ class DoCommand(DCommand):
...
@@ -36,9 +36,13 @@ class DoCommand(DCommand):
def
get_flags
(
self
):
def
get_flags
(
self
):
""" Additional flags. """
""" Additional flags. """
return
(
"d:s"
,
[
"date="
,
"strict"
])
opts
,
long_opts
=
super
(
DoCommand
,
self
).
get_flags
()
return
(
"d:s"
+
opts
,
[
"date="
,
"strict"
]
+
long_opts
)
def
process_flag
(
self
,
p_opt
,
p_value
):
def
process_flag
(
self
,
p_opt
,
p_value
):
super
(
DoCommand
,
self
).
process_flag
(
p_opt
,
p_value
)
if
p_opt
==
"-s"
or
p_opt
==
"--strict"
:
if
p_opt
==
"-s"
or
p_opt
==
"--strict"
:
self
.
strict_recurrence
=
True
self
.
strict_recurrence
=
True
elif
p_opt
==
"-d"
or
p_opt
==
"--date"
:
elif
p_opt
==
"-d"
or
p_opt
==
"--date"
:
...
...
topydo/commands/EditCommand.py
View file @
ebbf3954
...
@@ -34,26 +34,25 @@ DEFAULT_EDITOR = 'vi'
...
@@ -34,26 +34,25 @@ DEFAULT_EDITOR = 'vi'
# cannot use super() inside the class itself
# cannot use super() inside the class itself
BASE_TODOLIST
=
lambda
tl
:
super
(
TodoList
,
tl
)
BASE_TODOLIST
=
lambda
tl
:
super
(
TodoList
,
tl
)
class
EditCommand
(
MultiCommand
,
ExpressionCommand
):
class
EditCommand
(
MultiCommand
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_output
,
p_error
,
p_input
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_output
,
p_error
,
p_input
):
super
(
EditCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_output
,
super
(
EditCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_output
,
p_error
,
p_input
)
p_error
,
p_input
)
if
len
(
self
.
args
)
==
0
:
self
.
multi_mode
=
False
self
.
is_expression
=
False
self
.
is_expression
=
False
self
.
edit_archive
=
False
self
.
edit_archive
=
False
self
.
last_argument
=
False
def
_process_flags
(
self
):
def
get_flags
(
self
):
opts
,
args
=
self
.
getopt
(
'xed'
)
return
(
"d"
,
[])
for
opt
,
value
in
opts
:
if
opt
==
'-d'
:
self
.
edit_archive
=
True
elif
opt
==
'-x'
:
self
.
show_all
=
True
elif
opt
==
'-e'
:
self
.
is_expression
=
True
self
.
args
=
args
def
process_flag
(
self
,
p_opt
,
p_value
):
if
p_opt
==
'-d'
:
self
.
edit_archive
=
True
self
.
multi_mode
=
False
def
_todos_to_temp
(
self
):
def
_todos_to_temp
(
self
):
f
=
tempfile
.
NamedTemporaryFile
()
f
=
tempfile
.
NamedTemporaryFile
()
...
@@ -73,12 +72,20 @@ class EditCommand(MultiCommand, ExpressionCommand):
...
@@ -73,12 +72,20 @@ class EditCommand(MultiCommand, ExpressionCommand):
return
todo_objs
return
todo_objs
def
_open_in_editor
(
self
,
p_temp_file
,
p_editor
):
def
_open_in_editor
(
self
,
p_file
):
try
:
editor
=
os
.
environ
[
'EDITOR'
]
or
DEFAULT_EDITOR
except
(
KeyError
):
editor
=
DEFAULT_EDITOR
try
:
try
:
return
check_call
([
p_editor
,
p_temp_file
.
nam
e
])
return
check_call
([
editor
,
p_fil
e
])
except
CalledProcessError
:
except
CalledProcessError
:
self
.
error
(
'Something went wrong in the editor...'
)
self
.
error
(
'Something went wrong in the editor...'
)
return
1
return
1
except
(
OSError
):
self
.
error
(
'There is no such editor as: '
+
editor
+
'. '
'Check your $EDITOR and/or $PATH'
)
def
_catch_todo_errors
(
self
):
def
_catch_todo_errors
(
self
):
errors
=
[]
errors
=
[]
...
@@ -94,59 +101,35 @@ class EditCommand(MultiCommand, ExpressionCommand):
...
@@ -94,59 +101,35 @@ class EditCommand(MultiCommand, ExpressionCommand):
else
:
else
:
return
None
return
None
def
execute
(
self
):
def
_execute_multi_specific
(
self
):
if
not
super
(
EditCommand
,
self
).
execute
():
return
False
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
try
:
editor
=
os
.
environ
[
'EDITOR'
]
or
DEFAULT_EDITOR
except
(
KeyError
):
editor
=
DEFAULT_EDITOR
try
:
temp_todos
=
self
.
_todos_to_temp
()
if
len
(
self
.
args
)
<
1
:
todo
=
config
().
todotxt
()
return
call
([
editor
,
todo
])
==
0
if
not
self
.
_open_in_editor
(
temp_todos
.
name
):
new_todos
=
self
.
_todos_from_temp
(
temp_todos
)
if
len
(
new_todos
)
==
len
(
self
.
todos
):
for
todo
in
self
.
todos
:
BASE_TODOLIST
(
self
.
todolist
).
delete
(
todo
)
for
todo
in
new_todos
:
self
.
todolist
.
add_todo
(
todo
)
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
else
:
else
:
self
.
_process_flags
()
self
.
error
(
'Number of edited todos is not equal to '
'number of supplied todo IDs.'
)
if
self
.
edit_archive
:
else
:
archive
=
config
().
archive
()
self
.
error
(
self
.
usage
())
return
call
([
editor
,
archive
])
==
0
def
_execute_not_multi
(
self
):
if
self
.
edit_archive
:
if
self
.
is_expression
:
archive
=
config
().
archive
()
self
.
todos
=
self
.
_view
().
todos
else
:
return
self
.
_open_in_editor
(
archive
)
==
0
self
.
get_todos
(
self
.
args
)
else
:
todo
=
config
().
todotxt
()
todo_errors
=
self
.
_catch_todo_errors
()
return
self
.
_open_in_editor
(
todo
)
==
0
if
not
todo_errors
:
temp_todos
=
self
.
_todos_to_temp
()
if
not
self
.
_open_in_editor
(
temp_todos
,
editor
):
new_todos
=
self
.
_todos_from_temp
(
temp_todos
)
if
len
(
new_todos
)
==
len
(
self
.
todos
):
for
todo
in
self
.
todos
:
BASE_TODOLIST
(
self
.
todolist
).
delete
(
todo
)
for
todo
in
new_todos
:
self
.
todolist
.
add_todo
(
todo
)
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
else
:
self
.
error
(
'Number of edited todos is not equal to '
'number of supplied todo IDs.'
)
else
:
self
.
error
(
self
.
usage
())
else
:
for
error
in
todo_errors
:
self
.
error
(
error
)
except
(
OSError
):
self
.
error
(
'There is no such editor as: '
+
editor
+
'. '
'Check your $EDITOR and/or $PATH'
)
def
usage
(
self
):
def
usage
(
self
):
return
"""Synopsis:
return
"""Synopsis:
...
...
topydo/commands/PostponeCommand.py
View file @
ebbf3954
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
from
datetime
import
date
,
timedelta
from
datetime
import
date
,
timedelta
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.Command
import
InvalidCommandArgument
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.RelativeDate
import
relative_date_to_date
from
topydo.lib.RelativeDate
import
relative_date_to_date
...
@@ -32,19 +31,16 @@ class PostponeCommand(MultiCommand):
...
@@ -32,19 +31,16 @@ class PostponeCommand(MultiCommand):
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
move_start_date
=
False
self
.
move_start_date
=
False
self
.
_process_flags
()
self
.
last_argument
=
True
self
.
get_todos
(
self
.
args
[:
-
1
])
def
_process
_flags
(
self
):
def
get
_flags
(
self
):
opts
,
args
=
self
.
getopt
(
's'
)
return
(
"s"
,
[]
)
for
opt
,
_
in
opts
:
def
process_flag
(
self
,
p_opt
,
p_value
)
:
if
opt
==
'-s'
:
if
p_
opt
==
'-s'
:
self
.
move_start_date
=
True
self
.
move_start_date
=
True
self
.
args
=
args
def
_execute_multi_specific
(
self
):
def
execute_multi_specific
(
self
):
def
_get_offset
(
p_todo
):
def
_get_offset
(
p_todo
):
offset
=
p_todo
.
tag_value
(
offset
=
p_todo
.
tag_value
(
config
().
tag_due
(),
date
.
today
().
isoformat
())
config
().
tag_due
(),
date
.
today
().
isoformat
())
...
@@ -55,31 +51,28 @@ class PostponeCommand(MultiCommand):
...
@@ -55,31 +51,28 @@ class PostponeCommand(MultiCommand):
return
offset_date
return
offset_date
try
:
pattern
=
self
.
args
[
-
1
]
pattern
=
self
.
args
[
-
1
]
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
for
todo
in
self
.
todos
:
offset
=
_get_offset
(
todo
)
new_due
=
relative_date_to_date
(
pattern
,
offset
)
if
new_due
:
for
todo
in
self
.
todos
:
if
self
.
move_start_date
and
todo
.
has_tag
(
config
().
tag_start
()):
offset
=
_get_offset
(
todo
)
length
=
todo
.
length
()
new_due
=
relative_date_to_date
(
pattern
,
offset
)
new_start
=
new_due
-
timedelta
(
length
)
# pylint: disable=E1103
todo
.
set_tag
(
config
().
tag_start
(),
new_start
.
isoformat
())
if
new_due
:
if
self
.
move_start_date
and
todo
.
has_tag
(
config
().
tag_start
()):
length
=
todo
.
length
()
new_start
=
new_due
-
timedelta
(
length
)
# pylint: disable=E1103
# pylint: disable=E1103
todo
.
set_tag
(
config
().
tag_due
(),
new_due
.
isoformat
())
todo
.
set_tag
(
config
().
tag_start
(),
new_start
.
isoformat
())
self
.
todolist
.
set_dirty
()
# pylint: disable=E1103
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
todo
.
set_tag
(
config
().
tag_due
(),
new_due
.
isoformat
())
else
:
self
.
error
(
"Invalid date pattern given."
)
self
.
todolist
.
set_dirty
()
break
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
except
(
InvalidCommandArgument
,
IndexError
):
else
:
self
.
error
(
self
.
usage
())
self
.
error
(
"Invalid date pattern given."
)
break
def
usage
(
self
):
def
usage
(
self
):
return
"Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>"
return
"Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>"
...
...
topydo/commands/PriorityCommand.py
View file @
ebbf3954
...
@@ -26,31 +26,28 @@ class PriorityCommand(MultiCommand):
...
@@ -26,31 +26,28 @@ class PriorityCommand(MultiCommand):
super
(
PriorityCommand
,
self
).
__init__
(
super
(
PriorityCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
get_todos
(
self
.
args
[:
-
1
])
self
.
last_argument
=
True
def
execute_multi_specific
(
self
):
def
_
execute_multi_specific
(
self
):
priority
=
None
priority
=
None
try
:
priority
=
self
.
args
[
-
1
]
priority
=
self
.
args
[
-
1
]
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
if
is_valid_priority
(
priority
):
if
is_valid_priority
(
priority
):
for
todo
in
self
.
todos
:
for
todo
in
self
.
todos
:
old_priority
=
todo
.
priority
()
old_priority
=
todo
.
priority
()
self
.
todolist
.
set_priority
(
todo
,
priority
)
self
.
todolist
.
set_priority
(
todo
,
priority
)
if
old_priority
and
priority
and
old_priority
!=
priority
:
if
old_priority
and
priority
and
old_priority
!=
priority
:
self
.
out
(
"Priority changed from {} to {}"
.
format
(
self
.
out
(
"Priority changed from {} to {}"
.
format
(
old_priority
,
priority
))
old_priority
,
priority
))
elif
not
old_priority
:
elif
not
old_priority
:
self
.
out
(
"Priority set to {}."
.
format
(
priority
))
self
.
out
(
"Priority set to {}."
.
format
(
priority
))
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
self
.
out
(
self
.
printer
.
print_todo
(
todo
))
else
:
else
:
self
.
error
(
"Invalid priority given."
)
self
.
error
(
"Invalid priority given."
)
except
IndexError
:
self
.
error
(
self
.
usage
())
def
usage
(
self
):
def
usage
(
self
):
return
"""Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>"""
return
"""Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>"""
...
...
topydo/
commands
/DCommand.py
→
topydo/
lib
/DCommand.py
View file @
ebbf3954
...
@@ -35,29 +35,14 @@ class DCommand(MultiCommand):
...
@@ -35,29 +35,14 @@ class DCommand(MultiCommand):
self
.
force
=
False
self
.
force
=
False
self
.
process_flags
()
self
.
length
=
len
(
self
.
todolist
.
todos
())
# to determine newly activated todos
self
.
length
=
len
(
self
.
todolist
.
todos
())
# to determine newly activated todos
self
.
get_todos
(
self
.
args
)
def
get_flags
(
self
):
def
get_flags
(
self
):
""" Default implementation of getting specific flags. """
return
(
"f"
,
[
"force"
])
return
(
""
,
[])
def
process_flag
(
self
,
p_option
,
p_value
):
def
process_flag
(
self
,
p_opt
,
p_value
):
""" Default implementation of processing specific flags. """
if
p_opt
==
"-f"
or
p_opt
==
"--force"
:
pass
self
.
force
=
True
def
process_flags
(
self
):
opts
,
args
=
self
.
get_flags
()
opts
,
args
=
self
.
getopt
(
"f"
+
opts
,
[
"force"
]
+
args
)
for
opt
,
value
in
opts
:
if
opt
==
"-f"
or
opt
==
"--force"
:
self
.
force
=
True
else
:
self
.
process_flag
(
opt
,
value
)
self
.
args
=
args
def
_uncompleted_children
(
self
,
p_todo
):
def
_uncompleted_children
(
self
,
p_todo
):
return
sorted
(
return
sorted
(
...
@@ -128,7 +113,7 @@ class DCommand(MultiCommand):
...
@@ -128,7 +113,7 @@ class DCommand(MultiCommand):
"""
"""
pass
pass
def
execute_multi_specific
(
self
):
def
_
execute_multi_specific
(
self
):
old_active
=
self
.
_active_todos
()
old_active
=
self
.
_active_todos
()
for
todo
in
self
.
todos
:
for
todo
in
self
.
todos
:
...
...
topydo/lib/ExpressionCommand.py
View file @
ebbf3954
...
@@ -35,13 +35,22 @@ class ExpressionCommand(Command):
...
@@ -35,13 +35,22 @@ class ExpressionCommand(Command):
self
.
sort_expression
=
config
().
sort_string
()
self
.
sort_expression
=
config
().
sort_string
()
self
.
show_all
=
False
self
.
show_all
=
False
# Commands using last argument differently (i.e as something other than
# todo ID/expression) have to set attribute below to True.
self
.
last_argument
=
False
def
_filters
(
self
):
def
_filters
(
self
):
filters
=
[]
filters
=
[]
def
arg_filters
():
def
arg_filters
():
result
=
[]
result
=
[]
for
arg
in
self
.
args
:
if
self
.
last_argument
:
args
=
self
.
args
[:
-
1
]
else
:
args
=
self
.
args
for
arg
in
args
:
if
re
.
match
(
Filter
.
ORDINAL_TAG_MATCH
,
arg
):
if
re
.
match
(
Filter
.
ORDINAL_TAG_MATCH
,
arg
):
argfilter
=
Filter
.
OrdinalTagFilter
(
arg
)
argfilter
=
Filter
.
OrdinalTagFilter
(
arg
)
elif
len
(
arg
)
>
1
and
arg
[
0
]
==
'-'
:
elif
len
(
arg
)
>
1
and
arg
[
0
]
==
'-'
:
...
...
topydo/lib/MultiCommand.py
View file @
ebbf3954
...
@@ -16,10 +16,10 @@
...
@@ -16,10 +16,10 @@
from
six
import
u
from
six
import
u
from
topydo.lib.
Command
import
Command
from
topydo.lib.
ExpressionCommand
import
Expression
Command
from
topydo.lib.TodoListBase
import
InvalidTodoException
from
topydo.lib.TodoListBase
import
InvalidTodoException
class
MultiCommand
(
Command
):
class
MultiCommand
(
Expression
Command
):
"""
"""
A common class for operations that can work with multiple todo IDs.
A common class for operations that can work with multiple todo IDs.
"""
"""
...
@@ -33,14 +33,49 @@ class MultiCommand(Command):
...
@@ -33,14 +33,49 @@ class MultiCommand(Command):
self
.
todos
=
[]
self
.
todos
=
[]
self
.
invalid_numbers
=
[]
self
.
invalid_numbers
=
[]
self
.
is_expression
=
False
self
.
multi_mode
=
True
def
get_todos
(
self
,
p_numbers
):
def
get_flags
(
self
):
""" Default implementation of getting specific flags. """
return
(
""
,
[])
def
process_flag
(
self
,
p_option
,
p_value
):
""" Default implementation of processing specific flags. """
pass
def
_process_flags
(
self
):
opts
,
long_opts
=
self
.
get_flags
()
opts
,
args
=
self
.
getopt
(
"xe"
+
opts
,
long_opts
)
for
opt
,
value
in
opts
:
if
opt
==
'-x'
:
self
.
show_all
=
True
elif
opt
==
'-e'
:
self
.
is_expression
=
True
else
:
self
.
process_flag
(
opt
,
value
)
self
.
args
=
args
def
get_todos_from_expr
(
self
):
self
.
todos
=
self
.
_view
().
todos
def
get_todos
(
self
):
""" Gets todo objects from supplied todo IDs """
""" Gets todo objects from supplied todo IDs """
for
number
in
p_numbers
:
if
self
.
is_expression
:
try
:
self
.
get_todos_from_expr
()
self
.
todos
.
append
(
self
.
todolist
.
todo
(
number
))
else
:
except
InvalidTodoException
:
if
self
.
last_argument
:
self
.
invalid_numbers
.
append
(
number
)
numbers
=
self
.
args
[:
-
1
]
else
:
numbers
=
self
.
args
for
number
in
numbers
:
try
:
self
.
todos
.
append
(
self
.
todolist
.
todo
(
number
))
except
InvalidTodoException
:
self
.
invalid_numbers
.
append
(
number
)
def
_catch_todo_errors
(
self
):
def
_catch_todo_errors
(
self
):
"""
"""
...
@@ -65,23 +100,36 @@ class MultiCommand(Command):
...
@@ -65,23 +100,36 @@ class MultiCommand(Command):
else
:
else
:
return
None
return
None
def
execute_multi_specific
(
self
):
def
_
execute_multi_specific
(
self
):
"""
"""
Operations specific for particular command dealing with multiple todo
Operations specific for particular command dealing with multiple todo
IDs.
IDs.
"""
"""
pass
pass
def
_execute_not_multi
(
self
):
"""
Some commands can do something else besides operating on multiple todo
IDs. This method is a wrapper for those other operations.
"""
pass
def
execute
(
self
):
def
execute
(
self
):
if
not
super
(
MultiCommand
,
self
).
execute
():
if
not
super
(
MultiCommand
,
self
).
execute
():
return
False
return
False
todo_errors
=
self
.
_catch_todo_error
s
()
self
.
_process_flag
s
()
if
not
todo_errors
:
if
not
self
.
multi_mode
:
self
.
execute_multi_specific
()
self
.
_execute_not_multi
()
else
:
else
:
for
error
in
todo_errors
:
self
.
get_todos
()
self
.
error
(
error
)
todo_errors
=
self
.
_catch_todo_errors
()
if
not
todo_errors
:
self
.
_execute_multi_specific
()
else
:
for
error
in
todo_errors
:
self
.
error
(
error
)
return
True
return
True
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