# HG changeset patch # User Björn Ricks # Date 1323678364 -3600 # Node ID 6df408534f3f6f6ccf43a218b61ea89134e8fd0c # Parent 9d6df74058d72a2ae6b35d1a4516c83cade3d172 Move getan.py to getan/main.py It should be possible to import the main function from a getan module to be able to reuse main in different scripts. Also this allows to create a general script via setup.py. diff -r 9d6df74058d7 -r 6df408534f3f getan.py --- a/getan.py Mon Dec 12 09:22:34 2011 +0100 +++ b/getan.py Mon Dec 12 09:26:04 2011 +0100 @@ -10,52 +10,6 @@ # For details see LICENSE coming with the source of 'getan'. # -import logging -import sys -from optparse import OptionParser - -import getan.config as config -from getan.backend import DEFAULT_DATABASE, Backend -from getan.view import ProjectList, EntryList -from getan.controller import GetanController - -logger = logging.getLogger() - -def main(): +from getan.main import 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() +main() diff -r 9d6df74058d7 -r 6df408534f3f getan/main.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getan/main.py Mon Dec 12 09:26:04 2011 +0100 @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# (c) 2010 by Ingo Weinzierl +# (c) 2011 by Björn Ricks +# +# 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 optparse import OptionParser + +import getan.config as config +from getan.backend import DEFAULT_DATABASE, Backend +from getan.view import ProjectList, EntryList +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()