annotate 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
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
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
15 from datetime import datetime
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
16 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
17
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
18 import getan.config as config
109
1165422b5db7 Only import necessary classes and functions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
19 from getan.backend import DEFAULT_DATABASE, Backend
1165422b5db7 Only import necessary classes and functions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
20 from getan.view import GetanView, ProjectList, EntryList
1165422b5db7 Only import necessary classes and functions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
21 from getan.utils import format_time
1165422b5db7 Only import necessary classes and functions
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
22 from getan.states import PausedProjectsState
112
d85b2a25797c Move GetanController to it's own module
Björn Ricks <bjoern.ricks@intevation.de>
parents: 109
diff changeset
23 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
24
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
25 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
26
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
27 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
28
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 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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37 (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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45
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
46 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
47 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
48 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
49 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
50 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
51 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
52
31
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
53 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
54
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
55 try:
30
fea63a224065 Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 26
diff changeset
56 controller.main()
90
04dbf4c9f297 Handle KeyboardInterrupt and shutdown getan carefully afterwards
Björn Ricks <bjoern.ricks@intevation.de>
parents: 69
diff changeset
57 except KeyboardInterrupt:
04dbf4c9f297 Handle KeyboardInterrupt and shutdown getan carefully afterwards
Björn Ricks <bjoern.ricks@intevation.de>
parents: 69
diff changeset
58 pass
31
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
59 finally:
fa5b3b1db867 Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 30
diff changeset
60 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
61
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
62
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
63 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
64 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)