changeset 67:34a0f5c533bd

Use an OptionParser in getan to add options for debug level and logfile
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 25 May 2011 13:23:04 +0200
parents 13e3ec26dc36
children a25dab413260
files getan.py
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/getan.py	Wed May 25 13:21:34 2011 +0200
+++ b/getan.py	Wed May 25 13:23:04 2011 +0200
@@ -12,6 +12,7 @@
 import logging
 import sys
 from   datetime import datetime
+from optparse import OptionParser
 
 import getan.config  as config
 from   getan.backend import *
@@ -156,12 +157,27 @@
 
 
 def main():
-    config.initialize()
+
+    usage = "usage: %prog [options] [databasefile (default: " + \
+             DEFAULT_DATABASE + ")]"
+    parser = OptionParser(usage=usage)
+    parser.add_option("-d", "--debug", action="store_true", dest="debug",
+                      help="Set verbosity to debug")
+    parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE",
+                      help="Write log information to FILE [default: %default]",
+                      default="getan.log")
+    (options, args) = parser.parse_args()
+    logargs = dict()
+    if options.debug:
+        logargs["level"] = logging.DEBUG
+    if options.logfile:
+        logargs["filename"] = options.logfile
+    config.initialize(**logargs)
     global logger
 
-    if len(sys.argv) > 1:
-        backend = Backend(sys.argv[1])
-        logging.info("Use database '%s'." % sys.argv[1])
+    if len(args) > 0:
+        backend = Backend(args[0])
+        logging.info("Use database '%s'." % args[0])
     else:
         backend = Backend()
         logging.info("Use database '%s'." % DEFAULT_DATABASE)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)