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
30c961bf
Commit
30c961bf
authored
Nov 02, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to identify todos by a regex.
Works for delete and do subcommands.
parent
b8cd5ae1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
8 deletions
+59
-8
test/DeleteCommandTest.py
test/DeleteCommandTest.py
+9
-0
test/DoCommandTest.py
test/DoCommandTest.py
+10
-1
test/TodoListTest.py
test/TodoListTest.py
+12
-0
topydo/lib/DCommand.py
topydo/lib/DCommand.py
+5
-1
topydo/lib/TodoList.py
topydo/lib/TodoList.py
+23
-6
No files found.
test/DeleteCommandTest.py
View file @
30c961bf
...
...
@@ -36,6 +36,15 @@ class DeleteCommandTest(CommandTest.CommandTest):
self
.
assertEquals
(
self
.
output
,
" 2 Bar p:1
\
n
Removed: Foo id:1
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_del1_regex
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"Foo"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
lambda
p
:
"n"
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
todolist
.
todo
(
1
).
source
(),
"Bar"
)
self
.
assertEquals
(
self
.
output
,
" 2 Bar p:1
\
n
Removed: Foo id:1
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_del2
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"1"
],
self
.
todolist
,
self
.
out
,
self
.
error
,
lambda
p
:
"y"
)
command
.
execute
()
...
...
test/DoCommandTest.py
View file @
30c961bf
...
...
@@ -133,7 +133,7 @@ class DoCommandTest(CommandTest.CommandTest):
self
.
assertEquals
(
self
.
errors
,
"Invalid todo number given.
\
n
"
)
def
test_invalid2
(
self
):
command
=
DoCommand
.
DoCommand
([
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
=
DoCommand
.
DoCommand
([
"A
AA
"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
...
...
@@ -171,6 +171,15 @@ class DoCommandTest(CommandTest.CommandTest):
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
"Todo has already been completed.
\
n
"
)
def
test_do_regex1
(
self
):
command
=
DoCommand
.
DoCommand
([
"baz"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertTrue
(
self
.
todolist
.
todo
(
3
).
is_completed
())
self
.
assertEquals
(
self
.
output
,
"Completed: x %s Baz p:1
\
n
"
%
self
.
today
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_empty
(
self
):
command
=
DoCommand
.
DoCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
...
...
test/TodoListTest.py
View file @
30c961bf
...
...
@@ -181,6 +181,18 @@ class TodoListTester(unittest.TestCase):
self
.
assertEquals
(
self
.
todolist
.
count
(),
0
)
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
def
test_regex1
(
self
):
self
.
assertFalse
(
self
.
todolist
.
todo
(
"1"
))
def
test_regex2
(
self
):
""" Multiple hits should result in None. """
self
.
assertFalse
(
self
.
todolist
.
todo
(
"Project1"
))
def
test_regex3
(
self
):
todo
=
self
.
todolist
.
todo
(
"project2"
)
self
.
assertTrue
(
todo
)
self
.
assertEquals
(
todo
.
source
(),
"(D) Bar @Context1 +Project2"
)
class
TodoListDependencyTester
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
...
...
topydo/lib/DCommand.py
View file @
30c961bf
...
...
@@ -38,8 +38,12 @@ class DCommand(Command):
try
:
self
.
number
=
convert_todo_number
(
self
.
argument
(
0
))
self
.
todo
=
self
.
todolist
.
todo
(
self
.
number
)
except
(
InvalidCommandArgument
,
InvalidTodo
NumberException
,
InvalidTodo
Exception
):
except
(
InvalidCommandArgument
,
InvalidTodoException
):
self
.
todo
=
None
except
InvalidTodoNumberException
:
self
.
todo
=
self
.
todolist
.
todo
(
self
.
argument
(
0
))
if
self
.
todo
:
self
.
number
=
self
.
todolist
.
number
(
self
.
todo
)
def
_uncompleted_children
(
self
,
p_todo
):
return
sorted
([
t
for
t
in
self
.
todolist
.
children
(
p_todo
)
if
not
t
.
is_completed
()])
...
...
topydo/lib/TodoList.py
View file @
30c961bf
...
...
@@ -20,6 +20,7 @@ A list of todo items.
import
re
import
Filter
import
Graph
from
PrettyPrinter
import
pretty_print_list
import
Todo
...
...
@@ -50,7 +51,7 @@ class TodoList(object):
self
.
dirty
=
False
def
todo
(
self
,
p_
numb
er
):
def
todo
(
self
,
p_
identifi
er
):
"""
The _todos list has the same order as in the backend store (usually
a todo.txt file. The user refers to the first task as number 1, so use
...
...
@@ -58,15 +59,31 @@ class TodoList(object):
"""
result
=
None
try
:
result
=
self
.
_todos
[
p_
numb
er
-
1
]
result
=
self
.
_todos
[
p_
identifi
er
-
1
]
except
IndexError
:
raise
InvalidTodoException
except
TypeError
:
result
=
self
.
todo_by_regexp
(
p_identifier
)
return
result
def
todo_by_regexp
(
self
,
p_identifier
):
"""
Returns the todo that is (uniquely) identified by the given regexp.
If the regexp matches more than one item, no result is returned.
"""
result
=
None
candidates
=
Filter
.
GrepFilter
(
p_identifier
).
filter
(
self
.
_todos
)
if
len
(
candidates
)
==
1
:
result
=
candidates
[
0
]
return
result
def
todo_by_hash
(
self
,
p_hash
):
"""
Given the hash value of a todo, return the corresponding
hash
instance.
Given the hash value of a todo, return the corresponding instance.
"""
result
=
None
...
...
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