Commit cd41fdef authored by MinchinWeb's avatar MinchinWeb

Fix PEP8 E302

expected 2 blank lines, found 1 (above module level defined classes and
functions)
parent 08ff4806
......@@ -19,6 +19,7 @@ from topydo.lib.Todo import Todo
from topydo.lib.TodoFile import TodoFile
from topydo.lib.TodoList import TodoList
def load_file(p_filename):
"""
Loads a todo file from the given filename and returns a list of todos.
......@@ -26,6 +27,7 @@ def load_file(p_filename):
todolist = load_file_to_raw_list(p_filename)
return [Todo(src) for src in todolist]
def load_file_to_raw_list(p_filename):
"""
Loads a todo file from the given filename and returns a list of todo
......@@ -34,6 +36,7 @@ def load_file_to_raw_list(p_filename):
todofile = TodoFile(p_filename)
return todofile.read()
def load_file_to_todolist(p_filename):
"""
Loads a todo file to a TodoList instance.
......@@ -41,10 +44,12 @@ def load_file_to_todolist(p_filename):
todolist = load_file_to_raw_list(p_filename)
return TodoList(todolist)
def todolist_to_string(p_list):
""" Converts a todo list to a single string. """
return '\n'.join([t.source() for t in p_list])
def print_view(p_view):
printer = PrettyPrinter()
return printer.print_list(p_view.todos)
......@@ -33,6 +33,7 @@ from test.TestCommand import CommandTest
from topydo.lib.Config import config
from topydo.lib import TodoList
class AddCommandTest(CommandTest):
def setUp(self):
super(AddCommandTest, self).setUp()
......
......@@ -20,6 +20,7 @@ from topydo.commands.AppendCommand import AppendCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
class AppendCommandTest(CommandTest):
def setUp(self):
super(AppendCommandTest, self).setUp()
......
......@@ -21,6 +21,7 @@ from test.TestCommand import CommandTest
from test.Facilities import load_file_to_todolist
from topydo.lib.TodoList import TodoList
class ArchiveCommandTest(CommandTest):
def test_archive(self):
todolist = load_file_to_todolist("test/data/ArchiveCommandTest.txt")
......
......@@ -21,6 +21,7 @@ from topydo.lib.Colors import Colors, NEUTRAL_COLOR
from topydo.lib.Config import config
from test.TestTopydo import TopydoTest
class ColorsTest(TopydoTest):
def test_project_color1(self):
config(p_overrides={('colorscheme', 'project_color'): '2'})
......
......@@ -19,6 +19,7 @@ import unittest
from topydo.lib.Utils import escape_ansi
from test.TestTopydo import TopydoTest
class CommandTest(TopydoTest):
def __init__(self, *args, **kwargs):
super(CommandTest, self).__init__(*args, **kwargs)
......
......@@ -19,6 +19,7 @@ import unittest
from topydo.lib.Config import config
from test.TestTopydo import TopydoTest
class ConfigTest(TopydoTest):
def test_config1(self):
self.assertEqual(config("test/data/config1").default_command(), 'do')
......
......@@ -23,12 +23,15 @@ from topydo.commands.DeleteCommand import DeleteCommand
from topydo.lib.TodoList import TodoList
from topydo.lib.TodoListBase import InvalidTodoException
def _yes_prompt(self):
return "y"
def _no_prompt(self):
return "n"
class DeleteCommandTest(CommandTest):
def setUp(self):
super(DeleteCommandTest, self).setUp()
......
......@@ -20,6 +20,7 @@ from topydo.commands.DepCommand import DepCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
class DepCommandTest(CommandTest):
def setUp(self):
super(DepCommandTest, self).setUp()
......
......@@ -21,6 +21,7 @@ from topydo.commands.DepriCommand import DepriCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
class DepriCommandTest(CommandTest):
def setUp(self):
super(DepriCommandTest, self).setUp()
......
......@@ -22,12 +22,15 @@ from topydo.commands.DoCommand import DoCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
def _yes_prompt(self):
return "y"
def _no_prompt(self):
return "n"
class DoCommandTest(CommandTest):
def setUp(self):
super(DoCommandTest, self).setUp()
......
......@@ -32,6 +32,7 @@ from topydo.lib.TodoList import TodoList
from topydo.lib.Todo import Todo
from topydo.lib.Config import config
class EditCommandTest(CommandTest):
def setUp(self):
super(EditCommandTest, self).setUp()
......
......@@ -24,6 +24,7 @@ from test.Facilities import load_file, todolist_to_string, load_file_to_todolist
from topydo.lib.Todo import Todo
from test.TestTopydo import TopydoTest
class FilterTest(TopydoTest):
def test_filter03(self):
todo = Todo("(C) Relevant")
......@@ -295,6 +296,7 @@ class FilterTest(TopydoTest):
self.assertEqual(todolist_to_string(filtered_todos),
todolist_to_string(reference))
class OrdinalTagFilterTest(TopydoTest):
def setUp(self):
super(OrdinalTagFilterTest, self).setUp()
......@@ -374,6 +376,7 @@ class OrdinalTagFilterTest(TopydoTest):
self.assertEqual(len(result), 1)
self.assertEqual(result[0].source(), self.todo3)
class PriorityFilterTest(TopydoTest):
def setUp(self):
super(PriorityFilterTest, self).setUp()
......
......@@ -19,6 +19,7 @@ import unittest
from topydo.lib.Graph import DirectedGraph
from test.TestTopydo import TopydoTest
class GraphTest(TopydoTest):
def setUp(self):
super(GraphTest, self).setUp()
......
......@@ -22,6 +22,7 @@ from topydo.lib.Importance import importance
from topydo.lib.Todo import Todo
from test.TestTopydo import TopydoTest
class ImportanceTest(TopydoTest):
def test_importance1(self):
todo = Todo("Foo")
......
......@@ -18,6 +18,7 @@ from topydo.lib.JsonPrinter import JsonPrinter
from topydo.lib.Todo import Todo
from test.TestTopydo import TopydoTest
class JsonPrinterTest(TopydoTest):
"""
Tests the functionality of printing a single todo item. Printing a list is
......
......@@ -24,6 +24,7 @@ from topydo.commands.ListCommand import ListCommand
from test.TestCommand import CommandTest
from test.Facilities import load_file_to_todolist
class ListCommandTest(CommandTest):
def setUp(self):
super(ListCommandTest, self).setUp()
......@@ -217,6 +218,7 @@ class ListCommandTest(CommandTest):
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
class ListCommandUnicodeTest(CommandTest):
def setUp(self):
super(ListCommandUnicodeTest, self).setUp()
......@@ -233,6 +235,7 @@ class ListCommandUnicodeTest(CommandTest):
self.assertEqual(self.output, expected)
class ListCommandJsonTest(CommandTest):
def test_json(self):
todolist = load_file_to_todolist("test/data/ListCommandTest.txt")
......@@ -264,6 +267,7 @@ class ListCommandJsonTest(CommandTest):
self.assertEqual(self.output, jsontext)
self.assertEqual(self.errors, "")
def replace_ical_tags(p_text):
# replace identifiers with dots, since they're random.
result = re.sub(r'\bical:....\b', 'ical:....', p_text)
......@@ -271,6 +275,7 @@ def replace_ical_tags(p_text):
return result
class ListCommandIcalTest(CommandTest):
def setUp(self):
self.maxDiff = None
......
......@@ -20,6 +20,7 @@ from topydo.commands.ListContextCommand import ListContextCommand
from test.TestCommand import CommandTest
from test.Facilities import load_file_to_todolist
class ListContextCommandTest(CommandTest):
def test_contexts1(self):
todolist = load_file_to_todolist("test/data/TodoListTest.txt")
......
......@@ -20,6 +20,7 @@ from topydo.commands.ListProjectCommand import ListProjectCommand
from test.TestCommand import CommandTest
from test.Facilities import load_file_to_todolist
class ListProjectCommandTest(CommandTest):
def test_projects1(self):
todolist = load_file_to_todolist("test/data/TodoListTest.txt")
......
......@@ -22,6 +22,7 @@ from topydo.commands.PostponeCommand import PostponeCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
class PostponeCommandTest(CommandTest):
def setUp(self):
super(PostponeCommandTest, self).setUp()
......
......@@ -21,6 +21,7 @@ from topydo.commands.PriorityCommand import PriorityCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
class PriorityCommandTest(CommandTest):
def setUp(self):
super(PriorityCommandTest, self).setUp()
......
......@@ -22,6 +22,7 @@ from topydo.lib.Recurrence import advance_recurring_todo, NoRecurrenceException
from topydo.lib.Todo import Todo
from test.TestTopydo import TopydoTest
class RecurrenceTest(TopydoTest):
def setUp(self):
super(RecurrenceTest, self).setUp()
......
......@@ -20,6 +20,7 @@ import unittest
from topydo.lib.RelativeDate import relative_date_to_date
from test.TestTopydo import TopydoTest
class RelativeDateTester(TopydoTest):
def setUp(self):
super(RelativeDateTester, self).setUp()
......
......@@ -21,6 +21,7 @@ from topydo.commands.SortCommand import SortCommand
from test.TestCommand import CommandTest
from test.Facilities import load_file_to_todolist
class SortCommandTest(CommandTest):
def setUp(self):
super(SortCommandTest, self).setUp()
......
......@@ -22,6 +22,7 @@ from topydo.lib.Sorter import Sorter
from test.Facilities import load_file, todolist_to_string, load_file_to_todolist, print_view
from test.TestTopydo import TopydoTest
class SorterTest(TopydoTest):
def sort_file(self, p_filename, p_filename_ref, p_sorter):
"""
......
......@@ -20,6 +20,7 @@ from topydo.commands.TagCommand import TagCommand
from test.TestCommand import CommandTest
from topydo.lib.TodoList import TodoList
class TagCommandTest(CommandTest):
def setUp(self):
super(TagCommandTest, self).setUp()
......
......@@ -20,14 +20,17 @@ import unittest
from topydo.lib.Todo import Todo
from test.TestTopydo import TopydoTest
def today_date():
today = date.today()
return today.isoformat()
def tomorrow_date():
tomorrow = date.today() + timedelta(days=1)
return tomorrow.isoformat()
class TodoTest(TopydoTest):
def test_due_date1(self):
todo = Todo("(C) Foo due:2014-06-09")
......
......@@ -23,6 +23,7 @@ import unittest
from topydo.lib.TodoBase import TodoBase
from test.TestTopydo import TopydoTest
class TodoBaseTester(TopydoTest):
def test_parse_tag(self):
todo = TodoBase("(C) Test foo:bar foo:baz foo_:baz_ blah:zah:haz")
......
......@@ -20,6 +20,7 @@ import unittest
from test.Facilities import load_file
from test.TestTopydo import TopydoTest
class TodoFileTest(TopydoTest):
def test_empty_file(self):
todofile = load_file('test/data/TodoFileTest1.txt')
......
......@@ -27,6 +27,7 @@ from topydo.lib.TodoList import TodoList
from topydo.lib.TodoListBase import TodoListBase
from test.TestTopydo import TopydoTest
class TodoListTester(TopydoTest):
def setUp(self):
super(TodoListTester, self).setUp()
......@@ -224,6 +225,7 @@ class TodoListTester(TopydoTest):
self.assertNotEqual(self.todolist.number(todo), 't5c')
class TodoListDependencyTester(TopydoTest):
def setUp(self):
super(TodoListDependencyTester, self).setUp()
......@@ -361,6 +363,7 @@ class TodoListDependencyTester(TopydoTest):
self.assertTrue(todolist.todo_by_dep_id('1'))
self.assertFalse(todolist.todo_by_dep_id('2'))
class TodoListCleanDependencyTester(TopydoTest):
def setUp(self):
super(TodoListCleanDependencyTester, self).setUp()
......
......@@ -18,6 +18,7 @@ import unittest
from topydo.lib.Config import config
class TopydoTest(unittest.TestCase):
def tearDown(self):
"""
......
......@@ -23,6 +23,7 @@ from topydo.lib.TodoFile import TodoFile
from topydo.lib.TodoList import TodoList
from test.TestTopydo import TopydoTest
class ViewTest(TopydoTest):
def test_view(self):
""" Check filters and printer for views. """
......
......@@ -52,6 +52,7 @@ _SUBCOMMAND_MAP = {
'tag': 'TagCommand',
}
def get_subcommand(p_args):
"""
Retrieves the to-be executed Command and returns a tuple
......
......@@ -34,6 +34,7 @@ except ConfigError as config_error:
from topydo.Commands import get_subcommand
from topydo.lib import TodoList
class CLIApplication(CLIApplicationBase):
"""
Class that represents the (original) Command Line Interface of Topydo.
......@@ -58,6 +59,7 @@ class CLIApplication(CLIApplicationBase):
else:
self._post_execute()
def main():
""" Main entry point of the CLI. """
CLIApplication().run()
......
......@@ -26,6 +26,7 @@ from six.moves import input
MAIN_OPTS = "ac:d:ht:v"
def usage():
""" Prints the command-line usage of topydo. """
......@@ -61,6 +62,7 @@ Available commands:
Run `topydo help <subcommand>` for command-specific help.
""")
def write(p_file, p_string):
"""
Write p_string to file p_file, trailed by a newline character.
......@@ -73,11 +75,13 @@ def write(p_file, p_string):
if p_string:
p_file.write(p_string + "\n")
def error(p_string):
""" Writes an error on the standard error. """
write(sys.stderr, p_string)
def version():
""" Print the current version and exit. """
from topydo.lib.Version import VERSION, LICENSE
......@@ -103,6 +107,7 @@ from topydo.lib import TodoList
from topydo.lib import TodoListBase
from topydo.lib.Utils import escape_ansi
class CLIApplicationBase(object):
"""
Base class for a Command Line Interfaces (CLI) for topydo. Examples are the
......
......@@ -39,6 +39,7 @@ from topydo.Commands import get_subcommand
from topydo.lib import TodoFile
from topydo.lib import TodoList
def _todotxt_mtime():
"""
Returns the mtime for the configured todo.txt file.
......@@ -49,6 +50,7 @@ def _todotxt_mtime():
# file not found
return None
class PromptApplication(CLIApplicationBase):
"""
This class implements a variant of topydo's CLI showing a shell and
......@@ -112,6 +114,7 @@ class PromptApplication(CLIApplicationBase):
except TypeError:
usage()
def main():
""" Main entry point of the prompt interface. """
PromptApplication().run()
......
......@@ -28,6 +28,7 @@ from topydo.lib.Config import config
from topydo.Commands import _SUBCOMMAND_MAP
from topydo.lib.RelativeDate import relative_date_to_date
def _subcommands(p_word_before_cursor):
""" Generator for subcommand name completion. """
subcommands = [sc for sc in sorted(_SUBCOMMAND_MAP.keys()) if
......@@ -35,6 +36,7 @@ def _subcommands(p_word_before_cursor):
for command in subcommands:
yield Completion(command, -len(p_word_before_cursor))
def _dates(p_word_before_cursor):
""" Generator for date completion. """
def _date_suggestions():
......@@ -79,6 +81,7 @@ def _dates(p_word_before_cursor):
yield Completion(reldate, -len(value), display_meta=to_absolute(reldate))
class TopydoCompleter(Completer):
"""
Completer class that completes projects, contexts, dates and
......
......@@ -25,6 +25,7 @@ if "win32" in sys.platform:
import colorama
colorama.init()
def main():
""" Main entry point of the CLI. """
try:
......
......@@ -28,6 +28,7 @@ from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.TodoListBase import InvalidTodoException
class AddCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -18,6 +18,7 @@ from topydo.lib.Command import Command, InvalidCommandArgument
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.TodoListBase import InvalidTodoException
class AppendCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -16,6 +16,7 @@
from topydo.lib.Command import Command
class ArchiveCommand(Command):
def __init__(self, p_todolist, p_archive_list):
"""
......
......@@ -16,6 +16,7 @@
from topydo.lib.DCommand import DCommand
class DeleteCommand(DCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -22,6 +22,7 @@ from topydo.lib.Sorter import Sorter
from topydo.lib.TodoListBase import InvalidTodoException
from topydo.lib.View import View
class DepCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -17,6 +17,7 @@
from topydo.lib.MultiCommand import MultiCommand
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
class DepriCommand(MultiCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -22,6 +22,7 @@ from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.Recurrence import advance_recurring_todo, NoRecurrenceException
from topydo.lib.Utils import date_string_to_date
class DoCommand(DCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -34,6 +34,7 @@ DEFAULT_EDITOR = 'vi'
# cannot use super() inside the class itself
BASE_TODOLIST = lambda tl: super(TodoList, tl)
class EditCommand(MultiCommand):
def __init__(self, p_args, p_todolist, p_output, p_error, p_input):
super(EditCommand, self).__init__(p_args, p_todolist, p_output,
......
......@@ -18,6 +18,7 @@ import sys
from topydo.lib.Command import Command
class ExitCommand(Command):
"""
A command that exits topydo. Used for the 'exit' and 'quit' subcommands on
......
......@@ -24,6 +24,7 @@ from topydo.lib.PrettyPrinterFilter import (
from topydo.lib.IcalPrinter import IcalPrinter
from topydo.lib.JsonPrinter import JsonPrinter
class ListCommand(ExpressionCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -16,6 +16,7 @@
from topydo.lib.Command import Command
class ListContextCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -16,6 +16,7 @@
from topydo.lib.Command import Command
class ListProjectCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -22,6 +22,7 @@ from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.Utils import date_string_to_date
class PostponeCommand(MultiCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -20,6 +20,7 @@ from topydo.lib.MultiCommand import MultiCommand
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.Utils import is_valid_priority
class PriorityCommand(MultiCommand):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -18,6 +18,7 @@ from topydo.lib.Command import Command, InvalidCommandArgument
from topydo.lib.Config import config
from topydo.lib.Sorter import Sorter
class SortCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -18,6 +18,7 @@ from topydo.lib.Command import Command, InvalidCommandArgument
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
from topydo.lib.TodoListBase import InvalidTodoException
class TagCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -20,6 +20,7 @@ from topydo.lib.Config import config
NEUTRAL_COLOR = '\033[0m'
class Colors(object):
def __init__(self):
self.priority_colors = config().priority_colors()
......
......@@ -18,9 +18,11 @@ import getopt
from topydo.lib.PrettyPrinter import PrettyPrinter
class InvalidCommandArgument(Exception):
pass
class Command(object):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......
......@@ -18,6 +18,7 @@ import os
from six.moves import configparser
class ConfigError(Exception):
def __init__(self, p_text):
self.text = p_text
......@@ -25,6 +26,7 @@ class ConfigError(Exception):
def __str__(self):
return self.text
class _Config:
def __init__(self, p_path=None, p_overrides=None):
"""
......@@ -252,6 +254,7 @@ class _Config:
except ValueError:
return self.defaults['auto_creation_date'] == '1'
def config(p_path=None, p_overrides=None):
"""
Retrieve the config instance.
......
......@@ -20,6 +20,7 @@ from topydo.lib.MultiCommand import MultiCommand
from topydo.lib.PrettyPrinter import PrettyPrinter
from topydo.lib.PrettyPrinterFilter import PrettyPrinterNumbers
class DCommand(MultiCommand):
"""
A common class for the 'do' and 'del' operations, because they're quite
......
......@@ -22,6 +22,7 @@ from topydo.lib import Filter
from topydo.lib.Sorter import Sorter
from topydo.lib.View import View
class ExpressionCommand(Command):
"""
A common class for commands operating on todos selected by expressions.
......
......@@ -19,6 +19,7 @@ import re
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.Utils import date_string_to_date
class Filter(object):
def filter(self, p_todos):
"""
......@@ -31,6 +32,7 @@ class Filter(object):
def match(self, _):
raise NotImplementedError
class NegationFilter(Filter):
def __init__(self, p_filter):
self._filter = p_filter
......@@ -38,6 +40,7 @@ class NegationFilter(Filter):
def match(self, p_todo):
return not self._filter.match(p_todo)
class AndFilter(Filter):
def __init__(self, p_filter1, p_filter2):
self._filter1 = p_filter1
......@@ -46,6 +49,7 @@ class AndFilter(Filter):
def match(self, p_todo):
return self._filter1.match(p_todo) and self._filter2.match(p_todo)
class OrFilter(Filter):
def __init__(self, p_filter1, p_filter2):
self._filter1 = p_filter1
......@@ -54,6 +58,7 @@ class OrFilter(Filter):
def match(self, p_todo):
return self._filter1.match(p_todo) or self._filter2.match(p_todo)
class GrepFilter(Filter):
""" Matches when the todo text contains a text. """
......@@ -80,6 +85,7 @@ class GrepFilter(Filter):
return string.find(expr) != -1
class RelevanceFilter(Filter):
"""
Matches when the todo is relevant, i.e.:
......@@ -99,6 +105,7 @@ class RelevanceFilter(Filter):
return p_todo.is_active() and is_due
class DependencyFilter(Filter):
""" Matches when a todo has no unfinished child tasks. """
def __init__(self, p_todolist):
......@@ -120,6 +127,7 @@ class DependencyFilter(Filter):
return not uncompleted
class InstanceFilter(Filter):
def __init__(self, p_todos):
"""
......@@ -143,6 +151,7 @@ class InstanceFilter(Filter):
except ValueError:
return False
class LimitFilter(Filter):
def __init__(self, p_limit):
super(LimitFilter, self).__init__()
......@@ -153,6 +162,7 @@ class LimitFilter(Filter):
OPERATOR_MATCH = r"(?P<operator><=?|=|>=?|!)?"
class OrdinalFilter(Filter):
"""
Base class for ordinal filters.
......@@ -193,6 +203,7 @@ class OrdinalFilter(Filter):
ORDINAL_TAG_MATCH = r"(?P<key>[^:]*):" + OPERATOR_MATCH + r"(?P<value>\S+)"
class OrdinalTagFilter(OrdinalFilter):
def __init__(self, p_expression):
super(OrdinalTagFilter, self).__init__(p_expression, ORDINAL_TAG_MATCH)
......@@ -235,6 +246,7 @@ class OrdinalTagFilter(OrdinalFilter):
PRIORITY_MATCH = r"\(" + OPERATOR_MATCH + r"(?P<value>[A-Z]{1})\)"
class PriorityFilter(OrdinalFilter):
def __init__(self, p_expression):
super(PriorityFilter, self).__init__(p_expression, PRIORITY_MATCH)
......
......@@ -16,6 +16,7 @@
""" Contains the class for a directed graph. """
class DirectedGraph(object):
"""
Represents a simple directed graph, used for tracking todo
......
......@@ -27,6 +27,7 @@ _TABLE_SIZES = {
4: 1679609 # largest prime under zzzz_36
}
def _to_base36(p_value):
"""
Converts integer to base36 string.
......@@ -43,6 +44,7 @@ def _to_base36(p_value):
return base36 or alphabet[0]
def hash_list_values(p_list, p_key=lambda i: i):
"""
Calculates a unique value for each item in the list, these can be used as
......
......@@ -25,6 +25,7 @@ import string
from topydo.lib.PrettyPrinter import Printer
def _convert_priority(p_priority):
"""
Converts todo.txt priority to an iCalendar priority (RFC 2445).
......@@ -55,6 +56,7 @@ def _convert_priority(p_priority):
return result
class IcalPrinter(Printer):
"""
A printer that converts a list of Todo items to a string in iCalendar
......
......@@ -29,6 +29,7 @@ from topydo.lib.Config import config
IMPORTANCE_VALUE = {'A': 3, 'B': 2, 'C': 1}
def is_due_next_monday(p_todo):
""" Returns True when the given task is due next Monday. """
today = date.today()
......@@ -37,6 +38,7 @@ def is_due_next_monday(p_todo):
return due and due.weekday() == 0 and today.weekday() >= 4 and \
p_todo.days_till_due()
def importance(p_todo, p_ignore_weekend=config().ignore_weekends()):
"""
Calculates the importance of the given task.
......@@ -74,6 +76,7 @@ def importance(p_todo, p_ignore_weekend=config().ignore_weekends()):
return result if not p_todo.is_completed() else 0
def average_importance(p_todo, p_ignore_weekend=config().ignore_weekends()):
own_importance = importance(p_todo, p_ignore_weekend)
......
......@@ -23,6 +23,7 @@ import json
from topydo.lib.PrettyPrinter import Printer
def _convert_todo(p_todo):
""" Converts a Todo instance to a dictionary. """
creation_date = p_todo.creation_date()
......@@ -44,6 +45,7 @@ def _convert_todo(p_todo):
return result
class JsonPrinter(Printer):
"""
A printer that converts a list of Todo items to a string in JSON format.
......
......@@ -19,6 +19,7 @@ from six import u
from topydo.lib.ExpressionCommand import ExpressionCommand
from topydo.lib.TodoListBase import InvalidTodoException
class MultiCommand(ExpressionCommand):
"""
A common class for operations that can work with multiple todo IDs.
......
......@@ -19,6 +19,7 @@ from topydo.lib.PrettyPrinterFilter import (
PrettyPrinterNumbers
)
class Printer(object):
"""
An abstract class that turns todo items into strings.
......@@ -35,6 +36,7 @@ class Printer(object):
"""
return "\n".join([self.print_todo(todo) for todo in p_todos])
class PrettyPrinter(Printer):
"""
Prints todo items on a single line, decorated by the filters passed by
......@@ -68,6 +70,7 @@ class PrettyPrinter(Printer):
return todo_str
def pretty_printer_factory(p_todolist, p_additional_filters=None):
""" Returns a pretty printer suitable for the ls and dep subcommands. """
......
......@@ -22,6 +22,7 @@ from six import u
from topydo.lib.Config import config
from topydo.lib.Colors import Colors, NEUTRAL_COLOR
class PrettyPrinterFilter(object):
"""
Base class for a pretty printer filter.
......@@ -35,6 +36,7 @@ class PrettyPrinterFilter(object):
"""
raise NotImplementedError
class PrettyPrinterColorFilter(PrettyPrinterFilter):
"""
Adds colors to the todo string by inserting ANSI codes.
......@@ -84,6 +86,7 @@ class PrettyPrinterColorFilter(PrettyPrinterFilter):
return p_todo_str
class PrettyPrinterIndentFilter(PrettyPrinterFilter):
""" Adds indentation to the todo item. """
def __init__(self, p_indent=0):
......@@ -94,6 +97,7 @@ class PrettyPrinterIndentFilter(PrettyPrinterFilter):
""" Applies the indentation. """
return ' ' * self.indent + p_todo_str
class PrettyPrinterNumbers(PrettyPrinterFilter):
""" Prepends the todo's number, retrieved from the todolist. """
def __init__(self, p_todolist):
......@@ -104,6 +108,7 @@ class PrettyPrinterNumbers(PrettyPrinterFilter):
""" Prepends the number to the todo string. """
return u("|{:>3}| {}").format(self.todolist.number(p_todo), p_todo_str)
class PrettyPrinterHideTagFilter(PrettyPrinterFilter):
""" Removes all occurences of the given tags from the text. """
def __init__(self, p_hidden_tags):
......
......@@ -22,9 +22,11 @@ from topydo.lib.Config import config
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.Todo import Todo
class NoRecurrenceException(Exception):
pass
def advance_recurring_todo(p_todo, p_offset=None, p_strict=False):
"""
Given a Todo item, return a new instance of a Todo item with the dates
......
......@@ -20,6 +20,7 @@ from datetime import date, timedelta
import calendar
import re
def _add_months(p_sourcedate, p_months):
"""
Adds a number of months to the source date.
......@@ -35,6 +36,7 @@ def _add_months(p_sourcedate, p_months):
return date(year, month, day)
def _convert_pattern(p_length, p_periodunit, p_offset=None):
"""
Converts a pattern in the form [0-9][dwmy] and returns a date from the
......@@ -56,6 +58,7 @@ def _convert_pattern(p_length, p_periodunit, p_offset=None):
return result
def _convert_weekday_pattern(p_weekday):
"""
Converts a weekday name to an absolute date.
......@@ -81,6 +84,7 @@ def _convert_weekday_pattern(p_weekday):
shift = (target_day - day) % 7
return date.today() + timedelta(shift)
def relative_date_to_date(p_date, p_offset=None):
"""
Transforms a relative date into a date object.
......
......@@ -21,10 +21,12 @@ import re
from topydo.lib.Importance import importance, average_importance
def is_priority_field(p_field):
""" Returns True when the field name denotes the priority. """
return p_field.startswith('prio')
def get_field_function(p_field):
"""
Given a property (string) of a todo, return a function that attempts to
......@@ -59,6 +61,7 @@ def get_field_function(p_field):
return result
class Sorter(object):
"""
This class sorts a todo list.
......
......@@ -24,6 +24,7 @@ from topydo.lib.Config import config
from topydo.lib.TodoBase import TodoBase
from topydo.lib.Utils import date_string_to_date
class Todo(TodoBase):
"""
This class adds common functionality with respect to dates to the Todo
......
......@@ -25,6 +25,7 @@ from six import u
from topydo.lib.TodoParser import parse_line
from topydo.lib.Utils import is_valid_priority
class TodoBase(object):
"""
This class represents a single todo item in a todo.txt file. It maintains
......
......@@ -20,6 +20,7 @@ This module deals with todo.txt files.
import codecs
class TodoFile(object):
"""
This class represents a todo.txt file, which can be read from or written
......
......@@ -22,6 +22,7 @@ from topydo.lib.Config import config
from topydo.lib.Graph import DirectedGraph
from topydo.lib.TodoListBase import TodoListBase
class TodoList(TodoListBase):
"""
Provides operations for a todo list, such as adding items, removing them,
......
......@@ -29,9 +29,11 @@ from topydo.lib.PrettyPrinter import PrettyPrinter
from topydo.lib.Todo import Todo
from topydo.lib.View import View
class InvalidTodoException(Exception):
pass
class TodoListBase(object):
"""
Provides operations for a todo list, such as adding items, removing them,
......
......@@ -37,6 +37,7 @@ _TAG_MATCH = re.compile('(?P<key>[^:]+):(?P<value>.+)')
_PROJECT_MATCH = re.compile(r'\+(\S*\w)')
_CONTEXT_MATCH = re.compile(r'@(\S*\w)')
def parse_line(p_string):
"""
Parses a single line as can be encountered in a todo.txt file.
......
......@@ -21,6 +21,7 @@ Various utility functions.
from datetime import date
import re
def date_string_to_date(p_date):
"""
Given a date in YYYY-MM-DD, returns a Python date object. Returns None
......@@ -41,9 +42,11 @@ def date_string_to_date(p_date):
return result
def is_valid_priority(p_priority):
return p_priority != None and re.match(r'^[A-Z]$', p_priority) != None
def escape_ansi(p_string):
return escape_ansi.pattern.sub('', p_string)
......
......@@ -16,6 +16,7 @@
""" A view is a list of todos, sorted and filtered. """
class View(object):
"""
A view is instantiated by a todo list, usually obtained from a todo.txt
......
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