Mercurial > getan
comparison getan.py @ 114:6df408534f3f
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.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 12 Dec 2011 09:26:04 +0100 |
parents | 9d6df74058d7 |
children | 999a438474f2 |
comparison
equal
deleted
inserted
replaced
113:9d6df74058d7 | 114:6df408534f3f |
---|---|
8 # | 8 # |
9 # This is Free Software licensed under the terms of GPLv3 or later. | 9 # This is Free Software licensed under the terms of GPLv3 or later. |
10 # For details see LICENSE coming with the source of 'getan'. | 10 # For details see LICENSE coming with the source of 'getan'. |
11 # | 11 # |
12 | 12 |
13 import logging | 13 from getan.main import main |
14 import sys | |
15 from optparse import OptionParser | |
16 | 14 |
17 import getan.config as config | 15 main() |
18 from getan.backend import DEFAULT_DATABASE, Backend | |
19 from getan.view import ProjectList, EntryList | |
20 from getan.controller import GetanController | |
21 | |
22 logger = logging.getLogger() | |
23 | |
24 def main(): | |
25 | |
26 usage = "usage: %prog [options] [databasefile (default: " + \ | |
27 DEFAULT_DATABASE + ")]" | |
28 parser = OptionParser(usage=usage) | |
29 parser.add_option("-d", "--debug", action="store_true", dest="debug", | |
30 help="Set verbosity to debug") | |
31 parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE", | |
32 help="Write log information to FILE [default: %default]", | |
33 default="getan.log") | |
34 (options, args) = parser.parse_args() | |
35 logargs = dict() | |
36 if options.debug: | |
37 logargs["level"] = logging.DEBUG | |
38 if options.logfile: | |
39 logargs["filename"] = options.logfile | |
40 config.initialize(**logargs) | |
41 global logger | |
42 | |
43 if len(args) > 0: | |
44 backend = Backend(args[0]) | |
45 logging.info("Use database '%s'." % args[0]) | |
46 else: | |
47 backend = Backend() | |
48 logging.info("Use database '%s'." % DEFAULT_DATABASE) | |
49 | |
50 controller = GetanController(backend, ProjectList, EntryList) | |
51 | |
52 try: | |
53 controller.main() | |
54 except KeyboardInterrupt: | |
55 pass | |
56 finally: | |
57 controller.shutdown() | |
58 | |
59 | |
60 if __name__ == '__main__': | |
61 main() |