[Getan-commits] [PATCH] Improves command line options

Wald Commits scm-commit at wald.intevation.org
Thu Sep 7 17:11:00 CEST 2017


# HG changeset patch
# User Bernhard Reiter <bernhard at intevation.de>
# Date 1504796903 -7200
# Node ID 266634f3712a96747fc058d5ddf3afb1d1103af4
# Parent  8d03d7ada7e1ac9c307613964294eb12e0becd02
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`.

diff -r 8d03d7ada7e1 -r 266634f3712a CHANGES
--- 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)
diff -r 8d03d7ada7e1 -r 266634f3712a getan/main.py
--- 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)
 
diff -r 8d03d7ada7e1 -r 266634f3712a schema.sql
--- 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))
-);


More information about the Getan-commits mailing list