# HG changeset patch # User Magnus Schieder # Date 1517571431 -3600 # Node ID 7fedbb73022e555829b8887e36642815e8bfe1ce # Parent 193a4a0516600bcfe20c41c1ffe7271078daa434 clean up source code * use defaults in argparse and adapt the source code to it. * update CHANGES diff -r 193a4a051660 -r 7fedbb73022e CHANGES --- a/CHANGES Wed Jan 31 13:34:54 2018 +0100 +++ b/CHANGES Fri Feb 02 12:37:11 2018 +0100 @@ -1,6 +1,7 @@ 2.x 20xx-xx-xx UNRELEASED - * optparse to argparse Migration. + * Update and clean up the source code to better maintain it in the future. + optparse to argparse Migration. The optparse module is deprecated and will not be developed further.The development will continue with the argparse module. Patch by Magnus Schieder diff -r 193a4a051660 -r 7fedbb73022e getan/config.py --- a/getan/config.py Wed Jan 31 13:34:54 2018 +0100 +++ b/getan/config.py Fri Feb 02 12:37:11 2018 +0100 @@ -17,8 +17,7 @@ logger = None - -def initialize(level=logging.INFO, filename="getan.log"): +def initialize(level, filename): setup_logging(level, filename) setup_locale() diff -r 193a4a051660 -r 7fedbb73022e getan/main.py --- a/getan/main.py Wed Jan 31 13:34:54 2018 +0100 +++ b/getan/main.py Fri Feb 02 12:37:11 2018 +0100 @@ -33,30 +33,25 @@ parser = argparse.ArgumentParser(prog='getan', usage=usage) parser.add_argument('--version', action='version', version=version) parser.add_argument(dest='filename', nargs='?', - help='[databasefile (default: time.db)]') + 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_true', dest='debug', + parser.add_argument('-d', '--debug', action='store_const', dest='loglevel', + default=logging.INFO, const=logging.DEBUG, help='set verbosity to debug') - # Default value of the logfile name is defined in .getan/config.py. parser.add_argument('-l', '--logfile', dest='logfile', metavar='FILE', - help='write log information to FILE [default: getan.log]', - nargs='?') + help='write log information to FILE [default: %(default)s]', + default='getan.log') + args = parser.parse_args() - logargs = dict() - - if args.debug: - logargs["level"] = logging.DEBUG - if args.logfile: - logargs["filename"] = args.logfile - config.initialize(**logargs) + config.initialize(args.loglevel, args.logfile) global logger - if args.filename != None : - backend = Backend(args.filename) - logging.info("Using database '%s'." % args.filename) + if args.filename != DEFAULT_DATABASE : + database = args.filename else: if os.path.isfile(DEFAULT_DATABASE): database = os.path.abspath(DEFAULT_DATABASE) @@ -66,8 +61,8 @@ os.mkdir(getan_dir) database = os.path.join(getan_dir, DEFAULT_DATABASE) - backend = Backend(database) - logging.info("Using database '%s'." % database) + backend = Backend(database) + logging.info("Using database '%s'." % database) if args.initonly: return