changeset 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
files CHANGES getan/config.py getan/main.py
diffstat 3 files changed, 15 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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()
 
--- 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
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)