comparison getan.py @ 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 1d63ab21b8af
children f0e4637ad4e4
comparison
equal deleted inserted replaced
66:13e3ec26dc36 67:34a0f5c533bd
10 # 10 #
11 11
12 import logging 12 import logging
13 import sys 13 import sys
14 from datetime import datetime 14 from datetime import datetime
15 from optparse import OptionParser
15 16
16 import getan.config as config 17 import getan.config as config
17 from getan.backend import * 18 from getan.backend import *
18 from getan.view import * 19 from getan.view import *
19 from getan.utils import format_time 20 from getan.utils import format_time
154 for project in self.running: 155 for project in self.running:
155 self.stop_project() 156 self.stop_project()
156 157
157 158
158 def main(): 159 def main():
159 config.initialize() 160
161 usage = "usage: %prog [options] [databasefile (default: " + \
162 DEFAULT_DATABASE + ")]"
163 parser = OptionParser(usage=usage)
164 parser.add_option("-d", "--debug", action="store_true", dest="debug",
165 help="Set verbosity to debug")
166 parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE",
167 help="Write log information to FILE [default: %default]",
168 default="getan.log")
169 (options, args) = parser.parse_args()
170 logargs = dict()
171 if options.debug:
172 logargs["level"] = logging.DEBUG
173 if options.logfile:
174 logargs["filename"] = options.logfile
175 config.initialize(**logargs)
160 global logger 176 global logger
161 177
162 if len(sys.argv) > 1: 178 if len(args) > 0:
163 backend = Backend(sys.argv[1]) 179 backend = Backend(args[0])
164 logging.info("Use database '%s'." % sys.argv[1]) 180 logging.info("Use database '%s'." % args[0])
165 else: 181 else:
166 backend = Backend() 182 backend = Backend()
167 logging.info("Use database '%s'." % DEFAULT_DATABASE) 183 logging.info("Use database '%s'." % DEFAULT_DATABASE)
168 184
169 controller = GetanController(backend, ProjectList, EntryList) 185 controller = GetanController(backend, ProjectList, EntryList)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)