Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
8b9e3877
Commit
8b9e3877
authored
Feb 20, 2017
by
Jacek Sowiński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show error message when parsing of -F fails
parent
edc11eeb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
9 deletions
+30
-9
test/test_list_format.py
test/test_list_format.py
+8
-0
topydo/commands/ListCommand.py
topydo/commands/ListCommand.py
+9
-4
topydo/lib/ListFormat.py
topydo/lib/ListFormat.py
+13
-5
No files found.
test/test_list_format.py
View file @
8b9e3877
...
...
@@ -710,6 +710,14 @@ x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
def test_list_format47(self):
command = ListCommand(["-x", "-F", "%(r)"], self.todolist, self.out, self.error)
command.execute()
error = '
Error
while
parsing
format
string
(
list_format
config
option
or
-
F
)
\
n
'
self.assertEqual(self.output, '')
self.assertEqual(self.errors, error)
if __name__ == '
__main__
':
unittest.main()
topydo/commands/ListCommand.py
View file @
8b9e3877
...
...
@@ -21,6 +21,7 @@ import os
from
topydo.lib.Config
import
config
from
topydo.lib.ExpressionCommand
import
ExpressionCommand
from
topydo.lib.Filter
import
HiddenTagFilter
,
InstanceFilter
from
topydo.lib.ListFormat
import
ListFormatError
from
topydo.lib.printers.PrettyPrinter
import
pretty_printer_factory
from
topydo.lib.prettyprinters.Format
import
PrettyPrinterFormatFilter
from
topydo.lib.TodoListBase
import
InvalidTodoException
...
...
@@ -148,10 +149,14 @@ class ListCommand(ExpressionCommand):
self
.
printer
=
pretty_printer_factory
(
self
.
todolist
,
filters
)
try
:
if
self
.
group_expression
:
self
.
out
(
self
.
printer
.
print_groups
(
self
.
_view
().
groups
))
else
:
self
.
out
(
self
.
printer
.
print_list
(
self
.
_view
().
todos
))
except
ListFormatError
:
self
.
error
(
'Error while parsing format string (list_format config'
' option or -F)'
)
def
_view
(
self
):
sorter
=
Sorter
(
self
.
sort_expression
,
self
.
group_expression
)
...
...
topydo/lib/ListFormat.py
View file @
8b9e3877
...
...
@@ -129,6 +129,11 @@ def color_block(p_todo):
config
().
priority_color
(
p_todo
.
priority
()).
as_ansi
(),
)
class
ListFormatError
(
Exception
):
pass
class
ListFormatParser
(
object
):
""" Parser of format string. """
def
__init__
(
self
,
p_todolist
,
p_format
=
None
):
...
...
@@ -264,11 +269,14 @@ class ListFormatParser(object):
if placeholder == '
S
':
repl_trunc = repl
try:
if repl == '':
substr = re.sub(pattern, '', substr)
else:
substr = re.sub(pattern, _strip_placeholder_braces, substr)
substr = re.sub(r'
(
?
<
!
\\
)
%
({
ph
}
|
\
[{
ph
}
\
])
'.format(ph=placeholder), repl, substr)
except re.error:
raise ListFormatError
parsed_list.append(substr)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment