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
ddf3eed0
Commit
ddf3eed0
authored
Jul 19, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convenience functions for handling user-supplied arguments.
parent
f4fadceb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
43 deletions
+35
-43
Main.py
Main.py
+35
-43
No files found.
Main.py
View file @
ddf3eed0
...
...
@@ -27,6 +27,24 @@ def error(p_message, p_exit=True):
if
p_exit
:
exit
(
1
)
def
argument
(
number
):
""" Retrieves a value from the argument list. """
try
:
value
=
sys
.
argv
[
number
]
except
IndexError
:
usage
()
return
value
def
convert_number
(
number
):
""" Converts a string number to an integer. """
try
:
number
=
int
(
number
)
except
ValueError
:
error
(
"Invalid todo number given."
)
return
number
class
Application
(
object
):
def
__init__
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
...
...
@@ -40,60 +58,38 @@ class Application(object):
def
add
(
self
):
""" Adds a todo item to the list. """
try
:
self
.
todolist
.
add
(
sys
.
argv
[
2
])
self
.
print_todo
(
self
.
todolist
.
count
())
self
.
dirty
=
True
except
IndexError
:
error
(
"No todo text was given."
)
self
.
todolist
.
add
(
argument
(
2
))
self
.
print_todo
(
self
.
todolist
.
count
())
self
.
dirty
=
True
def
append
(
self
):
""" Appends a text to a todo item. """
number
=
convert_number
(
argument
(
2
))
text
=
argument
(
3
)
try
:
number
=
sys
.
argv
[
2
]
text
=
sys
.
argv
[
3
]
except
IndexError
:
usage
()
self
.
todolist
.
append
(
number
,
text
)
try
:
number
=
int
(
number
)
self
.
todolist
.
append
(
number
,
text
)
self
.
print_todo
(
number
)
self
.
dirty
=
True
self
.
print_todo
(
number
)
self
.
dirty
=
True
except
ValueError
:
error
(
"Invalid todo number given."
)
self
.
dirty
=
True
def
do
(
self
):
try
:
number
=
sys
.
argv
[
2
]
except
IndexError
:
usage
()
try
:
number
=
int
(
number
)
self
.
todolist
.
todo
(
number
).
set_completed
()
number
=
convert_number
(
argument
(
2
))
todo
=
self
.
todolist
.
todo
(
number
)
if
todo
:
self
.
print_todo
(
number
)
self
.
dirty
=
True
except
IndexError
:
usage
()
except
ValueError
:
error
(
"Invalid todo number given."
)
def
pri
(
self
):
try
:
number
=
sys
.
argv
[
2
]
priority
=
sys
.
argv
[
3
]
except
IndexError
:
usage
()
number
=
convert_number
(
argument
(
2
))
priority
=
argument
(
3
)
if
re
.
match
(
'^[A-Z]$'
,
priority
):
t
ry
:
number
=
int
(
number
)
todo
=
self
.
todolist
.
todo
(
number
)
t
odo
=
self
.
todolist
.
todo
(
number
)
if
todo
:
old_priority
=
todo
.
priority
()
todo
.
set_priority
(
priority
)
...
...
@@ -101,10 +97,6 @@ class Application(object):
%
(
old_priority
,
priority
)
self
.
print_todo
(
number
)
self
.
dirty
=
True
except
AttributeError
:
error
(
"Invalid todo number given."
)
except
ValueError
:
error
(
"Invalid todo number given."
)
else
:
error
(
"Invalid priority given."
)
...
...
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