Mercurial > getan
view getan.py @ 112:d85b2a25797c
Move GetanController to it's own module
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 12 Dec 2011 09:21:04 +0100 |
parents | 1165422b5db7 |
children | 9d6df74058d7 |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- # # (c) 2010 by Ingo Weinzierl <ingo.weinzierl@intevation.de> # (c) 2011 by Björn Ricks <bjoern.ricks@intevation.de> # # A python worklog-alike to log what you have 'getan' (done). # # This is Free Software licensed under the terms of GPLv3 or later. # For details see LICENSE coming with the source of 'getan'. # import logging import sys from datetime import datetime from optparse import OptionParser import getan.config as config from getan.backend import DEFAULT_DATABASE, Backend from getan.view import GetanView, ProjectList, EntryList from getan.utils import format_time from getan.states import PausedProjectsState from getan.controller import GetanController logger = logging.getLogger() def main(): 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(args) > 0: backend = Backend(args[0]) logging.info("Use database '%s'." % args[0]) else: backend = Backend() logging.info("Use database '%s'." % DEFAULT_DATABASE) controller = GetanController(backend, ProjectList, EntryList) try: controller.main() except KeyboardInterrupt: pass finally: controller.shutdown() if __name__ == '__main__': main()