Mercurial > getan > getan
comparison getan/main.py @ 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 | 27fc5f43a69b |
children | 193a4a051660 |
comparison
equal
deleted
inserted
replaced
432:8d03d7ada7e1 | 433:266634f3712a |
---|---|
29 | 29 |
30 usage = "usage: %prog [options] [databasefile (default: " + \ | 30 usage = "usage: %prog [options] [databasefile (default: " + \ |
31 DEFAULT_DATABASE + ")]" | 31 DEFAULT_DATABASE + ")]" |
32 version = "getan version %s" % getan.__version__ | 32 version = "getan version %s" % getan.__version__ |
33 parser = OptionParser(usage=usage, version=version) | 33 parser = OptionParser(usage=usage, version=version) |
34 parser.add_option("--init-only", action="store_true", dest="initonly", | |
35 help="create databasefile if necessary and exit") | |
34 parser.add_option("-d", "--debug", action="store_true", dest="debug", | 36 parser.add_option("-d", "--debug", action="store_true", dest="debug", |
35 help="Set verbosity to debug") | 37 help="set verbosity to debug") |
36 parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE", | 38 parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE", |
37 help="Write log information to FILE [default: %default]", | 39 help="write log information to FILE [default: %default]", |
38 default="getan.log") | 40 default="getan.log") |
39 (options, args) = parser.parse_args() | 41 (options, args) = parser.parse_args() |
40 logargs = dict() | 42 logargs = dict() |
41 if options.debug: | 43 if options.debug: |
42 logargs["level"] = logging.DEBUG | 44 logargs["level"] = logging.DEBUG |
45 config.initialize(**logargs) | 47 config.initialize(**logargs) |
46 global logger | 48 global logger |
47 | 49 |
48 if len(args) > 0: | 50 if len(args) > 0: |
49 backend = Backend(args[0]) | 51 backend = Backend(args[0]) |
50 logging.info("Use database '%s'." % args[0]) | 52 logging.info("Using database '%s'." % args[0]) |
51 else: | 53 else: |
52 if os.path.isfile(DEFAULT_DATABASE): | 54 if os.path.isfile(DEFAULT_DATABASE): |
53 database = os.path.abspath(DEFAULT_DATABASE) | 55 database = os.path.abspath(DEFAULT_DATABASE) |
54 else: | 56 else: |
55 getan_dir = os.path.expanduser(os.path.join("~", ".getan")) | 57 getan_dir = os.path.expanduser(os.path.join("~", ".getan")) |
56 if not os.path.exists(getan_dir): | 58 if not os.path.exists(getan_dir): |
57 os.mkdir(getan_dir) | 59 os.mkdir(getan_dir) |
58 database = os.path.join(getan_dir, DEFAULT_DATABASE) | 60 database = os.path.join(getan_dir, DEFAULT_DATABASE) |
59 | 61 |
60 backend = Backend(database) | 62 backend = Backend(database) |
61 logging.info("Use database '%s'." % database) | 63 logging.info("Using database '%s'." % database) |
64 | |
65 if options.initonly: | |
66 return | |
62 | 67 |
63 controller = GetanController(backend) | 68 controller = GetanController(backend) |
64 | 69 |
65 try: | 70 try: |
66 controller.main() | 71 controller.main() |