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
b2f34ad9
Commit
b2f34ad9
authored
Feb 03, 2016
by
Jacek Sowiński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't crash on shlex.split error
Show some meaningful error messages instead. Fixes #107
parent
3adbc019
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
10 deletions
+38
-10
test/data/aliases.conf
test/data/aliases.conf
+1
-0
test/test_get_sub_command.py
test/test_get_sub_command.py
+10
-2
topydo/Commands.py
topydo/Commands.py
+6
-2
topydo/cli/CLI.py
topydo/cli/CLI.py
+5
-1
topydo/cli/Prompt.py
topydo/cli/Prompt.py
+8
-1
topydo/lib/Config.py
topydo/lib/Config.py
+8
-4
No files found.
test/data/aliases.conf
View file @
b2f34ad9
...
@@ -4,3 +4,4 @@ baz = FooBar
...
@@ -4,3 +4,4 @@ baz = FooBar
format
=
ls
-
F
"|I| x c d {(}p{)} s k"
-
n
25
format
=
ls
-
F
"|I| x c d {(}p{)} s k"
-
n
25
smile
=
ls
☻
smile
=
ls
☻
star
=
tag
{}
star
1
star
=
tag
{}
star
1
quot
=
lol
'
d
test/test_get_sub_command.py
View file @
b2f34ad9
...
@@ -21,9 +21,8 @@ from topydo.Commands import get_subcommand
...
@@ -21,9 +21,8 @@ from topydo.Commands import get_subcommand
from
topydo.commands.AddCommand
import
AddCommand
from
topydo.commands.AddCommand
import
AddCommand
from
topydo.commands.DeleteCommand
import
DeleteCommand
from
topydo.commands.DeleteCommand
import
DeleteCommand
from
topydo.commands.ListCommand
import
ListCommand
from
topydo.commands.ListCommand
import
ListCommand
from
topydo.commands.ListProjectCommand
import
ListProjectCommand
from
topydo.commands.TagCommand
import
TagCommand
from
topydo.commands.TagCommand
import
TagCommand
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
,
ConfigError
class
GetSubcommandTest
(
TopydoTest
):
class
GetSubcommandTest
(
TopydoTest
):
def
test_normal_cmd
(
self
):
def
test_normal_cmd
(
self
):
...
@@ -120,6 +119,15 @@ class GetSubcommandTest(TopydoTest):
...
@@ -120,6 +119,15 @@ class GetSubcommandTest(TopydoTest):
real_cmd
,
final_args
=
get_subcommand
(
args
)
real_cmd
,
final_args
=
get_subcommand
(
args
)
self
.
assertEqual
(
real_cmd
,
None
)
self
.
assertEqual
(
real_cmd
,
None
)
def
test_alias_quotation
(
self
):
config
(
"test/data/aliases.conf"
)
args
=
[
"quot"
]
with
self
.
assertRaises
(
ConfigError
)
as
ce
:
get_subcommand
(
args
)
self
.
assertEqual
(
str
(
ce
.
exception
),
'No closing quotation'
)
def
test_help
(
self
):
def
test_help
(
self
):
real_cmd
,
final_args
=
get_subcommand
([
'help'
,
'nonexisting'
])
real_cmd
,
final_args
=
get_subcommand
([
'help'
,
'nonexisting'
])
self
.
assertFalse
(
real_cmd
)
self
.
assertFalse
(
real_cmd
)
...
...
topydo/Commands.py
View file @
b2f34ad9
...
@@ -21,7 +21,7 @@ instance based on an argument list.
...
@@ -21,7 +21,7 @@ instance based on an argument list.
import
sys
import
sys
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
,
ConfigError
_SUBCOMMAND_MAP
=
{
_SUBCOMMAND_MAP
=
{
'add'
:
'AddCommand'
,
'add'
:
'AddCommand'
,
...
@@ -90,7 +90,11 @@ def get_subcommand(p_args):
...
@@ -90,7 +90,11 @@ def get_subcommand(p_args):
If alias resolves to non-existent command, main help message is
If alias resolves to non-existent command, main help message is
returned.
returned.
"""
"""
real_subcommand
,
alias_args
=
alias_map
[
p_alias
]
try
:
real_subcommand
,
alias_args
=
alias_map
[
p_alias
]
except
ValueError
as
ve
:
raise
ConfigError
(
alias_map
[
p_alias
])
from
ve
try
:
try
:
result
=
import_subcommand
(
real_subcommand
)
result
=
import_subcommand
(
real_subcommand
)
args
=
join_args
(
p_args
,
alias_args
)
args
=
join_args
(
p_args
,
alias_args
)
...
...
topydo/cli/CLI.py
View file @
b2f34ad9
...
@@ -50,7 +50,11 @@ class CLIApplication(CLIApplicationBase):
...
@@ -50,7 +50,11 @@ class CLIApplication(CLIApplicationBase):
self
.
todofile
=
TodoFile
.
TodoFile
(
config
().
todotxt
())
self
.
todofile
=
TodoFile
.
TodoFile
(
config
().
todotxt
())
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
(
subcommand
,
args
)
=
get_subcommand
(
args
)
try
:
(
subcommand
,
args
)
=
get_subcommand
(
args
)
except
ConfigError
as
ce
:
error
(
'Error: '
+
str
(
ce
)
+
'. Check your aliases configuration'
)
sys
.
exit
(
1
)
if
subcommand
is
None
:
if
subcommand
is
None
:
self
.
_usage
()
self
.
_usage
()
...
...
topydo/cli/Prompt.py
View file @
b2f34ad9
...
@@ -99,9 +99,16 @@ class PromptApplication(CLIApplicationBase):
...
@@ -99,9 +99,16 @@ class PromptApplication(CLIApplicationBase):
sys
.
exit
(
0
)
sys
.
exit
(
0
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
continue
continue
except
ValueError
as
verr
:
error
(
'Error: '
+
str
(
verr
))
mtime_after
=
_todotxt_mtime
()
mtime_after
=
_todotxt_mtime
()
(
subcommand
,
args
)
=
get_subcommand
(
user_input
)
try
:
(
subcommand
,
args
)
=
get_subcommand
(
user_input
)
except
ConfigError
as
ce
:
error
(
'Error: '
+
str
(
ce
)
+
'. Check your aliases configuration'
)
continue
# refuse to perform operations such as 'del' and 'do' if the
# refuse to perform operations such as 'del' and 'do' if the
# todo.txt file has been changed in the background.
# todo.txt file has been changed in the background.
...
...
topydo/lib/Config.py
View file @
b2f34ad9
...
@@ -18,6 +18,7 @@ import configparser
...
@@ -18,6 +18,7 @@ import configparser
import
os
import
os
import
shlex
import
shlex
class
ConfigError
(
Exception
):
class
ConfigError
(
Exception
):
def
__init__
(
self
,
p_text
):
def
__init__
(
self
,
p_text
):
self
.
text
=
p_text
self
.
text
=
p_text
...
@@ -299,10 +300,13 @@ class _Config:
...
@@ -299,10 +300,13 @@ class _Config:
alias_dict
=
dict
()
alias_dict
=
dict
()
for
alias
,
meaning
in
aliases
:
for
alias
,
meaning
in
aliases
:
meaning
=
shlex
.
split
(
meaning
)
try
:
real_subcommand
=
meaning
[
0
]
meaning
=
shlex
.
split
(
meaning
)
alias_args
=
meaning
[
1
:]
real_subcommand
=
meaning
[
0
]
alias_dict
[
alias
]
=
(
real_subcommand
,
alias_args
)
alias_args
=
meaning
[
1
:]
alias_dict
[
alias
]
=
(
real_subcommand
,
alias_args
)
except
ValueError
as
verr
:
alias_dict
[
alias
]
=
str
(
verr
)
return
alias_dict
return
alias_dict
...
...
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