# HG changeset patch # User Björn Ricks # Date 1306322584 -7200 # Node ID 34a0f5c533bd9098be5d53e7a4dfb1fee6a834fe # Parent 13e3ec26dc36513d3a6e21a022a594b62376a9dc Use an OptionParser in getan to add options for debug level and logfile diff -r 13e3ec26dc36 -r 34a0f5c533bd getan.py --- 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)