Mercurial > getan
changeset 433:266634f3712a
Improves command line options.
* Adds option '--init-only' which will non-interactively just
create the databasefile if it does not exits. This is useful if you want
to add tasks non-interatively. It allows to remove the superfluous file
`schema.sql` which duplicates the build-in schema in `backend.py`.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Thu, 07 Sep 2017 17:08:23 +0200 |
parents | 8d03d7ada7e1 |
children | 11c2a3beee91 |
files | CHANGES getan/main.py schema.sql |
diffstat | 3 files changed, 11 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES Tue May 30 09:02:48 2017 +0200 +++ b/CHANGES Thu Sep 07 17:08:23 2017 +0200 @@ -1,4 +1,6 @@ 2.1 xx.xx.20xx UNRELEASED + * Adds option '--init-only' which will non-interactively just + create the databasefile if it does not exits. (Bernhard Reiter) * Fixes a possible encoding detection failure: uses 'utf-8' by default then. Patch by Tom Gottfried. (Bernhard Reiter)
--- a/getan/main.py Tue May 30 09:02:48 2017 +0200 +++ b/getan/main.py Thu Sep 07 17:08:23 2017 +0200 @@ -31,10 +31,12 @@ DEFAULT_DATABASE + ")]" version = "getan version %s" % getan.__version__ parser = OptionParser(usage=usage, version=version) + parser.add_option("--init-only", action="store_true", dest="initonly", + help="create databasefile if necessary and exit") parser.add_option("-d", "--debug", action="store_true", dest="debug", - help="Set verbosity to debug") + help="set verbosity to debug") parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE", - help="Write log information to FILE [default: %default]", + help="write log information to FILE [default: %default]", default="getan.log") (options, args) = parser.parse_args() logargs = dict() @@ -47,7 +49,7 @@ if len(args) > 0: backend = Backend(args[0]) - logging.info("Use database '%s'." % args[0]) + logging.info("Using database '%s'." % args[0]) else: if os.path.isfile(DEFAULT_DATABASE): database = os.path.abspath(DEFAULT_DATABASE) @@ -58,7 +60,10 @@ database = os.path.join(getan_dir, DEFAULT_DATABASE) backend = Backend(database) - logging.info("Use database '%s'." % database) + logging.info("Using database '%s'." % database) + + if options.initonly: + return controller = GetanController(backend)
--- a/schema.sql Tue May 30 09:02:48 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -CREATE TABLE projects ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - key VARCHAR(16), - description VARCHAR(256), - active BOOLEAN DEFAULT 1 -); - -CREATE TABLE entries ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - project_id INTEGER REFERENCES projects(id), - start_time TIMESTAMP NOT NULL, - stop_time TIMESTAMP NOT NULL, - description VARCHAR(256), - - CHECK (strftime('%s', start_time) <= strftime('%s', stop_time)) -);