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
c1726616
Commit
c1726616
authored
Oct 12, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First attempt at archiving todos to a separate file.
parent
22218f2f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
11 deletions
+42
-11
ArchiveCommand.py
ArchiveCommand.py
+12
-0
Config.py
Config.py
+1
-1
Main.py
Main.py
+22
-6
TodoFile.py
TodoFile.py
+7
-4
No files found.
ArchiveCommand.py
0 → 100644
View file @
c1726616
import
Command
import
Config
class
ArchiveCommand
(
Command
.
Command
):
def
__init__
(
self
,
p_todolist
,
p_archive_list
):
super
(
ArchiveCommand
,
self
).
__init__
([],
p_todolist
)
self
.
archive
=
p_archive_list
def
execute
(
self
):
for
todo
in
[
t
for
t
in
self
.
todolist
.
todos
()
if
t
.
is_completed
()]:
self
.
archive
.
add_todo
(
todo
)
self
.
todolist
.
delete
(
todo
.
attributes
[
'number'
])
Config.py
View file @
c1726616
...
...
@@ -7,7 +7,7 @@ COLORS = True
HIGHLIGHT_PROJECTS_CONTEXTS
=
True
FILENAME
=
'todo.txt'
COMPLETED
_FILENAME
=
'done.txt'
ARCHIVE
_FILENAME
=
'done.txt'
TAG_START
=
't'
TAG_DUE
=
'due'
...
...
Main.py
View file @
c1726616
...
...
@@ -5,6 +5,7 @@ import sys
from
AddCommand
import
AddCommand
from
AppendCommand
import
AppendCommand
from
ArchiveCommand
import
ArchiveCommand
from
DepCommand
import
DepCommand
import
Config
from
DoCommand
import
DoCommand
...
...
@@ -40,14 +41,28 @@ class CLIApplication(object):
def
__init__
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
def
archive
(
self
):
"""
Performs an archive action on the todolist.
This means that all completed tasks are moved to the archive file
(defaults to done.txt).
"""
archive_file
=
TodoFile
.
TodoFile
(
Config
.
ARCHIVE_FILENAME
)
archive
=
TodoList
.
TodoList
(
archive_file
.
read
())
if
archive
:
command
=
ArchiveCommand
(
self
.
todolist
,
archive
)
command
.
execute
()
if
archive
.
is_dirty
():
archive_file
.
write
(
archive
)
def
run
(
self
):
""" Main entry function. """
todofile
=
TodoFile
.
TodoFile
(
Config
.
FILENAME
)
try
:
self
.
todolist
=
TodoList
.
TodoList
(
todofile
.
read
())
except
Exception
:
pass
# TODO
self
.
todolist
=
TodoList
.
TodoList
(
todofile
.
read
())
try
:
subcommand
=
sys
.
argv
[
1
]
...
...
@@ -82,10 +97,11 @@ class CLIApplication(object):
lambda
e
:
sys
.
stderr
.
write
(
e
+
"
\
n
"
),
raw_input
)
if
not
command
.
execute
()
:
if
command
.
execute
()
==
False
:
exit
(
1
)
if
self
.
todolist
.
is_dirty
():
# self.archive()
todofile
.
write
(
str
(
self
.
todolist
))
if
__name__
==
'__main__'
:
...
...
TodoFile.py
View file @
c1726616
...
...
@@ -13,10 +13,13 @@ class TodoFile(object):
def
read
(
self
):
""" Reads the todo.txt file and returns a list of todo items. """
todofile
=
open
(
self
.
path
,
'r'
)
todos
=
todofile
.
readlines
()
todofile
.
close
()
todos
=
[]
try
:
todofile
=
open
(
self
.
path
,
'r'
)
todos
=
todofile
.
readlines
()
todofile
.
close
()
except
IOError
:
pass
return
todos
...
...
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