comparison getan/main.py @ 457:7fedbb73022e

clean up source code * use defaults in argparse and adapt the source code to it. * update CHANGES
author Magnus Schieder <mschieder@intevation.de>
date Fri, 02 Feb 2018 12:37:11 +0100
parents 193a4a051660
children 2707676cfd03
comparison
equal deleted inserted replaced
456:193a4a051660 457:7fedbb73022e
31 version = "getan version %s" % getan.__version__ 31 version = "getan version %s" % getan.__version__
32 32
33 parser = argparse.ArgumentParser(prog='getan', usage=usage) 33 parser = argparse.ArgumentParser(prog='getan', usage=usage)
34 parser.add_argument('--version', action='version', version=version) 34 parser.add_argument('--version', action='version', version=version)
35 parser.add_argument(dest='filename', nargs='?', 35 parser.add_argument(dest='filename', nargs='?',
36 help='[databasefile (default: time.db)]') 36 help='[databasefile (default: %(default)s)]',
37 default=DEFAULT_DATABASE)
37 parser.add_argument('--init-only', action='store_true', dest='initonly', 38 parser.add_argument('--init-only', action='store_true', dest='initonly',
38 help='create databasefile if necessary and exit') 39 help='create databasefile if necessary and exit')
39 parser.add_argument('-d', '--debug', action='store_true', dest='debug', 40 parser.add_argument('-d', '--debug', action='store_const', dest='loglevel',
41 default=logging.INFO, const=logging.DEBUG,
40 help='set verbosity to debug') 42 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 parser.add_argument('-l', '--logfile', dest='logfile', metavar='FILE',
43 help='write log information to FILE [default: getan.log]', 44 help='write log information to FILE [default: %(default)s]',
44 nargs='?') 45 default='getan.log')
46
45 47
46 args = parser.parse_args() 48 args = parser.parse_args()
47 49
48 logargs = dict() 50 config.initialize(args.loglevel, args.logfile)
49
50 if args.debug:
51 logargs["level"] = logging.DEBUG
52 if args.logfile:
53 logargs["filename"] = args.logfile
54 config.initialize(**logargs)
55 global logger 51 global logger
56 52
57 if args.filename != None : 53 if args.filename != DEFAULT_DATABASE :
58 backend = Backend(args.filename) 54 database = args.filename
59 logging.info("Using database '%s'." % args.filename)
60 else: 55 else:
61 if os.path.isfile(DEFAULT_DATABASE): 56 if os.path.isfile(DEFAULT_DATABASE):
62 database = os.path.abspath(DEFAULT_DATABASE) 57 database = os.path.abspath(DEFAULT_DATABASE)
63 else: 58 else:
64 getan_dir = os.path.expanduser(os.path.join("~", ".getan")) 59 getan_dir = os.path.expanduser(os.path.join("~", ".getan"))
65 if not os.path.exists(getan_dir): 60 if not os.path.exists(getan_dir):
66 os.mkdir(getan_dir) 61 os.mkdir(getan_dir)
67 database = os.path.join(getan_dir, DEFAULT_DATABASE) 62 database = os.path.join(getan_dir, DEFAULT_DATABASE)
68 63
69 backend = Backend(database) 64 backend = Backend(database)
70 logging.info("Using database '%s'." % database) 65 logging.info("Using database '%s'." % database)
71 66
72 if args.initonly: 67 if args.initonly:
73 return 68 return
74 69
75 controller = GetanController(backend) 70 controller = GetanController(backend)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)