Commit 8cd2afd0 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Speed up 'ls' a bit (and also lsprj, lscon).

This is achieved by importing some modules only when applicable. For
instance, 'ls' doesn't need ChangeSet and also doesn't always need
icalendar. Sorting and archiving is also only applicable to writing
commands (del, add, etc.).
parent 4d7150a0
......@@ -101,12 +101,9 @@ except ConfigError as config_error:
error(str(config_error))
sys.exit(1)
from topydo.commands.ArchiveCommand import ArchiveCommand
from topydo.commands.SortCommand import SortCommand
from topydo.lib import TodoFile
from topydo.lib import TodoList
from topydo.lib import TodoListBase
from topydo.lib.ChangeSet import ChangeSet
from topydo.lib.Utils import escape_ansi
......@@ -178,6 +175,7 @@ class CLIApplicationBase(object):
self.backup.add_archive(archive)
if archive:
from topydo.commands.ArchiveCommand import ArchiveCommand
command = ArchiveCommand(self.todolist, archive)
command.execute()
......@@ -209,6 +207,8 @@ class CLIApplicationBase(object):
"""
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)
command = p_command(
......@@ -237,6 +237,7 @@ class CLIApplicationBase(object):
self._archive()
if config().keep_sorted():
from topydo.commands.SortCommand import SortCommand
self._execute(SortCommand, [])
if self.backup:
......
......@@ -16,8 +16,6 @@
from topydo.lib.Config import config
from topydo.lib.ExpressionCommand import ExpressionCommand
from topydo.lib.IcalPrinter import IcalPrinter
from topydo.lib.JsonPrinter import JsonPrinter
from topydo.lib.PrettyPrinter import pretty_printer_factory
from topydo.lib.PrettyPrinterFilter import (PrettyPrinterHideTagFilter,
PrettyPrinterIndentFilter)
......@@ -58,9 +56,11 @@ class ListCommand(ExpressionCommand):
self.sort_expression = value
elif opt == '-f':
if value == 'json':
from topydo.lib.JsonPrinter import JsonPrinter
self.printer = JsonPrinter()
elif value == 'ical':
if self._poke_icalendar():
from topydo.lib.IcalPrinter import IcalPrinter
self.printer = IcalPrinter(self.todolist)
else:
self.printer = None
......
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