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
e2bc4c26
Commit
e2bc4c26
authored
Nov 24, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'opts' into stable
Conflicts: topydo/cli/Main.py
parents
cba47430
f85dfe5a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
21 deletions
+63
-21
topydo/cli/Main.py
topydo/cli/Main.py
+55
-21
topydo/lib/Version.py
topydo/lib/Version.py
+8
-0
No files found.
topydo/cli/Main.py
View file @
e2bc4c26
...
...
@@ -16,26 +16,21 @@
""" Entry file for the Python todo.txt CLI. """
import
getopt
import
sys
def
usage
():
""" Prints the usage of the todo.txt CLI """
exit
(
1
)
def
arguments
(
p_start
=
2
):
"""
Retrieves all values from the argument list starting from the given
position.
print
"""
\
-c : Specify an alternative configuration file.
-d : Specify an alternative archive file (done.txt)
-h : This help text
-t : Specify an alternative todo file
-v : Print version and exit
"""
This is a parameter, because argv has a different structure when no
subcommand was given and it fallbacks to the default subcommand.
"""
try
:
values
=
sys
.
argv
[
p_start
:]
except
IndexError
:
usage
()
return
values
exit
(
0
)
def
write
(
p_file
,
p_string
):
"""
...
...
@@ -54,6 +49,13 @@ def error(p_string):
write
(
sys
.
stderr
,
p_string
)
def
version
():
""" Print the current version and exit. """
from
topydo.lib.Version
import
VERSION
,
LICENSE
print
"topydo %s
\
n
"
%
(
VERSION
)
print
LICENSE
exit
(
0
)
from
topydo.lib.Config
import
config
,
ConfigError
# First thing is to poke the configuration and check whether it's sane
...
...
@@ -93,6 +95,38 @@ class CLIApplication(object):
def
__init__
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
self
.
config
=
config
()
self
.
path
=
self
.
config
.
todotxt
()
self
.
archive_path
=
self
.
config
.
archive
()
def
_process_flags
(
self
):
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"c:d:ht:v"
)
except
getopt
.
GetoptError
as
e
:
error
(
str
(
e
))
exit
(
1
)
alt_path
=
None
alt_archive
=
None
for
opt
,
value
in
opts
:
if
opt
==
"-c"
:
self
.
config
=
config
(
value
)
elif
opt
==
"-t"
:
alt_path
=
value
elif
opt
==
"-d"
:
alt_archive
=
value
elif
opt
==
"-v"
:
version
()
else
:
usage
()
self
.
path
=
alt_path
if
alt_path
else
self
.
config
.
todotxt
()
self
.
archive_path
=
alt_archive
\
if
alt_archive
else
self
.
config
.
archive
()
return
args
def
archive
(
self
):
"""
Performs an archive action on the todolist.
...
...
@@ -100,7 +134,7 @@ class CLIApplication(object):
This means that all completed tasks are moved to the archive file
(defaults to done.txt).
"""
archive_file
=
TodoFile
.
TodoFile
(
config
().
archive
()
)
archive_file
=
TodoFile
.
TodoFile
(
self
.
archive_path
)
archive
=
TodoListBase
.
TodoListBase
(
archive_file
.
read
())
if
archive
:
...
...
@@ -126,13 +160,15 @@ class CLIApplication(object):
def
run
(
self
):
""" Main entry function. """
todofile
=
TodoFile
.
TodoFile
(
config
().
todotxt
())
args
=
self
.
_process_flags
()
todofile
=
TodoFile
.
TodoFile
(
self
.
path
)
self
.
todolist
=
TodoList
.
TodoList
(
todofile
.
read
())
try
:
subcommand
=
sys
.
argv
[
1
]
subcommand
=
args
.
pop
(
0
)
except
IndexError
:
subcommand
=
config
()
.
default_command
()
subcommand
=
self
.
config
.
default_command
()
subcommand_map
=
{
'add'
:
AddCommand
,
...
...
@@ -158,10 +194,8 @@ class CLIApplication(object):
'tag'
:
TagCommand
,
}
args
=
arguments
()
if
not
subcommand
in
subcommand_map
:
subcommand
=
config
().
default_command
()
args
=
arguments
(
1
)
subcommand
=
self
.
config
.
default_command
()
if
self
.
execute
(
subcommand_map
[
subcommand
],
args
)
==
False
:
exit
(
1
)
...
...
topydo/lib/Version.py
0 → 100644
View file @
e2bc4c26
""" Version of Topydo. """
VERSION
=
0.1
LICENSE
=
"""Copyright (C) 2014 Bram Schoenmakers
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law."""
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