Commit 4efef4ec authored by Jacek Sowiński's avatar Jacek Sowiński

Remove no longer needed IndexError exceptions

MultiCommand._catch_todo_errors() prevents occuring of those.
parent 4d049970
...@@ -26,17 +26,13 @@ class DepriCommand(MultiCommand): ...@@ -26,17 +26,13 @@ class DepriCommand(MultiCommand):
p_args, p_todolist, p_out, p_err, p_prompt) p_args, p_todolist, p_out, p_err, p_prompt)
def execute_multi_specific(self): def execute_multi_specific(self):
try: self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
for todo in self.todos: for todo in self.todos:
if todo.priority() != None: if todo.priority() != None:
self.todolist.set_priority(todo, None) self.todolist.set_priority(todo, None)
self.out("Priority removed.") self.out("Priority removed.")
self.out(self.printer.print_todo(todo)) self.out(self.printer.print_todo(todo))
except IndexError:
self.error(self.usage())
def usage(self): def usage(self):
return """Synopsis: depri <NUMBER1> [<NUMBER2> ...]""" return """Synopsis: depri <NUMBER1> [<NUMBER2> ...]"""
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
from datetime import date, timedelta from datetime import date, timedelta
from topydo.lib.MultiCommand import MultiCommand from topydo.lib.MultiCommand import MultiCommand
from topydo.lib.Command import InvalidCommandArgument
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.RelativeDate import relative_date_to_date from topydo.lib.RelativeDate import relative_date_to_date
...@@ -52,31 +51,28 @@ class PostponeCommand(MultiCommand): ...@@ -52,31 +51,28 @@ class PostponeCommand(MultiCommand):
return offset_date return offset_date
try: pattern = self.args[-1]
pattern = self.args[-1] self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
for todo in self.todos: for todo in self.todos:
offset = _get_offset(todo) offset = _get_offset(todo)
new_due = relative_date_to_date(pattern, offset) new_due = relative_date_to_date(pattern, offset)
if new_due:
if self.move_start_date and todo.has_tag(config().tag_start()):
length = todo.length()
new_start = new_due - timedelta(length)
# pylint: disable=E1103
todo.set_tag(config().tag_start(), new_start.isoformat())
if new_due:
if self.move_start_date and todo.has_tag(config().tag_start()):
length = todo.length()
new_start = new_due - timedelta(length)
# pylint: disable=E1103 # pylint: disable=E1103
todo.set_tag(config().tag_due(), new_due.isoformat()) todo.set_tag(config().tag_start(), new_start.isoformat())
self.todolist.set_dirty() # pylint: disable=E1103
self.out(self.printer.print_todo(todo)) todo.set_tag(config().tag_due(), new_due.isoformat())
else:
self.error("Invalid date pattern given.") self.todolist.set_dirty()
break self.out(self.printer.print_todo(todo))
except (InvalidCommandArgument, IndexError): else:
self.error(self.usage()) self.error("Invalid date pattern given.")
break
def usage(self): def usage(self):
return "Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>" return "Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>"
......
...@@ -31,26 +31,23 @@ class PriorityCommand(MultiCommand): ...@@ -31,26 +31,23 @@ class PriorityCommand(MultiCommand):
def execute_multi_specific(self): def execute_multi_specific(self):
priority = None priority = None
try: priority = self.args[-1]
priority = self.args[-1] self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
if is_valid_priority(priority):
if is_valid_priority(priority): for todo in self.todos:
for todo in self.todos: old_priority = todo.priority()
old_priority = todo.priority() self.todolist.set_priority(todo, priority)
self.todolist.set_priority(todo, priority)
if old_priority and priority and old_priority != priority:
if old_priority and priority and old_priority != priority: self.out("Priority changed from {} to {}".format(
self.out("Priority changed from {} to {}".format( old_priority, priority))
old_priority, priority)) elif not old_priority:
elif not old_priority: self.out("Priority set to {}.".format(priority))
self.out("Priority set to {}.".format(priority))
self.out(self.printer.print_todo(todo))
self.out(self.printer.print_todo(todo)) else:
else: self.error("Invalid priority given.")
self.error("Invalid priority given.")
except IndexError:
self.error(self.usage())
def usage(self): def usage(self):
return """Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>""" return """Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>"""
......
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