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
e384a348
Commit
e384a348
authored
Jun 15, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make main script more robust against invalid parameters.
parent
3338fe76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
21 deletions
+33
-21
Main.py
Main.py
+33
-21
No files found.
Main.py
100644 → 100755
View file @
e384a348
...
@@ -17,12 +17,15 @@ def print_iterable(p_iter):
...
@@ -17,12 +17,15 @@ def print_iterable(p_iter):
def
usage
():
def
usage
():
""" Prints the usage of the todo.txt CLI """
""" Prints the usage of the todo.txt CLI """
pass
exit
(
1
)
def
error
(
p_message
):
def
error
(
p_message
,
p_exit
=
True
):
""" Prints a message on the standard error. """
""" Prints a message on the standard error. """
sys
.
stderr
.
write
(
p_message
+
'
\
n
'
)
sys
.
stderr
.
write
(
p_message
+
'
\
n
'
)
if
p_exit
:
exit
(
1
)
class
Application
(
object
):
class
Application
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
self
.
todolist
=
TodoList
.
TodoList
([])
...
@@ -30,9 +33,11 @@ class Application(object):
...
@@ -30,9 +33,11 @@ class Application(object):
def
add
(
self
):
def
add
(
self
):
""" Adds a todo item to the list. """
""" Adds a todo item to the list. """
if
sys
.
argv
[
2
]
:
try
:
self
.
todolist
.
add
(
sys
.
argv
[
2
])
self
.
todolist
.
add
(
sys
.
argv
[
2
])
self
.
dirty
=
True
self
.
dirty
=
True
except
IndexError
:
error
(
"No todo text was given."
)
def
append
(
self
):
def
append
(
self
):
""" Appends a text to a todo item. """
""" Appends a text to a todo item. """
...
@@ -49,37 +54,44 @@ class Application(object):
...
@@ -49,37 +54,44 @@ class Application(object):
error
(
"Invalid todo number given."
)
error
(
"Invalid todo number given."
)
def
do
(
self
):
def
do
(
self
):
number
=
sys
.
argv
[
2
]
try
:
number
=
sys
.
argv
[
2
]
except
IndexError
:
usage
()
try
:
try
:
number
=
int
(
number
)
number
=
int
(
number
)
self
.
todolist
.
set_completed
(
number
)
self
.
todolist
.
todo
(
number
).
set_completed
(
number
)
self
.
dirty
=
True
self
.
dirty
=
True
except
IndexError
:
usage
()
except
ValueError
:
except
ValueError
:
error
(
"Invalid todo number given."
)
error
(
"Invalid todo number given."
)
def
pri
(
self
):
def
pri
(
self
):
number
=
sys
.
argv
[
2
]
try
:
priority
=
sys
.
argv
[
3
]
number
=
sys
.
argv
[
2
]
priority
=
sys
.
argv
[
3
]
if
number
and
priority
:
except
IndexError
:
if
re
.
match
(
'^[A-Z]$'
,
priority
):
usage
()
try
:
number
=
int
(
number
)
if
re
.
match
(
'^[A-Z]$'
,
priority
):
self
.
todolist
.
todo
(
number
).
set_priority
(
priority
)
try
:
self
.
dirty
=
True
number
=
int
(
number
)
except
AttributeError
:
self
.
todolist
.
todo
(
number
).
set_priority
(
priority
)
error
(
"Invalid todo number given."
)
self
.
dirty
=
True
except
ValueError
:
except
AttributeError
:
error
(
"Invalid todo number given."
)
error
(
"Invalid todo number given."
)
else
:
except
ValueError
:
error
(
"Invalid priority given."
)
error
(
"Invalid todo number given."
)
else
:
error
(
"Invalid priority given."
)
def
list
(
self
):
def
list
(
self
):
sorter
=
Sorter
.
Sorter
(
Config
.
SORT_STRING
)
sorter
=
Sorter
.
Sorter
(
Config
.
SORT_STRING
)
filters
=
[
Filter
.
RelevanceFilter
()]
filters
=
[
Filter
.
RelevanceFilter
()]
if
len
(
sys
.
argv
)
>
1
:
if
len
(
sys
.
argv
)
>
2
:
filters
.
append
(
Filter
.
GrepFilter
(
sys
.
argv
[
2
]))
filters
.
append
(
Filter
.
GrepFilter
(
sys
.
argv
[
2
]))
print
self
.
todolist
.
view
(
sorter
,
filters
)
print
self
.
todolist
.
view
(
sorter
,
filters
)
...
...
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