Commit 4e9f2e08 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Prompt: don't show "todo file modified" warning for readonly commands.

This reuses the logic that the backup functionality uses to determine
whether a command is read-only or not. In that case, prompt mode doesn't
trigger a warning for ls* commands when the backing todo file was
changed.
parent bfe194a8
......@@ -196,13 +196,18 @@ class CLIApplicationBase(object):
"""
return input
def is_read_only(self, p_command):
""" Returns True when the given command class is read-only. """
read_only_commands = tuple(cmd + 'Command' for cmd in ('Revert', ) +
READ_ONLY_COMMANDS)
return p_command.__module__.endswith(read_only_commands)
def _execute(self, p_command, p_args):
"""
Execute a subcommand with arguments. p_command is a class (not an
object).
"""
cmds_wo_backup = tuple(cmd + 'Command' for cmd in ('Revert', ) + READ_ONLY_COMMANDS)
if config().backup_count() > 0 and p_command and not p_command.__module__.endswith(cmds_wo_backup):
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"
self.backup = ChangeSet(self.todolist, p_call=call)
......
......@@ -99,15 +99,14 @@ class PromptApplication(CLIApplicationBase):
sys.exit(0)
mtime_after = _todotxt_mtime()
(subcommand, args) = get_subcommand(user_input)
if self.mtime != mtime_after:
# refuse to perform operations such as 'del' and 'do' if the
# todo.txt file has been changed in the background.
# refuse to perform operations such as 'del' and 'do' if the
# todo.txt file has been changed in the background.
if not self.is_read_only(subcommand) and self.mtime != mtime_after:
error("WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed.")
continue
(subcommand, args) = get_subcommand(user_input)
try:
if self._execute(subcommand, args) != False:
self._post_execute()
......
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