Mercurial > getan
annotate getan.py @ 41:f44f808e7d47
Make getan runnable if there is no project in database.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 15 Dec 2010 11:55:25 +0100 |
parents | f96a18c10836 |
children | a5439795ef09 |
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> |
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
|
5 # |
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 # 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
|
7 # |
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 # 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
|
9 # 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
|
10 # |
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 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
|
13 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
|
14 from datetime import datetime |
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 |
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 import getan.config as config |
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 from getan.backend import * |
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 from getan.view import * |
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
|
19 from getan.utils import format_time |
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
|
20 |
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 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
|
22 |
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 class GetanController: |
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 __init__(self, backend, pv_class, ev_class): |
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 self.ev_class = ev_class |
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 self.pv_class = pv_class |
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 |
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
|
28 self.projects = backend.load_projects() |
41
f44f808e7d47
Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
29 if self.projects: |
f44f808e7d47
Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
30 entries = backend.load_entries(self.projects[0].id) |
f44f808e7d47
Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
31 else: |
f44f808e7d47
Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
32 entries = [] |
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
|
33 self.running = [] |
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
|
34 |
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
|
35 self.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
|
36 self.project_view = pv_class(self, self.projects) |
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
|
37 self.entries_view = ev_class(entries) |
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
|
38 |
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
|
39 self.view = GetanView(self, self.project_view, self.entries_view) |
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
|
40 self.state = PausedProjectsState(self, self.project_view) |
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 |
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 def main(self): |
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
|
43 self.view.run() |
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 |
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 def unhandled_keypress(self, key): |
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 self.state = self.state.keypress(key) |
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 |
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 def input_filter(self, input, raw_input): |
26
5e4d2810a739
Added support for resizing the application window.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
25
diff
changeset
|
49 if 'window resize' in input: |
5e4d2810a739
Added support for resizing the application window.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
25
diff
changeset
|
50 self.view.loop.screen_size = None |
5e4d2810a739
Added support for resizing the application window.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
25
diff
changeset
|
51 self.view.loop.draw_screen() |
5e4d2810a739
Added support for resizing the application window.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
25
diff
changeset
|
52 else: |
5e4d2810a739
Added support for resizing the application window.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
25
diff
changeset
|
53 self.state = self.state.keypress(input) |
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
|
54 |
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
|
55 def update_entries(self, project): |
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
|
56 logger.debug("GetanController: update entries.") |
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
|
57 self.entries_view.set_rows(self.backend.load_entries(project.id)) |
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 self.view.update_view() |
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 def move_selected_entries(self, project): |
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 old_project = None |
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 entries = [] |
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 try: |
33
f96a18c10836
Made getan python-2.4 compatible.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
31
diff
changeset
|
64 while self.entries_view.selection: |
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
|
65 node = self.entries_view.selection.pop() |
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
|
66 if node.selected: node.select() |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
67 entries.append(node.item) |
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
|
68 logger.info("GetanController: move entry '%s' (id = %d, "\ |
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
|
69 "project id = %d) to project '%s'" |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
70 % (node.item.desc, node.item.id, |
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
71 node.item.project_id, project.desc)) |
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
|
72 |
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
|
73 if not old_project: |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
74 old_project = self.project_by_id(node.item.project_id) |
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
|
75 finally: |
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
|
76 self.backend.move_entries(entries, project.id) |
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
|
77 if not old_project: return |
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
|
78 project.entries = self.backend.load_entries(project.id) |
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
|
79 old_project.entries = self.backend.load_entries(old_project.id) |
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
|
80 self.update_entries(old_project) |
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
|
81 self.project_view.update_all() |
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
|
82 |
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
|
83 def delete_entries(self, entry_nodes): |
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
|
84 if not entry_nodes: return |
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
|
85 proj = None |
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
|
86 entries = [] |
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
|
87 try: |
33
f96a18c10836
Made getan python-2.4 compatible.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
31
diff
changeset
|
88 while self.entries_view.selection: |
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
|
89 node = self.entries_view.selection.pop() |
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
|
90 if node.selected: node.select() |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
91 entries.append(node.item) |
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
|
92 logger.info("GetanController: delete entry '%s' (id = %d, "\ |
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
|
93 "project id = %d)" |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
94 % (node.item.desc, node.item.id, |
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
95 node.item.project_id)) |
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
|
96 |
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
|
97 if proj is None: |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
98 proj = self.project_by_id(node.item.project_id) |
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
|
99 finally: |
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
|
100 self.backend.delete_entries(entries) |
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
|
101 proj.entries = self.backend.load_entries(proj.id) |
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
|
102 self.update_entries(proj) |
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
|
103 self.project_view.update() |
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
|
104 |
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
|
105 def update_project_list(self): |
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
|
106 self.project_view.update() |
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
|
107 self.view.update_view() |
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
|
108 |
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
|
109 def exit(self): |
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
|
110 self.view.exit() |
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
|
111 |
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
|
112 def project_by_key(self, key): |
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
|
113 for proj in self.projects: |
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
|
114 if proj.key == key: |
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
|
115 return proj |
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
|
116 return None |
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
|
117 |
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
|
118 def project_by_id(self, id): |
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
|
119 for proj in self.projects: |
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
|
120 if proj.id == id: |
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
|
121 return proj |
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
|
122 return None |
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
|
123 |
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
|
124 def start_project(self, project): |
41
f44f808e7d47
Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
125 if not project: return |
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
|
126 self.running.append(project) |
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
|
127 project.start = datetime.now() |
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
|
128 logger.info("Start project '%s' at %s." |
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
|
129 % (project.desc, format_time(datetime.now()))) |
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
|
130 self.view.set_footer_text(" Running on '%s'" % project.desc, 'running') |
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
|
131 logger.debug('All running projects: %r' % self.running) |
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
|
132 |
30
fea63a224065
Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
26
diff
changeset
|
133 def stop_project(self, desc='-no description-'): |
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
|
134 project = self.running.pop() |
41
f44f808e7d47
Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
33
diff
changeset
|
135 if not project: return |
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
|
136 logger.info("Stop project '%s' at %s." |
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
|
137 % (project.desc, format_time(datetime.now()))) |
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
|
138 project.stop = datetime.now() |
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
|
139 self.backend.insert_project_entry(project, datetime.now(), desc) |
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
|
140 self.update_entries(project) |
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
|
141 self.update_project_list() |
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
|
142 logger.debug('Still running projects: %r' % self.running) |
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
|
143 |
31
fa5b3b1db867
Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
30
diff
changeset
|
144 def shutdown(self): |
30
fea63a224065
Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
26
diff
changeset
|
145 for project in self.running: |
fea63a224065
Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
26
diff
changeset
|
146 self.stop_project() |
fea63a224065
Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
26
diff
changeset
|
147 |
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
|
148 |
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
|
149 def 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
|
150 config.initialize() |
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
|
151 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
|
152 |
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
|
153 if len(sys.argv) > 1: |
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
|
154 backend = Backend(sys.argv[1]) |
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
|
155 logging.info("Use database '%s'." % sys.argv[1]) |
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
|
156 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
|
157 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
|
158 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
|
159 |
31
fa5b3b1db867
Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
30
diff
changeset
|
160 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
|
161 |
fa5b3b1db867
Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
30
diff
changeset
|
162 try: |
30
fea63a224065
Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
26
diff
changeset
|
163 controller.main() |
31
fa5b3b1db867
Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
30
diff
changeset
|
164 finally: |
fa5b3b1db867
Bugfix: removed 'with' statement - replaced by try/finally (ISSUE1566).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
30
diff
changeset
|
165 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
|
166 |
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
|
167 |
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
|
168 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
|
169 main() |