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
92f372cb
Commit
92f372cb
authored
Sep 21, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import date from datetime, instead of mentioning datetime everywhere.
parent
f1d2414d
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
47 additions
and
52 deletions
+47
-52
Importance.py
Importance.py
+2
-2
Main.py
Main.py
+2
-2
Sorter.py
Sorter.py
+3
-3
Todo.py
Todo.py
+3
-4
TodoBase.py
TodoBase.py
+5
-5
Utils.py
Utils.py
+3
-5
test/FilterTest.py
test/FilterTest.py
+0
-1
test/ImportanceTest.py
test/ImportanceTest.py
+2
-2
test/TodoBaseTest.py
test/TodoBaseTest.py
+20
-20
test/TodoListTest.py
test/TodoListTest.py
+0
-1
test/TodoTest.py
test/TodoTest.py
+7
-7
No files found.
Importance.py
View file @
92f372cb
...
...
@@ -7,7 +7,7 @@ today may have a higher importance than high priority tasks in the distant
future.
"""
import
datetim
e
from
datetime
import
dat
e
import
Config
...
...
@@ -15,7 +15,7 @@ IMPORTANCE_VALUE = {'A': 3, 'B': 2, 'C': 1}
def
is_due_next_monday
(
p_todo
):
""" Returns True when the given task is due next Monday. """
today
=
date
time
.
date
.
today
()
today
=
date
.
today
()
due
=
p_todo
.
due_date
()
return
due
and
due
.
weekday
()
==
0
and
today
.
weekday
()
>=
4
and
\
...
...
Main.py
View file @
92f372cb
#!/usr/bin/env python
""" Entry file for the Python todo.txt CLI. """
import
datetim
e
from
datetime
import
dat
e
import
re
import
sys
...
...
@@ -76,7 +76,7 @@ def postprocess_input_todo(p_todo):
if
date
:
p_todo
.
set_tag
(
tag
,
date
.
isoformat
())
p_todo
.
set_creation_date
(
date
time
.
date
.
today
())
p_todo
.
set_creation_date
(
date
.
today
())
class
Application
(
object
):
def
__init__
(
self
):
...
...
Sorter.py
View file @
92f372cb
""" This module provides functionality to sort lists with todo items. """
import
datetim
e
from
datetime
import
dat
e
import
re
import
Config
...
...
@@ -24,10 +24,10 @@ def get_field_function(p_field):
# when a task has no creation date, push it to the end by assigning it
# the maximum possible date.
result
=
(
lambda
a
:
a
.
creation_date
()
if
a
.
creation_date
()
\
else
date
time
.
date
.
max
)
else
date
.
max
)
elif
p_field
==
'done'
or
p_field
==
'completed'
or
p_field
==
'completion'
:
result
=
(
lambda
a
:
a
.
completion_date
()
if
a
.
completion_date
()
\
else
date
time
.
date
.
max
)
else
date
.
max
)
elif
p_field
==
'importance'
:
result
=
lambda
a
:
importance
(
a
,
Config
.
IGNORE_WEEKENDS
)
elif
p_field
==
'importance-avg'
or
p_field
==
'importance-average'
:
...
...
Todo.py
View file @
92f372cb
...
...
@@ -2,7 +2,7 @@
This module provides the Todo class.
"""
import
datetim
e
from
datetime
import
dat
e
import
Config
import
Utils
...
...
@@ -37,8 +37,7 @@ class Todo(TodoBase.TodoBase):
task has not yet been completed.
"""
start
=
self
.
start_date
()
return
not
self
.
is_completed
()
and
\
(
not
start
or
start
<=
datetime
.
date
.
today
())
return
not
self
.
is_completed
()
and
(
not
start
or
start
<=
date
.
today
())
def
is_overdue
(
self
):
"""
...
...
@@ -55,7 +54,7 @@ class Todo(TodoBase.TodoBase):
"""
due
=
self
.
due_date
()
if
due
:
diff
=
due
-
date
time
.
date
.
today
()
diff
=
due
-
date
.
today
()
return
diff
.
days
return
0
...
...
TodoBase.py
View file @
92f372cb
...
...
@@ -2,7 +2,7 @@
This module contains the class that represents a single todo item.
"""
import
datetim
e
from
datetime
import
dat
e
import
re
import
TodoParser
...
...
@@ -172,17 +172,17 @@ class TodoBase(object):
self.set_priority(None)
self.fields['
completed
'] = True
today = date
time.date
.today()
today = date.today()
self.fields['
completionDate
'] = today
self.src = re.sub(r'
^
(
\
([
A
-
Z
]
\
)
)
?
',
\
'
x
' + today.isoformat() + '
', self.src)
def set_creation_date(self,
date=datetime.
date.today()):
def set_creation_date(self,
p_date=
date.today()):
"""
Sets the creation date of a todo. Should be passed a date object.
"""
self.fields['
creationDate
'] = date
self.fields['
creationDate
'] =
p_
date
# not particulary pretty, but inspired by
# http://bugs.python.org/issue1519638 non-existent matches trigger
...
...
@@ -190,7 +190,7 @@ class TodoBase(object):
self.src = re.sub(
r'
^
(
x
\
d
{
4
}
-
\
d
{
2
}
-
\
d
{
2
}
|
\
([
A
-
Z
]
\
)
)
?
(
\
d
{
4
}
-
\
d
{
2
}
-
\
d
{
2
}
)
?
(.
*
)
$
',
\
lambda m:
\
"%s%s %s" % (m.group(1) or '', date.isoformat(), m.group(3)),
\
"%s%s %s" % (m.group(1) or '',
p_
date.isoformat(), m.group(3)),
\
self.src)
def creation_date(self):
...
...
Utils.py
View file @
92f372cb
...
...
@@ -2,7 +2,7 @@
Various utility functions.
"""
import
datetim
e
from
datetime
import
dat
e
import
re
def
date_string_to_date
(
p_date
):
...
...
@@ -16,14 +16,12 @@ def date_string_to_date(p_date):
parsed_date
=
re
.
match
(
r'(\
d{
4})-(\
d{
2})-(\
d{
2})'
,
p_date
)
if
parsed_date
:
try
:
date
=
datetime
.
date
(
result
=
date
(
int
(
parsed_date
.
group
(
1
)),
# year
int
(
parsed_date
.
group
(
2
)),
# month
int
(
parsed_date
.
group
(
3
))
# day
)
result
=
date
except
ValueError
:
pass
# just return
None
result
=
None
return
result
test/FilterTest.py
View file @
92f372cb
""" Tests for the filter functionality. """
import
datetime
import
unittest
import
Filter
...
...
test/ImportanceTest.py
View file @
92f372cb
import
datetim
e
from
datetime
import
dat
e
import
unittest
import
Config
...
...
@@ -19,6 +19,6 @@ class ImportanceTest(unittest.TestCase):
self
.
assertEqual
(
importance
(
todo
),
6
)
def
test_importance4
(
self
):
today_str
=
date
time
.
date
.
today
().
isoformat
()
today_str
=
date
.
today
().
isoformat
()
todo
=
Todo
.
Todo
(
"(C) Foo "
+
Config
.
TAG_DUE
+
":"
+
today_str
)
self
.
assertEqual
(
importance
(
todo
),
8
)
test/TodoBaseTest.py
View file @
92f372cb
""" Tests for the TodoBase class. """
import
datetim
e
from
datetime
import
dat
e
import
re
import
unittest
...
...
@@ -191,7 +191,7 @@ class TodoBaseTester(unittest.TestCase):
todo
=
TodoBase
.
TodoBase
(
"(A) Foo"
)
todo
.
set_completed
()
today
=
date
time
.
date
.
today
()
today
=
date
.
today
()
today_str
=
today
.
isoformat
()
self
.
assertFalse
(
todo
.
priority
())
...
...
@@ -202,7 +202,7 @@ class TodoBaseTester(unittest.TestCase):
todo
=
TodoBase
.
TodoBase
(
"2014-06-12 Foo"
)
todo
.
set_completed
()
today
=
date
time
.
date
.
today
()
today
=
date
.
today
()
today_str
=
today
.
isoformat
()
self
.
assertEquals
(
todo
.
fields
[
'completionDate'
],
today
)
...
...
@@ -213,7 +213,7 @@ class TodoBaseTester(unittest.TestCase):
todo
=
TodoBase
.
TodoBase
(
"Foo"
)
todo
.
set_completed
()
today
=
date
time
.
date
.
today
()
today
=
date
.
today
()
today_str
=
today
.
isoformat
()
self
.
assertEquals
(
todo
.
fields
[
'completionDate'
],
today
)
...
...
@@ -223,7 +223,7 @@ class TodoBaseTester(unittest.TestCase):
todo
=
TodoBase
.
TodoBase
(
"(A) 2014-06-12 Foo"
)
todo
.
set_completed
()
today
=
date
time
.
date
.
today
()
today
=
date
.
today
()
today_str
=
today
.
isoformat
()
self
.
assertEquals
(
todo
.
fields
[
'completionDate'
],
today
)
...
...
@@ -246,47 +246,47 @@ class TodoBaseTester(unittest.TestCase):
def
test_set_creation_date1
(
self
):
todo
=
TodoBase
.
TodoBase
(
"Foo"
)
date
=
datetime
.
date
(
2014
,
7
,
24
)
creation_date
=
date
(
2014
,
7
,
24
)
todo
.
set_creation_date
(
date
)
todo
.
set_creation_date
(
creation_
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
creation_
date
)
self
.
assertEquals
(
todo
.
src
,
"2014-07-24 Foo"
)
def
test_set_creation_date2
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(A) Foo"
)
date
=
datetime
.
date
(
2014
,
7
,
24
)
creation_date
=
date
(
2014
,
7
,
24
)
todo
.
set_creation_date
(
date
)
todo
.
set_creation_date
(
creation_
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
creation_
date
)
self
.
assertEquals
(
todo
.
src
,
"(A) 2014-07-24 Foo"
)
def
test_set_creation_date3
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(A) 2014-07-23 Foo"
)
date
=
datetime
.
date
(
2014
,
7
,
24
)
creation_date
=
date
(
2014
,
7
,
24
)
todo
.
set_creation_date
(
date
)
todo
.
set_creation_date
(
creation_
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
creation_
date
)
self
.
assertEquals
(
todo
.
src
,
"(A) 2014-07-24 Foo"
)
def
test_set_creation_date4
(
self
):
todo
=
TodoBase
.
TodoBase
(
"2014-07-23 Foo"
)
date
=
datetime
.
date
(
2014
,
7
,
24
)
creation_date
=
date
(
2014
,
7
,
24
)
todo
.
set_creation_date
(
date
)
todo
.
set_creation_date
(
creation_
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
creation_
date
)
self
.
assertEquals
(
todo
.
src
,
"2014-07-24 Foo"
)
def
test_set_creation_date5
(
self
):
todo
=
TodoBase
.
TodoBase
(
"x 2014-07-25 2014-07-23 Foo"
)
date
=
datetime
.
date
(
2014
,
7
,
24
)
creation_date
=
date
(
2014
,
7
,
24
)
todo
.
set_creation_date
(
date
)
todo
.
set_creation_date
(
creation_
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
date
)
self
.
assertEquals
(
todo
.
creation_date
(),
creation_
date
)
self
.
assertEquals
(
todo
.
src
,
"x 2014-07-25 2014-07-24 Foo"
)
if
__name__
==
'__main__'
:
...
...
test/TodoListTest.py
View file @
92f372cb
""" Tests for the TodoList class. """
import
datetime
import
re
import
unittest
...
...
test/TodoTest.py
View file @
92f372cb
import
datetime
from
datetime
import
date
,
timedelta
import
unittest
import
Todo
def
today_date
():
date
=
datetime
.
date
.
today
()
return
date
.
isoformat
()
today
=
date
.
today
()
return
today
.
isoformat
()
def
tomorrow_date
():
date
=
datetime
.
date
.
today
()
+
datetime
.
timedelta
(
days
=
1
)
return
date
.
isoformat
()
tomorrow
=
date
.
today
()
+
timedelta
(
days
=
1
)
return
tomorrow
.
isoformat
()
class
TodoTest
(
unittest
.
TestCase
):
def
test_due_date1
(
self
):
todo
=
Todo
.
Todo
(
"(C) Foo due:2014-06-09"
)
d
ate
=
datetime
.
date
(
2014
,
6
,
9
)
d
ue
=
date
(
2014
,
6
,
9
)
self
.
assertEqual
(
todo
.
due_date
(),
d
at
e
)
self
.
assertEqual
(
todo
.
due_date
(),
d
u
e
)
def
test_false_date
(
self
):
todo
=
Todo
.
Todo
(
"(C) Foo due:2014-04-31"
)
...
...
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