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
fafe392d
Commit
fafe392d
authored
May 25, 2015
by
Jacek Sowiński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add todos from file with '-f' flag.
parent
61a35f8f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
9 deletions
+38
-9
topydo/commands/AddCommand.py
topydo/commands/AddCommand.py
+38
-9
No files found.
topydo/commands/AddCommand.py
View file @
fafe392d
...
@@ -34,14 +34,26 @@ class AddCommand(Command):
...
@@ -34,14 +34,26 @@ class AddCommand(Command):
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
text
=
' '
.
join
(
p_args
)
self
.
text
=
' '
.
join
(
p_args
)
self
.
todo
=
None
self
.
todo
=
None
self
.
from_file
=
False
def
_preprocess_input_todo
(
self
):
def
_process_flags
(
self
):
opts
,
args
=
self
.
getopt
(
'f'
)
for
opt
,
value
in
opts
:
if
opt
==
'-f'
:
self
.
from_file
=
True
self
.
args
=
args
def
_preprocess_input_todo
(
self
,
p_todo_text
):
"""
"""
Preprocesses user input when adding a task.
Preprocesses user input when adding a task.
It detects a priority mid-sentence and puts it at the start.
It detects a priority mid-sentence and puts it at the start.
"""
"""
self
.
text
=
re
.
sub
(
r'^(.+) (\
([A-Z]
\))(.*)$'
,
r'\2 \1\3'
,
self
.
text
)
todo_text
=
re
.
sub
(
r'^(.+) (\
([A-Z]
\))(.*)$'
,
r'\2 \1\3'
,
p_todo_text
)
return
todo_text
def
_postprocess_input_todo
(
self
):
def
_postprocess_input_todo
(
self
):
"""
"""
...
@@ -83,18 +95,35 @@ class AddCommand(Command):
...
@@ -83,18 +95,35 @@ class AddCommand(Command):
self
.
todo
.
set_creation_date
(
date
.
today
())
self
.
todo
.
set_creation_date
(
date
.
today
())
def
get_todos_from_file
(
self
,
p_filename
):
f
=
open
(
p_filename
,
'r'
)
todos
=
f
.
read
().
decode
(
'utf-8'
).
splitlines
()
return
todos
def
_add_todo
(
self
,
p_todo_text
):
todo_text
=
self
.
_preprocess_input_todo
(
p_todo_text
)
self
.
todo
=
self
.
todolist
.
add
(
todo_text
)
self
.
_postprocess_input_todo
()
self
.
out
(
self
.
printer
.
print_todo
(
self
.
todo
))
def
execute
(
self
):
def
execute
(
self
):
""" Adds a todo item to the list. """
""" Adds a todo item to the list. """
if
not
super
(
AddCommand
,
self
).
execute
():
if
not
super
(
AddCommand
,
self
).
execute
():
return
False
return
False
if
self
.
text
:
self
.
_preprocess_input_todo
()
self
.
todo
=
self
.
todolist
.
add
(
self
.
text
)
self
.
_postprocess_input_todo
()
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
self
.
printer
.
add_filter
(
PrettyPrinterNumbers
(
self
.
todolist
))
self
.
out
(
self
.
printer
.
print_todo
(
self
.
todo
))
self
.
_process_flags
()
if
self
.
from_file
:
new_todos
=
self
.
get_todos_from_file
(
self
.
args
[
0
])
for
todo
in
new_todos
:
self
.
_add_todo
(
todo
)
else
:
if
self
.
text
:
self
.
_add_todo
(
self
.
text
)
else
:
else
:
self
.
error
(
self
.
usage
())
self
.
error
(
self
.
usage
())
...
...
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