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
791fbe2a
Commit
791fbe2a
authored
May 04, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare for other CLI interfaces.
Split the CLI class into a CLI base class.
parent
817a7585
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
33 deletions
+92
-33
setup.py
setup.py
+1
-1
topydo/cli/CLI.py
topydo/cli/CLI.py
+66
-0
topydo/cli/CLIApplicationBase.py
topydo/cli/CLIApplicationBase.py
+25
-32
No files found.
setup.py
View file @
791fbe2a
...
@@ -13,7 +13,7 @@ setup(
...
@@ -13,7 +13,7 @@ setup(
'prompt-toolkit'
:
[
'prompt-toolkit'
],
'prompt-toolkit'
:
[
'prompt-toolkit'
],
},
},
entry_points
=
{
entry_points
=
{
'console_scripts'
:
[
'topydo = topydo.cli.
Main
:main'
],
'console_scripts'
:
[
'topydo = topydo.cli.
CLI
:main'
],
},
},
classifiers
=
[
classifiers
=
[
"Development Status :: 4 - Beta"
,
"Development Status :: 4 - Beta"
,
...
...
topydo/cli/CLI.py
0 → 100755
View file @
791fbe2a
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 - 2015 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
""" Entry file for the Python todo.txt CLI. """
import
sys
from
topydo.cli.CLIApplicationBase
import
CLIApplicationBase
,
write
,
error
from
topydo.lib
import
TodoFile
from
topydo.lib.Config
import
config
,
ConfigError
# First thing is to poke the configuration and check whether it's sane
# The modules below may already read in configuration upon import, so
# make sure to bail out if the configuration is invalid.
try
:
config
()
except
ConfigError
as
config_error
:
error
(
str
(
config_error
))
sys
.
exit
(
1
)
from
topydo.lib.Commands
import
get_subcommand
from
topydo.lib
import
TodoList
class
CLIApplication
(
CLIApplicationBase
):
"""
Class that represents the Command Line Interface of Topydo.
Handles input/output of the various subcommand.
"""
def
__init__
(
self
):
super
(
CLIApplication
,
self
).
__init__
()
def
run
(
self
):
""" Main entry function. """
args
=
self
.
_process_flags
()
self
.
todofile
=
TodoFile
.
TodoFile
(
self
.
path
)
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
(
subcommand
,
args
)
=
get_subcommand
(
args
)
if
subcommand
==
None
:
self
.
_usage
()
if
self
.
_execute
(
subcommand
,
args
)
==
False
:
sys
.
exit
(
1
)
def
main
():
""" Main entry point of the CLI. """
CLIApplication
().
run
()
if
__name__
==
'__main__'
:
main
()
topydo/cli/
Main
.py
→
topydo/cli/
CLIApplicationBase
.py
View file @
791fbe2a
# Topydo - A todo.txt client written in Python.
# Topydo - A todo.txt client written in Python.
# Copyright (C) 201
4 - 201
5 Bram Schoenmakers <me@bramschoenmakers.nl>
# Copyright (C) 2015 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# it under the terms of the GNU General Public License as published by
...
@@ -19,10 +19,7 @@
...
@@ -19,10 +19,7 @@
import
getopt
import
getopt
import
sys
import
sys
def
usage
():
USAGE
=
"""
\
""" Prints the command-line usage of topydo. """
print
"""
\
Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
topydo -h
topydo -h
topydo -v
topydo -v
...
@@ -53,8 +50,6 @@ Available commands:
...
@@ -53,8 +50,6 @@ Available commands:
Run `topydo help <subcommand>` for command-specific help.
Run `topydo help <subcommand>` for command-specific help.
"""
"""
sys
.
exit
(
0
)
def
write
(
p_file
,
p_string
):
def
write
(
p_file
,
p_string
):
"""
"""
Write p_string to file p_file, trailed by a newline character.
Write p_string to file p_file, trailed by a newline character.
...
@@ -90,7 +85,6 @@ except ConfigError as config_error:
...
@@ -90,7 +85,6 @@ except ConfigError as config_error:
error
(
str
(
config_error
))
error
(
str
(
config_error
))
sys
.
exit
(
1
)
sys
.
exit
(
1
)
from
topydo.lib.Commands
import
get_subcommand
from
topydo.lib.ArchiveCommand
import
ArchiveCommand
from
topydo.lib.ArchiveCommand
import
ArchiveCommand
from
topydo.lib.SortCommand
import
SortCommand
from
topydo.lib.SortCommand
import
SortCommand
from
topydo.lib
import
TodoFile
from
topydo.lib
import
TodoFile
...
@@ -98,7 +92,7 @@ from topydo.lib import TodoList
...
@@ -98,7 +92,7 @@ from topydo.lib import TodoList
from
topydo.lib
import
TodoListBase
from
topydo.lib
import
TodoListBase
from
topydo.lib.Utils
import
escape_ansi
from
topydo.lib.Utils
import
escape_ansi
class
CLIApplication
(
object
):
class
CLIApplication
Base
(
object
):
"""
"""
Class that represents the Command Line Interface of Topydo.
Class that represents the Command Line Interface of Topydo.
...
@@ -111,6 +105,12 @@ class CLIApplication(object):
...
@@ -111,6 +105,12 @@ class CLIApplication(object):
self
.
path
=
self
.
config
.
todotxt
()
self
.
path
=
self
.
config
.
todotxt
()
self
.
archive_path
=
self
.
config
.
archive
()
self
.
archive_path
=
self
.
config
.
archive
()
self
.
todofile
=
None
def
_usage
(
self
):
print
USAGE
sys
.
exit
(
0
)
def
_process_flags
(
self
):
def
_process_flags
(
self
):
try
:
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"c:d:ht:v"
)
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"c:d:ht:v"
)
...
@@ -131,7 +131,7 @@ class CLIApplication(object):
...
@@ -131,7 +131,7 @@ class CLIApplication(object):
elif
opt
==
"-v"
:
elif
opt
==
"-v"
:
version
()
version
()
else
:
else
:
usage
()
self
.
_
usage
()
self
.
path
=
alt_path
if
alt_path
else
self
.
config
.
todotxt
()
self
.
path
=
alt_path
if
alt_path
else
self
.
config
.
todotxt
()
self
.
archive_path
=
alt_archive
\
self
.
archive_path
=
alt_archive
\
...
@@ -162,6 +162,12 @@ class CLIApplication(object):
...
@@ -162,6 +162,12 @@ class CLIApplication(object):
else
:
else
:
pass
# TODO
pass
# TODO
def
_input
(
self
):
"""
Returns a function that retrieves user input.
"""
return
raw_input
def
_execute
(
self
,
p_command
,
p_args
):
def
_execute
(
self
,
p_command
,
p_args
):
"""
"""
Execute a subcommand with arguments. p_command is a class (not an
Execute a subcommand with arguments. p_command is a class (not an
...
@@ -172,36 +178,23 @@ class CLIApplication(object):
...
@@ -172,36 +178,23 @@ class CLIApplication(object):
self
.
todolist
,
self
.
todolist
,
lambda
o
:
write
(
sys
.
stdout
,
o
),
lambda
o
:
write
(
sys
.
stdout
,
o
),
error
,
error
,
raw_input
)
self
.
_input
()
)
return
False
if
command
.
execute
()
==
False
else
True
if
command
.
execute
()
!=
False
:
self
.
_post_execute
()
return
True
def
run
(
self
):
return
False
""" Main entry function. """
args
=
self
.
_process_flags
()
todofile
=
TodoFile
.
TodoFile
(
self
.
path
)
self
.
todolist
=
TodoList
.
TodoList
(
todofile
.
read
())
(
subcommand
,
args
)
=
get_subcommand
(
args
)
if
subcommand
==
None
:
usage
()
if
self
.
_execute
(
subcommand
,
args
)
==
False
:
sys
.
exit
(
1
)
def
_post_execute
(
self
):
if
self
.
todolist
.
is_dirty
():
if
self
.
todolist
.
is_dirty
():
self
.
_archive
()
self
.
_archive
()
if
config
().
keep_sorted
():
if
config
().
keep_sorted
():
self
.
_execute
(
SortCommand
,
[])
self
.
_execute
(
SortCommand
,
[])
todofile
.
write
(
str
(
self
.
todolist
))
self
.
todofile
.
write
(
str
(
self
.
todolist
))
def
main
():
def
run
(
self
):
""" Main entry point of the CLI. """
raise
NotImplementedError
CLIApplication
().
run
()
if
__name__
==
'__main__'
:
main
()
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