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
fea67492
Commit
fea67492
authored
Sep 20, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make number not a class attribute but an entry in the attributes field.
parent
c31aa9df
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
33 deletions
+31
-33
Filter.py
Filter.py
+1
-1
Main.py
Main.py
+1
-1
PrettyPrinter.py
PrettyPrinter.py
+1
-1
Todo.py
Todo.py
+3
-3
TodoBase.py
TodoBase.py
+1
-2
TodoList.py
TodoList.py
+20
-18
test/FilterTest.py
test/FilterTest.py
+3
-6
test/TestFacilities.py
test/TestFacilities.py
+1
-1
No files found.
Filter.py
View file @
fea67492
...
...
@@ -69,7 +69,7 @@ class DependencyFilter(Filter):
"""
Returns True when there are no children that are uncompleted yet.
"""
children
=
self
.
todolist
.
children
(
p_todo
.
number
)
children
=
self
.
todolist
.
children
(
p_todo
.
attributes
[
'number'
]
)
uncompleted
=
[
todo
for
todo
in
children
if
not
todo
.
is_completed
()]
return
not
uncompleted
Main.py
View file @
fea67492
...
...
@@ -163,7 +163,7 @@ class Application(object):
def
do
(
self
):
def
complete_children
(
p_number
):
children
=
[
t
.
number
for
t
in
self
.
todolist
.
children
(
p_number
)
if
not
t
.
is_completed
()]
children
=
[
t
.
attributes
[
'number'
]
for
t
in
self
.
todolist
.
children
(
p_number
)
if
not
t
.
is_completed
()]
if
children
:
for
child
in
children
:
self
.
print_todo
(
child
)
...
...
PrettyPrinter.py
View file @
fea67492
...
...
@@ -39,7 +39,7 @@ def pretty_print(p_todos, p_show_numbers=False, p_color=False):
todo_str = str(todo)
if p_show_numbers:
todo_str = "%3d %s" % (todo.
number
, todo_str)
todo_str = "%3d %s" % (todo.
attributes['
number
']
, todo_str)
if Config.COLORS and p_color:
todo_str = add_colors(todo_str, todo)
...
...
Todo.py
View file @
fea67492
...
...
@@ -14,9 +14,9 @@ class Todo(TodoBase.TodoBase):
base class, mainly by interpreting the start and due dates of task.
"""
def
__init__
(
self
,
p_str
,
p_number
=-
1
):
TodoBase
.
TodoBase
.
__init__
(
self
,
p_str
,
p_number
)
self
.
attributes
=
{}
def
__init__
(
self
,
p_str
):
TodoBase
.
TodoBase
.
__init__
(
self
,
p_str
)
self
.
attributes
=
{
'number'
:
-
1
}
def
get_date
(
self
,
p_tag
):
""" Given a date tag, return a date object. """
...
...
TodoBase.py
View file @
fea67492
...
...
@@ -19,10 +19,9 @@ class TodoBase(object):
in a todo item.
"""
def
__init__
(
self
,
p_src
,
p_number
=-
1
):
def
__init__
(
self
,
p_src
):
self
.
src
=
""
self
.
fields
=
{}
self
.
number
=
p_number
self
.
set_text
(
p_src
)
...
...
TodoList.py
View file @
fea67492
...
...
@@ -62,23 +62,32 @@ class TodoList(object):
dep_id
=
p_todo
.
tag_value
(
'id'
)
# maintain dependency graph
if
dep_id
:
self
.
_depgraph
.
add_node
(
p_todo
.
number
)
self
.
_depgraph
.
add_node
(
p_todo
.
attributes
[
'number'
]
)
# connect all tasks we have in memory so far that refer to this
# task
for
dep
in
\
[
dep
for
dep
in
self
.
_todos
if
dep
.
has_tag
(
'p'
,
dep_id
)]:
self
.
_depgraph
.
add_edge
(
p_todo
.
number
,
dep
.
number
,
dep_id
)
self
.
_depgraph
.
add_edge
(
p_todo
.
attributes
[
'number'
],
dep
.
attributes
[
'number'
]
,
dep_id
)
for
child
in
p_todo
.
tag_values
(
'p'
):
parent
=
self
.
todo_by_dep_id
(
child
)
if
parent
:
self
.
_depgraph
.
add_edge
(
parent
.
number
,
p_todo
.
number
,
child
)
self
.
_depgraph
.
add_edge
(
parent
.
attributes
[
'number'
],
p_todo
.
attributes
[
'number'
]
,
child
)
def
add
(
self
,
p_src
):
""" Given a todo string, parse it and put it to the end of the list. """
todo
=
None
if
re
.
search
(
r'\
S
', p_src):
todo = Todo.Todo(p_src)
self.add_todo(todo)
return todo
def add_todo(self, p_todo):
"""
Given a todo string, parse it and put it to the end of
the list.
Add an Todo object to
the list.
Also maintains the dependency graph to track the dependencies between
tasks.
...
...
@@ -93,17 +102,7 @@ class TodoList(object):
Then there will be an edge 1 --> 2 with ID 4.
"""
todo
=
None
if
re
.
search
(
r'\
S
', p_src):
number = len(self._todos) + 1
todo = Todo.Todo(p_src, number)
self.add_todo(todo)
return todo
def add_todo(self, p_todo):
""" Add an Todo object to the list. """
p_todo.attributes['
number
'] = len(self._todos) + 1
self._todos.append(p_todo)
self._maintain_dep_graph(p_todo)
...
...
@@ -115,10 +114,10 @@ class TodoList(object):
if todo:
for child in self.children(p_number):
self.remove_dependency(todo.
number, child.number
)
self.remove_dependency(todo.
attributes['
number
'], child.attributes['
number
']
)
for parent in self.parents(p_number):
self.remove_dependency(parent.
number, todo.number
)
self.remove_dependency(parent.
attributes['
number
'], todo.attributes['
number
']
)
del self._todos[p_number - 1]
...
...
@@ -263,7 +262,10 @@ class TodoList(object):
"""
for todo in self._todos:
todo.attributes['parents'] = self.parents(todo.number)
todo.attributes['parents'] = self.parents(todo.attributes['number'])
def todos(self):
return self._todos
def __str__(self):
return '
\
n
'.join(pretty_print(self._todos))
...
...
test/FilterTest.py
View file @
fea67492
...
...
@@ -4,7 +4,7 @@ import datetime
import
unittest
import
Filter
from
TestFacilities
import
load_file
,
load_file_to_raw_list
,
todolist_to_string
from
TestFacilities
import
*
import
Todo
import
TodoList
...
...
@@ -65,13 +65,10 @@ class FilterTest(unittest.TestCase):
def
test_filter7
(
self
):
""" Tests the dependency filter. """
todos_raw
=
load_file_to_raw_list
(
'data/FilterTest2.txt'
)
todos
=
load_file
(
'data/FilterTest2.txt'
)
todolist
=
TodoList
.
TodoList
(
todos_raw
)
todolist
=
load_file_to_todolist
(
'data/FilterTest2.txt'
)
depfilter
=
Filter
.
DependencyFilter
(
todolist
)
filtered_todos
=
depfilter
.
filter
(
todo
s
)
filtered_todos
=
depfilter
.
filter
(
todo
list
.
todos
()
)
reference
=
load_file
(
'data/FilterTest2-result.txt'
)
self
.
assertEquals
(
todolist_to_string
(
filtered_todos
),
\
...
...
test/TestFacilities.py
View file @
fea67492
...
...
@@ -7,7 +7,7 @@ def load_file(p_filename):
Loads a todo file from the given filename and returns a list of todos.
"""
todolist
=
load_file_to_raw_list
(
p_filename
)
return
[
Todo
.
Todo
(
src
,
number
+
1
)
for
number
,
src
in
enumerate
(
todolist
)
]
return
[
Todo
.
Todo
(
src
)
for
src
in
todolist
]
def
load_file_to_raw_list
(
p_filename
):
"""
...
...
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