Commit 43c6beee authored by Bram Schoenmakers's avatar Bram Schoenmakers

Various pylint fixes.

parent f56bd7e2
......@@ -30,8 +30,10 @@ class AddCommand(Command.Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(AddCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(AddCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
self.text = ' '.join(p_args)
self.todo = None
def _preprocess_input_todo(self):
"""
......@@ -102,7 +104,8 @@ class AddCommand(Command.Command):
return """Synopsis: add <text>"""
def help(self):
return """This subcommand automatically adds the creation date to the added item.
return """\
This subcommand automatically adds the creation date to the added item.
<text> may contain:
......
......@@ -23,7 +23,8 @@ class AppendCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(AppendCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt=lambda a: None)
super(AppendCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt=lambda a: None)
def execute(self):
if not super(AppendCommand, self).execute():
......@@ -48,4 +49,6 @@ class AppendCommand(Command):
return """Synopsis: append <number> <text>"""
def help(self):
return """Adds the given <text> to the end of the todo indicated by <number>."""
return """\
Adds the given <text> to the end of the todo indicated by <number>.
"""
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......
......@@ -73,9 +73,9 @@ class Command(object):
def getopt(self, p_flags, p_long=[]):
try:
result = getopt.getopt(self.args, p_flags, p_long)
except getopt.GetoptError as e:
self.error(str(e))
result = ([],self.args)
except getopt.GetoptError as goe:
self.error(str(goe))
result = ([], self.args)
return result
......
......@@ -146,8 +146,8 @@ def config(p_path=None):
if not config.instance or p_path != None:
try:
config.instance = _Config(p_path)
except ConfigParser.ParsingError as e:
raise ConfigError(str(e))
except ConfigParser.ParsingError as perr:
raise ConfigError(str(perr))
return config.instance
......
......@@ -30,7 +30,8 @@ class DCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(DCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(DCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
self.force = False
......@@ -63,7 +64,9 @@ class DCommand(Command):
self.args = args
def _uncompleted_children(self, p_todo):
return sorted([t for t in self.todolist.children(p_todo) if not t.is_completed()])
return sorted(
[t for t in self.todolist.children(p_todo) if not t.is_completed()]
)
def _print_list(self, p_todos, p_print_numbers=True):
filters = []
......@@ -81,17 +84,17 @@ class DCommand(Command):
return ""
def _process_subtasks(self):
children = self._uncompleted_children(self.todo)
if children:
self._print_list(children)
children = self._uncompleted_children(self.todo)
if children:
self._print_list(children)
if not self.force:
confirmation = self.prompt(self.prompt_text())
if not self.force:
confirmation = self.prompt(self.prompt_text())
if not self.force and re.match('^y(es)?$', confirmation, re.I):
for child in children:
self.execute_specific_core(child)
self.out(self.prefix() + pretty_print(child))
if not self.force and re.match('^y(es)?$', confirmation, re.I):
for child in children:
self.execute_specific_core(child)
self.out(self.prefix() + pretty_print(child))
def _print_unlocked_todos(self, p_old, p_new):
delta = [todo for todo in p_new if todo not in p_old]
......@@ -109,10 +112,13 @@ class DCommand(Command):
Since these todos pop up at the end of the list, we cut off the list
just before that point.
"""
return [todo for todo in self.todolist.todos()[:self.length] if not self._uncompleted_children(todo) and todo.is_active()]
return [todo for todo in self.todolist.todos()[:self.length]
if not self._uncompleted_children(todo) and todo.is_active()]
def condition(self):
""" An additional condition whether execute_specific should be executed. """
"""
An additional condition whether execute_specific should be executed.
"""
return True
def condition_failed_text(self):
......
......@@ -22,7 +22,8 @@ class DeleteCommand(DCommand):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(DeleteCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(DeleteCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def prompt_text(self):
return "Also remove subtasks? [y/N] "
......
......@@ -26,7 +26,8 @@ class DepCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(DepCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(DepCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
try:
self.subsubcommand = self.argument(0)
......@@ -130,7 +131,10 @@ class DepCommand(Command):
dep clean"""
def help(self):
return """* add: Adds a dependency. Using 1 before 2 creates a dependency from todo item 2 to 1.
* rm (alias: del): Removes a dependency.
* ls: Lists all dependencies to or from a certain todo.
* clean (alias: gc): Removes redundant id or p tags."""
return """\
* add : Adds a dependency. Using 1 before 2 creates a dependency
from todo item 2 to 1.
* rm (alias: del) : Removes a dependency.
* ls : Lists all dependencies to or from a certain todo.
* clean (alias: gc): Removes redundant id or p tags.
"""
......@@ -23,7 +23,8 @@ class DepriCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(DepriCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(DepriCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self):
if not super(DepriCommand, self).execute():
......
......@@ -30,7 +30,8 @@ class DoCommand(DCommand):
self.strict_recurrence = False
self.completion_date = date.today()
super(DoCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(DoCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def get_flags(self):
""" Additional flags. """
......@@ -59,7 +60,9 @@ class DoCommand(DCommand):
return "Completed: "
def condition(self):
""" An additional condition whether execute_specific should be executed. """
"""
An additional condition whether execute_specific should be executed.
"""
return not self.todo.is_completed()
def condition_failed_text(self):
......
......@@ -60,6 +60,8 @@ class GrepFilter(Filter):
""" Matches when the todo text contains a text. """
def __init__(self, p_expression, p_case_sensitive=None):
super(GrepFilter, self).__init__()
self.expression = p_expression
if p_case_sensitive != None:
......@@ -107,6 +109,7 @@ class DependencyFilter(Filter):
Pass on a TodoList instance such that the dependencies can be
looked up.
"""
super(DependencyFilter, self).__init__()
self.todolist = p_todolist
def match(self, p_todo):
......@@ -128,6 +131,7 @@ class InstanceFilter(Filter):
This is handy for constructing a view given a plain list of Todo items.
"""
super(InstanceFilter, self).__init__()
self.todos = p_todos
def match(self, p_todo):
......@@ -142,6 +146,7 @@ class InstanceFilter(Filter):
class LimitFilter(Filter):
def __init__(self, p_limit):
super(LimitFilter, self).__init__()
self.limit = p_limit
def filter(self, p_todos):
......@@ -151,6 +156,7 @@ ORDINAL_TAG_MATCH = r"(?P<key>[^:]*):(?P<operator><=?|=|>=?|!)?(?P<value>\S*)"
class OrdinalTagFilter(Filter):
def __init__(self, p_expression):
super(OrdinalTagFilter, self).__init__()
match = re.match(ORDINAL_TAG_MATCH, p_expression)
if match:
self.key = match.group('key')
......
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -27,7 +27,8 @@ class ListCommand(Command.Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(ListCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(ListCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
self.sort_expression = config().sort_string()
self.show_all = False
......@@ -35,11 +36,11 @@ class ListCommand(Command.Command):
def _process_flags(self):
opts, args = self.getopt('s:x')
for o, a in opts:
if o == '-x':
for opt, value in opts:
if opt == '-x':
self.show_all = True
elif o == '-s':
self.sort_expression = a
elif opt == '-s':
self.sort_expression = value
self.args = args
......@@ -53,7 +54,8 @@ class ListCommand(Command.Command):
argfilter = Filter.OrdinalTagFilter(arg)
elif len(arg) > 1 and arg[0] == '-':
# when a word starts with -, exclude it
argfilter = Filter.NegationFilter(Filter.GrepFilter(arg[1:]))
argfilter = Filter.GrepFilter(arg[1:])
argfilter = Filter.NegationFilter(argfilter)
else:
argfilter = Filter.GrepFilter(arg)
......@@ -88,7 +90,8 @@ class ListCommand(Command.Command):
return """Synopsis: ls [-x] [-s <sort_expression>] [expression]"""
def help(self):
return """Lists all relevant todos. A todo is relevant when:
return """\
Lists all relevant todos. A todo is relevant when:
* has not been completed yet;
* the start date (if present) has passed;
......@@ -98,4 +101,5 @@ When an expression is given, only the todos matching that expression are shown.
-s : Sort the list according to a sort expression. Defaults to the expression
in the configuration.
-x : Show all todos (i.e. do not filter on dependencies or relevance)."""
-x : Show all todos (i.e. do not filter on dependencies or relevance).
"""
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -21,7 +21,8 @@ class ListContextCommand(Command.Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(ListContextCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(ListContextCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self):
if not super(ListContextCommand, self).execute():
......@@ -31,7 +32,7 @@ class ListContextCommand(Command.Command):
self.out(context)
def usage(self):
return """Synopsis: lscon"""
return """Synopsis: lscon"""
def help(self):
return """Lists all contexts in the todo list."""
return """Lists all contexts in the todo list."""
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -21,7 +21,8 @@ class ListProjectCommand(Command.Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(ListProjectCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(ListProjectCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self):
if not super(ListProjectCommand, self).execute():
......@@ -31,7 +32,7 @@ class ListProjectCommand(Command.Command):
self.out(project)
def usage(self):
return """Synopsis: lscon"""
return """Synopsis: lscon"""
def help(self):
return """Lists all projects in the todo list."""
return """Lists all projects in the todo list."""
......@@ -28,15 +28,16 @@ class PostponeCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(PostponeCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(PostponeCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
self.move_start_date = False
def _process_flags(self):
opts, args = self.getopt('s')
for o, a in opts:
if o == '-s':
for opt, _ in opts:
if opt == '-s':
self.move_start_date = True
self.args = args
......@@ -86,7 +87,8 @@ class PostponeCommand(Command):
return "Synopsis: postpone [-s] <NUMBER> <PATTERN>"
def help(self):
return """Postpone a todo item with the given number and the given pattern.
return """\
Postpone a todo item with the given number and the given pattern.
Postponing is done by adjusting the due date of the todo, and if the -s flag is
given, the start date accordingly.
......@@ -94,4 +96,5 @@ given, the start date accordingly.
The pattern is a relative date, written in the format <COUNT><PERIOD> where
count is a number and <PERIOD> is either 'd', 'w', 'm' or 'y', which stands for
days, weeks, months and years respectively. Example: 'postpone 1 1w' postpones
todo number 1 for 1 week."""
todo number 1 for 1 week.
"""
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -46,7 +46,9 @@ def pp_color(p_todo_str, p_todo):
p_todo_str = '%s%s%s' % (color, p_todo_str, NEUTRAL_COLOR)
if config().highlight_projects_contexts():
p_todo_str = re.sub(r'\B(\+|@)(\S*\w)', PROJECT_COLOR + r'\g<0>' + color, \
p_todo_str = re.sub(
r'\B(\+|@)(\S*\w)',
PROJECT_COLOR + r'\g<0>' + color,
p_todo_str)
p_todo_str += NEUTRAL_COLOR
......
......@@ -24,7 +24,8 @@ class PriorityCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(PriorityCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(PriorityCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self):
if not super(PriorityCommand, self).execute():
......@@ -61,4 +62,6 @@ class PriorityCommand(Command):
return """Synopsis: pri <NUMBER> <PRIORITY>"""
def help(self):
return """Sets the priority of todo the given number to the given priority."""
return """\
Sets the priority of todo the given number to the given priority.
"""
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -81,7 +81,18 @@ def relative_date_to_date(p_date, p_offset=date.today()):
p_date = p_date.lower()
relative = re.match('(?P<length>[0-9]+)(?P<period>[dwmy])$', p_date, re.I)
weekday = re.match('mo(n(day)?)?$|tu(e(sday)?)?$|we(d(nesday)?)?$|th(u(rsday)?)?$|fr(i(day)?)?$|sa(t(urday)?)?$|su(n(day)?)?$', p_date)
monday = 'mo(n(day)?)?$'
tuesday = 'tu(e(sday)?)?$'
wednesday = 'we(d(nesday)?)?$'
thursday = 'th(u(rsday)?)?$'
friday = 'fr(i(day)?)?$'
saturday = 'sa(t(urday)?)?$'
sunday = 'su(n(day)?)?$'
weekday = re.match('|'.join(
[monday, tuesday, wednesday, thursday, friday, saturday, sunday]),
p_date)
if relative:
length = relative.group('length')
......
......@@ -23,7 +23,8 @@ class SortCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(SortCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(SortCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
def execute(self):
if not super(SortCommand, self).execute():
......@@ -46,8 +47,9 @@ class SortCommand(Command):
return """Synopsis: sort [expression]"""
def help(self):
return """Sorts the file according to the expression. If no expression is given,
the expression in the configuration is used.
return """\
Sorts the file according to the expression. If no expression is given, the
expression in the configuration is used.
The following sort properties are supported:
......
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -45,9 +45,9 @@ def get_field_function(p_field):
result = (lambda a: a.completion_date() if a.completion_date() \
else date.max)
elif p_field == 'importance':
result = lambda a: importance(a)
result = importance
elif p_field == 'importance-avg' or p_field == 'importance-average':
result = lambda a: average_importance(a)
result = average_importance
elif p_field == 'text':
result = lambda a: a.text()
else:
......
......@@ -23,7 +23,8 @@ class TagCommand(Command):
p_out=lambda a: None,
p_err=lambda a: None,
p_prompt=lambda a: None):
super(TagCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
super(TagCommand, self).__init__(
p_args, p_todolist, p_out, p_err, p_prompt)
self.force = False
self.force_add = False
......@@ -31,10 +32,11 @@ class TagCommand(Command):
self.tag = None
self.value = None
self.values = []
self.current_values = []
def _process_flags(self):
flags, args = self.getopt("af")
for flag, value in flags:
for flag, _ in flags:
if flag == "-a":
self.force_add = True
elif flag == "-f":
......@@ -70,7 +72,8 @@ class TagCommand(Command):
for i, value in enumerate(self.current_values):
self.out("%2d. %s" % (i + 1, value))
answer = self.prompt('Which value to remove? Enter number or "all": ')
answer = self.prompt(
'Which value to remove? Enter number or "all": ')
if answer != "all":
try:
......@@ -118,9 +121,12 @@ class TagCommand(Command):
return """Synopsis: tag [-a] [-f] <NUMBER> <tag> [<value>]"""
def help(self):
return """Sets the given tag to the given todo number with the given value. If
the value is omitted, the tag is removed from the todo item.
-a : Do not change the current value of the tag if it exists, but add a new value.
-f : Force setting/removing all values of the tag. Prevents interaction with the user.
"""
return """\
Sets the given tag to the given todo number with the given value. If the value
is omitted, the tag is removed from the todo item.
-a : Do not change the current value of the tag if it exists, but add a new
value.
-f : Force setting/removing all values of the tag. Prevents interaction with the
user.
"""
......@@ -145,7 +145,8 @@ class TodoList(TodoListBase.TodoListBase):
Returns a list of parent todos that (in)directly depend on the
given todo.
"""
parents = self._depgraph.incoming_neighbors(hash(p_todo), not p_only_direct)
parents = self._depgraph.incoming_neighbors(
hash(p_todo), not p_only_direct)
return [self._tododict[parent] for parent in parents]
def children(self, p_todo, p_only_direct=False):
......@@ -167,7 +168,9 @@ class TodoList(TodoListBase.TodoListBase):
"""
def clean_by_tag(tag_name):
""" Generic function to handle 'p' and 'id' tags. """
for todo in [todo for todo in self._todos if todo.has_tag(tag_name)]:
for todo in [todo for todo in self._todos
if todo.has_tag(tag_name)]:
value = todo.tag_value(tag_name)
if not self._depgraph.has_edge_id(value):
todo.remove_tag(tag_name, value)
......
......@@ -185,7 +185,8 @@ class TodoListBase(object):
A filter for the pretty printer to append the todo number to the
printed todo.
"""
return lambda p_todo_str, p_todo: "%3d %s" % (self.number(p_todo), p_todo_str)
return lambda p_todo_str, p_todo: \
"%3d %s" % (self.number(p_todo), p_todo_str)
def __str__(self):
return '\n'.join(pretty_print_list(self._todos))
......
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -23,12 +23,19 @@ import re
import Utils
_date_match = r'\d{4}-\d{2}-\d{2}'
_completed_head_match = re.compile(r'x ((?P<completionDate>' + _date_match + ') )' + '((?P<creationDate>' + _date_match + ') )?(?P<rest>.*)')
_normal_head_match = re.compile(r'(\((?P<priority>[A-Z])\) )?' + '((?P<creationDate>' + _date_match + ') )?(?P<rest>.*)')
_tag_match = re.compile('(?P<key>[^:]*):(?P<value>.*)')
_project_match = re.compile(r'\+(\S*\w)')
_context_match = re.compile(r'@(\S*\w)')
_DATE_MATCH = r'\d{4}-\d{2}-\d{2}'
_COMPLETED_HEAD_MATCH = re.compile(
r'x ((?P<completionDate>' + _DATE_MATCH + ') )' + '((?P<creationDate>' +
_DATE_MATCH + ') )?(?P<rest>.*)')
_NORMAL_HEAD_MATCH = re.compile(
r'(\((?P<priority>[A-Z])\) )?' + '((?P<creationDate>' + _DATE_MATCH +
') )?(?P<rest>.*)')
_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):
"""
......@@ -52,8 +59,8 @@ def parse_line(p_string):
'tags': []
}
completed_head = _completed_head_match.match(p_string)
normal_head = _normal_head_match.match(p_string)
completed_head = _COMPLETED_HEAD_MATCH.match(p_string)
normal_head = _NORMAL_HEAD_MATCH.match(p_string)
rest = p_string
......@@ -76,15 +83,15 @@ def parse_line(p_string):
rest = normal_head.group('rest')
for word in rest.split():
project = _project_match.match(word)
project = _PROJECT_MATCH.match(word)
if project:
result['projects'].append(project.group(1))
context = _context_match.match(word)
context = _CONTEXT_MATCH.match(word)
if context:
result['contexts'].append(context.group(1))
tag = _tag_match.match(word)
tag = _TAG_MATCH.match(word)
if tag:
result['tags'].append((tag.group('key'), tag.group('value')))
continue
......
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -44,7 +44,7 @@ class View(object):
def pretty_print(self, p_pp_filters=[]):
""" Pretty prints the view. """
pp_filters = [self._todolist.pp_number(), pp_color] + p_pp_filters;
pp_filters = [self._todolist.pp_number(), pp_color] + p_pp_filters
return '\n'.join(pretty_print_list(self._viewdata, pp_filters))
def __str__(self):
......
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