Commit 13d2a633 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Merge branch 'master' of github.com:bram85/topydo

parents 013fe700 45bcd4a9
...@@ -284,6 +284,20 @@ class RevertCommandTest(CommandTest): ...@@ -284,6 +284,20 @@ class RevertCommandTest(CommandTest):
self.assertEqual(result, []) self.assertEqual(result, [])
self.assertEqual(self.errors, "") self.assertEqual(self.errors, "")
def test_revert07(self):
""" Test backup when no archive file is set """
backup = ChangeSet(self.todolist, None, ['add One'])
backup.timestamp = '1'
command1 = AddCommand(["One"], self.todolist, self.out, self.error, None)
command1.execute()
backup.save(self.todolist)
changesets = list(backup.backup_dict.keys())
changesets.remove('index')
self.assertEqual(len(changesets), 1)
self.assertEqual(self.errors, "")
def test_backup_config01(self): def test_backup_config01(self):
config(p_overrides={('topydo', 'backup_count'): '1'}) config(p_overrides={('topydo', 'backup_count'): '1'})
......
...@@ -99,7 +99,10 @@ class ChangeSet(object): ...@@ -99,7 +99,10 @@ class ChangeSet(object):
current_hash = hash_todolist(p_todolist) current_hash = hash_todolist(p_todolist)
list_todo = (self.todolist.print_todos()+'\n').splitlines(True) list_todo = (self.todolist.print_todos()+'\n').splitlines(True)
list_archive = (self.archive.print_todos()+'\n').splitlines(True) try:
list_archive = (self.archive.print_todos()+'\n').splitlines(True)
except AttributeError:
list_archive = []
self.backup_dict[self.timestamp] = (list_todo, list_archive, self.call) self.backup_dict[self.timestamp] = (list_todo, list_archive, self.call)
......
...@@ -150,6 +150,17 @@ from topydo.lib import TodoListBase ...@@ -150,6 +150,17 @@ from topydo.lib import TodoListBase
from topydo.lib.Utils import escape_ansi from topydo.lib.Utils import escape_ansi
def _retrieve_archive():
"""
Returns a tuple with archive content: the first element is a TodoListBase
and the second element is a TodoFile.
"""
archive_file = TodoFile.TodoFile(config().archive())
archive = TodoListBase.TodoListBase(archive_file.read())
return (archive, archive_file)
class CLIApplicationBase(object): class CLIApplicationBase(object):
""" """
Base class for a Command Line Interfaces (CLI) for topydo. Examples are the Base class for a Command Line Interfaces (CLI) for topydo. Examples are the
...@@ -211,8 +222,7 @@ class CLIApplicationBase(object): ...@@ -211,8 +222,7 @@ class CLIApplicationBase(object):
This means that all completed tasks are moved to the archive file This means that all completed tasks are moved to the archive file
(defaults to done.txt). (defaults to done.txt).
""" """
archive_file = TodoFile.TodoFile(config().archive()) archive, archive_file = _retrieve_archive()
archive = TodoListBase.TodoListBase(archive_file.read())
if self.backup: if self.backup:
self.backup.add_archive(archive) self.backup.add_archive(archive)
...@@ -275,6 +285,9 @@ class CLIApplicationBase(object): ...@@ -275,6 +285,9 @@ class CLIApplicationBase(object):
# (i.e. explicitly left empty in the configuration # (i.e. explicitly left empty in the configuration
if self.do_archive and config().archive(): if self.do_archive and config().archive():
self._archive() self._archive()
elif config().archive() and self.backup:
archive = _retrieve_archive()[0]
self.backup.add_archive(archive)
if config().keep_sorted(): if config().keep_sorted():
from topydo.commands.SortCommand import SortCommand from topydo.commands.SortCommand import SortCommand
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment