annotate getan.py @ 113:9d6df74058d7

Remove unnecessary imports
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 12 Dec 2011 09:22:34 +0100
parents d85b2a25797c
children 6df408534f3f
rev   line source
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
1 #!/usr/bin/env python
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
3 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
4 # (c) 2010 by Ingo Weinzierl <ingo.weinzierl@intevation.de>
97
99639833968d Add me as author in files that I did touch
Björn Ricks <bjoern.ricks@intevation.de>
parents: 90
diff changeset
5 # (c) 2011 by Björn Ricks <bjoern.ricks@intevation.de>
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
6 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
7 # A python worklog-alike to log what you have 'getan' (done).
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
8 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
9 # This is Free Software licensed under the terms of GPLv3 or later.
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
10 # For details see LICENSE coming with the source of 'getan'.
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
11 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
12
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
13 import logging
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
14 import sys
67
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
15 from optparse import OptionParser
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
16
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
17 import getan.config as config
109
1165422b5db7 Only import necessary classes and functions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
18 from getan.backend import DEFAULT_DATABASE, Backend
113
9d6df74058d7 Remove unnecessary imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 112
diff changeset
19 from getan.view import ProjectList, EntryList
112
d85b2a25797c Move GetanController to it's own module
Björn Ricks <bjoern.ricks@intevation.de>
parents: 109
diff changeset
20 from getan.controller import GetanController
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
21
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
22 logger = logging.getLogger()
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
24 def main():
67
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
25
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
26 usage = "usage: %prog [options] [databasefile (default: " + \
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
27 DEFAULT_DATABASE + ")]"
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
28 parser = OptionParser(usage=usage)
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
29 parser.add_option("-d", "--debug", action="store_true", dest="debug",
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
30 help="Set verbosity to debug")
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
31 parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE",
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
32 help="Write log information to FILE [default: %default]",
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
33 default="getan.log")
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
34 (options, args) = parser.parse_args()
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
35 logargs = dict()
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
36 if options.debug:
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
37 logargs["level"] = logging.DEBUG
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
38 if options.logfile:
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
39 logargs["filename"] = options.logfile
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
40 config.initialize(**logargs)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
41 global logger
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
42
67
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
43 if len(args) > 0:
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
44 backend = Backend(args[0])
34a0f5c533bd Use an OptionParser in getan to add options for debug level and logfile
Björn Ricks <bjoern.ricks@intevation.de>
parents: 53
diff changeset
45 logging.info("Use database '%s'." % args[0])
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
46 else:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
47 backend = Backend()
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
48 logging.info("Use database '%s'." % DEFAULT_DATABASE)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
49
31
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
50 controller = GetanController(backend, ProjectList, EntryList)
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
51
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
52 try:
30
fea63a224065 Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 26
diff changeset
53 controller.main()
90
04dbf4c9f297 Handle KeyboardInterrupt and shutdown getan carefully afterwards
Björn Ricks <bjoern.ricks@intevation.de>
parents: 69
diff changeset
54 except KeyboardInterrupt:
04dbf4c9f297 Handle KeyboardInterrupt and shutdown getan carefully afterwards
Björn Ricks <bjoern.ricks@intevation.de>
parents: 69
diff changeset
55 pass
31
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
56 finally:
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
57 controller.shutdown()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
58
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
59
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
60 if __name__ == '__main__':
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
61 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)