Commit 83d1005a authored by Jacek Sowiński's avatar Jacek Sowiński

Fix backup descriptions for column UI transactions

This provides that each backup description will still inform user about
each command that was executed. When transaction of commands was
executed user will get printed list of commands separated by ';'.

Example:

Successfully reverted: append 1 FooBar; append 3 FooBar; append 6 FooBar;
parent 87970230
......@@ -57,7 +57,7 @@ class RevertCommandTest(CommandTest):
self.archive = TodoList([])
def test_revert01(self):
backup = ChangeSet(p_call=['do 1'])
backup = ChangeSet(p_label=['do 1'])
backup.add_todolist(self.todolist)
backup.add_archive(self.archive)
backup.timestamp = '1'
......
......@@ -43,7 +43,7 @@ class RevertCommand(Command):
archive_file.write(archive.print_todos())
last_change.delete()
self.out("Successfully reverted: " + last_change.call)
self.out("Successfully reverted: " + last_change.label)
except (ValueError, KeyError):
self.error('No backup was found for the current state of ' + config().todotxt())
......
......@@ -43,11 +43,11 @@ def get_backup_path():
class ChangeSet(object):
""" Class for operations related with backup management. """
def __init__(self, p_todolist=None, p_archive=None, p_call=[]):
def __init__(self, p_todolist=None, p_archive=None, p_label=[]):
self.todolist = deepcopy(p_todolist)
self.archive = deepcopy(p_archive)
self.timestamp = str(int(time.time()))
self.call = ' '.join(p_call)
self.label = ' '.join(p_label)
try:
self.json_file = open(get_backup_path(), 'r+b')
......@@ -104,7 +104,7 @@ class ChangeSet(object):
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.label)
index = self._get_index()
index.insert(0, (self.timestamp, current_hash))
......@@ -161,7 +161,7 @@ class ChangeSet(object):
def get_backup(self, p_todolist):
"""
Retrieves a backup for p_todolist from backup file and sets todolist,
archive and call attributes to appropriate data from it.
archive and label attributes to appropriate data from it.
"""
change_hash = hash_todolist(p_todolist)
......@@ -172,7 +172,7 @@ class ChangeSet(object):
self.todolist = TodoList(d[0])
self.archive = TodoList(d[1])
self.call = d[2]
self.label = d[2]
def apply(self, p_todolist, p_archive):
""" Applies backup on supplied p_todolist. """
......
......@@ -247,12 +247,13 @@ class CLIApplicationBase(object):
READ_ONLY_COMMANDS)
return p_command.__module__.endswith(read_only_commands)
def _backup(self, p_command, p_args):
def _backup(self, p_command, p_args=[], p_label=None):
if config().backup_count() > 0 and p_command and not self.is_read_only(p_command):
call = [p_command.__module__.lower()[16:-7]] + p_args # strip "topydo.commands" and "Command"
from topydo.lib.ChangeSet import ChangeSet
self.backup = ChangeSet(self.todolist, p_call=call)
label = p_label if p_label else call
self.backup = ChangeSet(self.todolist, p_label=label)
def _execute(self, p_command, p_args):
"""
......
......@@ -301,8 +301,6 @@ class UIApplication(CLIApplicationBase):
'Error: {}. Check your aliases configuration.'.format(cerr))
return
self._backup(subcommand, args)
env_args = (self.todolist, p_output, self._output, self._input)
ids = None
......@@ -320,6 +318,8 @@ class UIApplication(CLIApplicationBase):
transaction = Transaction(subcommand, env_args, ids)
transaction.prepare(args)
label = transaction.label
self._backup(subcommand, p_label=label)
try:
if transaction.execute():
......
......@@ -27,6 +27,8 @@ class Transaction(object):
self._cmd = lambda op: p_subcommand(op, *p_env_args)
self._todo_ids = p_todo_ids
self._operations = []
self._cmd_name = p_subcommand.__module__.lower()[16:-7]
self.label = []
def prepare(self, p_args):
"""
......@@ -49,6 +51,17 @@ class Transaction(object):
else:
self._operations.append(p_args)
self._create_label()
def _create_label(self):
if len(self._operations) > 1:
for operation in self._operations:
self.label.append(self._cmd_name + ' ' +
' '.join(operation) + ';')
else:
self.label.append(self._cmd_name + ' ' +
' '.join(self._operations[0]))
def execute(self):
"""
Executes each operation from _operations attribute.
......
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