Mercurial > getan > getan
view getan/main.py @ 458:2707676cfd03
check source code style.
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Fri, 02 Feb 2018 13:21:36 +0100 |
parents | 7fedbb73022e |
children | 2ab6fdde1010 |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- # # (c) 2010 by Ingo Weinzierl <ingo.weinzierl@intevation.de> # (c) 2011 by Björn Ricks <bjoern.ricks@intevation.de> # # A python worklog-alike to log what you have 'getan' (done). # # This is Free Software licensed under the terms of GPLv3 or later. # For details see LICENSE coming with the source of 'getan'. # import logging import os import os.path import argparse import getan import getan.config as config from getan.backend import DEFAULT_DATABASE, Backend from getan.controller import GetanController logger = logging.getLogger() def main(): usage = "%(prog)s [options] [databasefile (default: " + \ DEFAULT_DATABASE + ")]" version = "getan version %s" % getan.__version__ parser = argparse.ArgumentParser(prog='getan', usage=usage) parser.add_argument('--version', action='version', version=version) parser.add_argument(dest='filename', nargs='?', help='[databasefile (default: %(default)s)]', default=DEFAULT_DATABASE) parser.add_argument('--init-only', action='store_true', dest='initonly', help='create databasefile if necessary and exit') parser.add_argument('-d', '--debug', action='store_const', dest='loglevel', default=logging.INFO, const=logging.DEBUG, help='set verbosity to debug') parser.add_argument('-l', '--logfile', dest='logfile', metavar='FILE', help='''write log information to FILE [default: %(default)s]''', default='getan.log') args = parser.parse_args() config.initialize(args.loglevel, args.logfile) global logger if args.filename != DEFAULT_DATABASE: database = args.filename else: if os.path.isfile(DEFAULT_DATABASE): database = os.path.abspath(DEFAULT_DATABASE) else: getan_dir = os.path.expanduser(os.path.join("~", ".getan")) if not os.path.exists(getan_dir): os.mkdir(getan_dir) database = os.path.join(getan_dir, DEFAULT_DATABASE) backend = Backend(database) logging.info("Using database '%s'." % database) if args.initonly: return controller = GetanController(backend) try: controller.main() except KeyboardInterrupt: pass finally: controller.shutdown() if __name__ == '__main__': main()