Mercurial > getan > getan
comparison getan/main.py @ 456:193a4a051660
Version: bumps to 2.3.dev1, ptparse to argparse Migration.
* Updates CHANGES
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Wed, 31 Jan 2018 13:34:54 +0100 |
parents | 266634f3712a |
children | 7fedbb73022e |
comparison
equal
deleted
inserted
replaced
455:669766ad5477 | 456:193a4a051660 |
---|---|
11 # | 11 # |
12 | 12 |
13 import logging | 13 import logging |
14 import os | 14 import os |
15 import os.path | 15 import os.path |
16 | 16 import argparse |
17 from optparse import OptionParser | |
18 | 17 |
19 import getan | 18 import getan |
20 import getan.config as config | 19 import getan.config as config |
21 | 20 |
22 from getan.backend import DEFAULT_DATABASE, Backend | 21 from getan.backend import DEFAULT_DATABASE, Backend |
25 logger = logging.getLogger() | 24 logger = logging.getLogger() |
26 | 25 |
27 | 26 |
28 def main(): | 27 def main(): |
29 | 28 |
30 usage = "usage: %prog [options] [databasefile (default: " + \ | 29 usage = "%(prog)s [options] [databasefile (default: " + \ |
31 DEFAULT_DATABASE + ")]" | 30 DEFAULT_DATABASE + ")]" |
32 version = "getan version %s" % getan.__version__ | 31 version = "getan version %s" % getan.__version__ |
33 parser = OptionParser(usage=usage, version=version) | 32 |
34 parser.add_option("--init-only", action="store_true", dest="initonly", | 33 parser = argparse.ArgumentParser(prog='getan', usage=usage) |
35 help="create databasefile if necessary and exit") | 34 parser.add_argument('--version', action='version', version=version) |
36 parser.add_option("-d", "--debug", action="store_true", dest="debug", | 35 parser.add_argument(dest='filename', nargs='?', |
37 help="set verbosity to debug") | 36 help='[databasefile (default: time.db)]') |
38 parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE", | 37 parser.add_argument('--init-only', action='store_true', dest='initonly', |
39 help="write log information to FILE [default: %default]", | 38 help='create databasefile if necessary and exit') |
40 default="getan.log") | 39 parser.add_argument('-d', '--debug', action='store_true', dest='debug', |
41 (options, args) = parser.parse_args() | 40 help='set verbosity to debug') |
41 # Default value of the logfile name is defined in .getan/config.py. | |
42 parser.add_argument('-l', '--logfile', dest='logfile', metavar='FILE', | |
43 help='write log information to FILE [default: getan.log]', | |
44 nargs='?') | |
45 | |
46 args = parser.parse_args() | |
47 | |
42 logargs = dict() | 48 logargs = dict() |
43 if options.debug: | 49 |
50 if args.debug: | |
44 logargs["level"] = logging.DEBUG | 51 logargs["level"] = logging.DEBUG |
45 if options.logfile: | 52 if args.logfile: |
46 logargs["filename"] = options.logfile | 53 logargs["filename"] = args.logfile |
47 config.initialize(**logargs) | 54 config.initialize(**logargs) |
48 global logger | 55 global logger |
49 | 56 |
50 if len(args) > 0: | 57 if args.filename != None : |
51 backend = Backend(args[0]) | 58 backend = Backend(args.filename) |
52 logging.info("Using database '%s'." % args[0]) | 59 logging.info("Using database '%s'." % args.filename) |
53 else: | 60 else: |
54 if os.path.isfile(DEFAULT_DATABASE): | 61 if os.path.isfile(DEFAULT_DATABASE): |
55 database = os.path.abspath(DEFAULT_DATABASE) | 62 database = os.path.abspath(DEFAULT_DATABASE) |
56 else: | 63 else: |
57 getan_dir = os.path.expanduser(os.path.join("~", ".getan")) | 64 getan_dir = os.path.expanduser(os.path.join("~", ".getan")) |
60 database = os.path.join(getan_dir, DEFAULT_DATABASE) | 67 database = os.path.join(getan_dir, DEFAULT_DATABASE) |
61 | 68 |
62 backend = Backend(database) | 69 backend = Backend(database) |
63 logging.info("Using database '%s'." % database) | 70 logging.info("Using database '%s'." % database) |
64 | 71 |
65 if options.initonly: | 72 if args.initonly: |
66 return | 73 return |
67 | 74 |
68 controller = GetanController(backend) | 75 controller = GetanController(backend) |
69 | 76 |
70 try: | 77 try: |