Mercurial > getan
annotate classic/getan @ 91:40f52b4b02a4
Add docu about creating new projects
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 16 Aug 2011 11:54:59 +0200 |
parents | 9c4e8ba3c4fa |
children |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 # | |
4 # getan | |
5 # ----- | |
6 # (c) 2008 by Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
7 # | |
8 # A python worklog-alike to log what you have 'getan' (done). | |
9 # | |
10 # This is Free Software licensed under the terms of GPLv3 or later. | |
11 # For details see LICENSE coming with the source of 'getan'. | |
12 # | |
13 import sys | |
14 import re | |
15 import curses | |
16 import curses.ascii | |
17 import traceback | |
18 import signal | |
19 | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
20 from datetime import datetime, timedelta, tzinfo |
0 | 21 |
22 from pysqlite2 import dbapi2 as db | |
23 | |
24 PAUSED = 0 | |
25 RUNNING = 1 | |
26 PRE_EXIT = 2 | |
27 PAUSED_ESC = 3 | |
28 RUNNING_ESC = 4 | |
29 | |
30 SPACE = re.compile("[\\t ]+") | |
31 | |
32 DEFAULT_DATABASE = "time.db" | |
33 | |
34 LOAD_ACTIVE_PROJECTS = ''' | |
35 SELECT id, key, description, total | |
36 FROM projects LEFT JOIN | |
37 (SELECT | |
38 project_id, | |
39 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total | |
40 FROM entries | |
41 GROUP BY project_id) ON project_id = id | |
42 WHERE active | |
43 ''' | |
44 | |
45 WRITE_LOG = ''' | |
46 INSERT INTO entries (project_id, start_time, stop_time, description) | |
47 VALUES(:project_id, :start_time, :stop_time, :description) | |
48 ''' | |
49 | |
50 CREATE_PROJECT = ''' | |
51 INSERT INTO projects (key, description) VALUES (:key, :description) | |
52 ''' | |
53 | |
54 LAST_PROJECT_ID = ''' | |
55 SELECT last_insert_rowid() | |
56 ''' | |
57 | |
58 RENAME_PROJECT = ''' | |
59 UPDATE projects set key = :key, description = :description WHERE id = :id | |
60 ''' | |
61 | |
62 ASSIGN_LOGS = ''' | |
63 UPDATE entries SET project_id = :new_id WHERE project_id = :old_id | |
64 ''' | |
65 | |
66 DELETE_PROJECT = ''' | |
67 DELETE FROM projects WHERE id = :id | |
68 ''' | |
69 | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
70 # XXX: This is not very efficent! |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
71 LAST_ENTRY = ''' |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
72 SELECT id, strftime('%s', start_time), strftime('%s', stop_time) FROM entries |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
73 WHERE project_id = :project_id |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
74 ORDER by strftime('%s', stop_time) DESC LIMIT 1 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
75 ''' |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
76 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
77 DELETE_ENTRY = ''' |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
78 DELETE FROM entries WHERE id = :id |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
79 ''' |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
80 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
81 UPDATE_STOP_TIME = ''' |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
82 UPDATE entries SET stop_time = :stop_time WHERE id = :id |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
83 ''' |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
84 |
0 | 85 worklog = None |
86 stdscr = None | |
87 | |
88 orig_vis = None | |
89 | |
90 def cursor_visible(flag): | |
91 global orig_vis | |
92 try: | |
93 old = curses.curs_set(flag) | |
94 if orig_vis is None: orig_vis = old | |
95 return old | |
96 except: | |
97 pass | |
98 return 1 | |
99 | |
100 def restore_cursor(): | |
101 global orig_vis | |
102 if not orig_vis is None: | |
103 curses.curs_set(orig_vis) | |
104 | |
105 def render_header(ofs=0): | |
106 global stdscr | |
107 stdscr.attron(curses.A_BOLD) | |
108 stdscr.addstr(ofs, 5, "getan v0.1") | |
109 stdscr.addstr(ofs+1, 3, "--------------") | |
110 stdscr.attroff(curses.A_BOLD) | |
111 return ofs + 2 | |
112 | |
113 def render_quit(ofs=0): | |
114 global stdscr | |
115 stdscr.addstr(ofs + 2, 3, "Press DEL once more to quit") | |
116 return ofs + 3 | |
117 | |
118 def tolerantClose(cur): | |
119 if cur: | |
120 try: cur.close() | |
121 except: pass | |
122 | |
123 def ifNull(v, d): | |
124 if v is None: return d | |
125 return v | |
126 | |
127 def human_time(delta): | |
128 seconds = delta.seconds | |
129 s = seconds % 60 | |
130 if delta.microseconds >= 500000: s += 1 | |
131 seconds /= 60 | |
132 m = seconds % 60 | |
133 seconds /= 60 | |
134 out = "%02d:%02d:%02d" % (seconds, m, s) | |
135 if delta.days: | |
136 out = "%dd %s" % (delta.days, out) | |
137 return out | |
138 | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
139 FACTORS = { |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
140 's': 1, |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
141 'm': 60, |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
142 'h' : 60*60, |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
143 'd': 24*60*60} |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
144 |
17
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
145 def human_seconds(timespec): |
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
146 """Translate human input to seconds, default factor is minutes""" |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
147 total = 0 |
17
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
148 for v in timespec.split(':'): |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
149 factor = FACTORS.get(v[-1]) |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
150 if factor: v = v[:-1] |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
151 else: factor = 60 |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
152 total += int(v) * factor |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
153 return total |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
154 |
7
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
155 ESC_MAP = { |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
156 curses.KEY_F1 : ord('1'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
157 curses.KEY_F2 : ord('2'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
158 curses.KEY_F3 : ord('3'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
159 curses.KEY_F4 : ord('4'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
160 curses.KEY_F5 : ord('5'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
161 curses.KEY_F6 : ord('6'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
162 curses.KEY_F7 : ord('7'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
163 curses.KEY_F8 : ord('8'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
164 curses.KEY_F9 : ord('9'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
165 curses.KEY_F10: ord('0'), |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
166 } |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
167 |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
168 ZERO = timedelta(0) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
169 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
170 class UTC(tzinfo): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
171 """UTC""" |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
172 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
173 def utcoffset(self, dt): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
174 return ZERO |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
175 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
176 def tzname(self, dt): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
177 return "UTC" |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
178 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
179 def dst(self, dt): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
180 return ZERO |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
181 |
0 | 182 class Project: |
183 | |
184 def __init__(self, id = None, key = None, desc = None, total = 0): | |
185 self.id = id | |
186 self.key = key | |
187 self.desc = desc | |
188 self.total = timedelta(seconds = ifNull(total, 0)) | |
189 self.start_time = None | |
190 | |
191 def checkExistence(self, cur): | |
192 if self.id is None: | |
193 cur.execute(CREATE_PROJECT, { | |
194 'key' : self.key, | |
195 'description': self.desc}) | |
196 cur.execute(LAST_PROJECT_ID) | |
197 row = cur.fetchone() | |
198 cur.connection.commit() | |
199 self.id = row[0] | |
200 | |
201 def writeLog(self, cur, description = None): | |
202 if self.start_time is None: return | |
203 self.checkExistence(cur) | |
204 now = datetime.now() | |
205 cur.execute(WRITE_LOG, { | |
206 'project_id' : self.id, | |
207 'start_time' : self.start_time, | |
208 'stop_time' : now, | |
209 'description': description}) | |
210 self.total += now-self.start_time | |
211 return now | |
212 | |
213 def getId(self, cur): | |
214 self.checkExistence(cur) | |
215 return self.id | |
216 | |
217 def rename(self, cur, key, desc): | |
218 self.key = key | |
219 self.desc = desc | |
220 self.checkExistence(cur) | |
221 cur.execute(RENAME_PROJECT, { | |
222 'key' : key, | |
223 'description': desc, | |
224 'id' : self.id }) | |
225 cur.connection.commit() | |
226 | |
227 def assignLogs(self, cur, anon): | |
228 self.total += anon.total | |
229 anon.total = timedelta(seconds=0) | |
230 old_id = anon.getId(cur) | |
231 new_id = self.getId(cur) | |
232 cur.execute(ASSIGN_LOGS, { | |
233 'new_id': new_id, | |
234 'old_id': old_id}) | |
235 cur.connection.commit() | |
236 | |
237 def delete(self, cur): | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
238 pid = self.getId(cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
239 cur.execute(DELETE_PROJECT, { 'id': pid }) |
0 | 240 cur.connection.commit() |
241 | |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
242 def subtractTime(self, cur, seconds): |
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
243 subtractTimeed, zero = timedelta(), timedelta() |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
244 pid = {'project_id': self.getId(cur)} |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
245 utc = UTC() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
246 while seconds > zero: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
247 cur.execute(LAST_ENTRY, pid) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
248 row = cur.fetchone() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
249 if row is None: break |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
250 # TODO: evaluate egenix-mx |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
251 start_time = datetime.fromtimestamp(float(row[1]), utc) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
252 stop_time = datetime.fromtimestamp(float(row[2]), utc) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
253 runtime = stop_time - start_time |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
254 if runtime <= seconds: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
255 cur.execute(DELETE_ENTRY, { 'id': row[0] }) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
256 cur.connection.commit() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
257 seconds -= runtime |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
258 subtractTimeed += runtime |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
259 else: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
260 stop_time -= seconds |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
261 cur.execute(UPDATE_STOP_TIME, { |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
262 'id': row[0], |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
263 'stop_time': stop_time}) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
264 cur.connection.commit() |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
265 subtractTimeed += seconds |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
266 break |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
267 |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
268 self.total -= subtractTimeed |
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
269 return subtractTimeed |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
270 |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
271 def addTime(self, cur, seconds, description): |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
272 now = datetime.now() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
273 cur.execute(WRITE_LOG, { |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
274 'project_id' : self.getId(cur), |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
275 'start_time' : now - seconds, |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
276 'stop_time' : now, |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
277 'description': description |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
278 }) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
279 cur.connection.commit() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
280 self.total += seconds |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
281 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
282 def build_tree(project, depth): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
283 if len(project.key) == depth+1: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
284 return ProjectNode(project, project.key[depth]) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
285 node = ProjectNode(None, project.key[depth]) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
286 node.children.append(build_tree(project, depth+1)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
287 return node |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
288 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
289 class ProjectNode: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
290 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
291 def __init__(self, project = None, key = None): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
292 self.children = [] |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
293 self.project = project |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
294 self.key = key |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
295 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
296 def insertProject(self, project, depth = 0): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
297 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
298 if not project.key: # anonym -> end |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
299 node = ProjectNode(project) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
300 self.children.append(node) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
301 return |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
302 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
303 for i, child in enumerate(self.children): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
304 if not child.key: # before anonym projects |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
305 self.children.insert(i, build_tree(project, depth)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
306 return |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
307 if child.key == project.key[depth]: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
308 child.insertProject(project, depth+1) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
309 return |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
310 self.children.append(build_tree(project, depth)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
311 |
14
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
312 def removeProject(self, project): |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
313 |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
314 if self.isLeaf(): return |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
315 stack = [self] |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
316 while stack: |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
317 parent = stack.pop() |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
318 for child in parent.children: |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
319 if not child.isLeaf(): |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
320 stack.append(child) |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
321 continue |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
322 if child.project == project: |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
323 parent.children.remove(child) |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
324 return |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
325 |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
326 def isLeaf(self): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
327 return not self.project is None |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
328 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
329 def findProject(self, key): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
330 l, lower = key.lower(), None |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
331 for child in self.children: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
332 if child.key == key: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
333 return child |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
334 if child.key and child.key.lower() == l: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
335 lower = child |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
336 return lower |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
337 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
338 def dump(self, depth = 0): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
339 out = [] |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
340 indent = " " * depth |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
341 out.append("%skey: %s" % (indent, self.key)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
342 if self.project: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
343 out.append("%sdescription: %s" % (indent, self.project.desc)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
344 for child in self.children: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
345 out.append(child.dump(depth+1)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
346 return "\n".join(out) |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
347 |
0 | 348 class Worklog: |
349 | |
350 def __init__(self, database): | |
351 self.initDB(database) | |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
352 self.projects = [] |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
353 self.tree = ProjectNode() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
354 self.state = PAUSED |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
355 self.current_project = None |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
356 self.selection = self.tree |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
357 self.stack = [] |
0 | 358 self.loadProjects() |
359 | |
360 def initDB(self, database): | |
361 self.con = db.connect(database) | |
362 | |
363 def loadProjects(self): | |
364 cur = None | |
365 try: | |
366 cur = self.con.cursor() | |
367 cur.execute(LOAD_ACTIVE_PROJECTS) | |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
368 while True: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
369 row = cur.fetchone() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
370 if not row: break |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
371 project = Project(*row) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
372 self.projects.append(project) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
373 self.tree.insertProject(project) |
0 | 374 finally: |
375 tolerantClose(cur) | |
376 | |
377 def shutdown(self): | |
378 self.con.close() | |
379 | |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
380 def fetchStack(self): |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
381 cut = ''.join([chr(i) for i in self.stack]) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
382 self.stack = [] |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
383 return cut |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
384 |
0 | 385 def findProject(self, key): |
386 key_lower = key.lower() | |
387 lower = None | |
388 | |
389 for p in self.projects: | |
390 if p.key == key: | |
391 return p | |
392 if p.key and p.key.lower() == key_lower: | |
393 lower = p | |
394 | |
395 return lower | |
396 | |
397 def findAnonymProject(self, num): | |
398 count = 0 | |
399 for p in self.projects: | |
400 if p.key is None: | |
401 if count == num: | |
402 return p | |
403 count += 1 | |
404 return None | |
405 | |
406 def renameAnonymProject(self, num, key, description): | |
407 project = self.findAnonymProject(num) | |
408 if project: | |
409 cur = None | |
410 try: | |
411 cur = self.con.cursor() | |
412 project.rename(cur, key, description) | |
413 finally: | |
414 tolerantClose(cur) | |
14
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
415 self.tree.removeProject(project) |
83f99008a3f9
Insert anonym tasks into project tree when give them a name.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
12
diff
changeset
|
416 self.tree.insertProject(project) |
0 | 417 |
418 def assignLogs(self, num, key): | |
419 anon = self.findAnonymProject(num) | |
420 if anon is None: return | |
421 project = self.findProject(key) | |
422 if project is None: return | |
423 cur = None | |
424 try: | |
425 cur = self.con.cursor() | |
426 project.assignLogs(cur, anon) | |
427 self.projects.remove(anon) | |
428 anon.delete(cur) | |
429 finally: | |
430 tolerantClose(cur) | |
431 | |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
432 def addTime(self, key, seconds, description = None): |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
433 project = self.findProject(key) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
434 if project is None: return |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
435 cur = None |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
436 try: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
437 cur = self.con.cursor() |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
438 project.addTime(cur, seconds, description) |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
439 finally: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
440 tolerantClose(cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
441 |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
442 def subtractTime(self, key, seconds): |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
443 project = self.findProject(key) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
444 if project is None: return |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
445 cur = None |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
446 try: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
447 cur = self.con.cursor() |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
448 project.subtractTime(cur, seconds) |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
449 finally: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
450 tolerantClose(cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
451 |
0 | 452 def isRunning(self): |
453 return self.state in (RUNNING, RUNNING_ESC) | |
454 | |
3
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
455 def totalTime(self): |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
456 sum = timedelta() |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
457 for p in self.projects: |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
458 sum += p.total |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
459 return sum |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
460 |
0 | 461 def render(self, ofs=0): |
462 ofs = render_header(ofs) | |
463 ml = max([len(p.desc and p.desc or "unknown") for p in self.projects]) | |
464 unknown = 0 | |
465 | |
466 if self.current_project and self.current_project.start_time: | |
3
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
467 current_delta = datetime.now() - self.current_project.start_time |
0 | 468 current_time_str = "%s " % human_time(current_delta) |
469 current_time_space = " " * len(current_time_str) | |
470 else: | |
3
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
471 current_delta = timedelta() |
0 | 472 current_time_str = "" |
473 current_time_space = "" | |
474 | |
475 for project in self.projects: | |
476 is_current = project == self.current_project | |
477 pref = is_current and " -> " or " " | |
478 if project.key is None: | |
479 key = "^%d" % unknown | |
480 unknown += 1 | |
481 else: | |
482 key = " %s" % project.key | |
483 desc = project.desc is None and "unknown" or project.desc | |
484 stdscr.attron(curses.A_BOLD) | |
485 stdscr.addstr(ofs, 0, "%s%s" % (pref, key)) | |
486 stdscr.attroff(curses.A_BOLD) | |
487 stdscr.addstr(" %s" % desc) | |
488 | |
489 diff = ml - len(desc) + 1 | |
490 stdscr.addstr(" " * diff) | |
491 if is_current: stdscr.attron(curses.A_UNDERLINE) | |
492 | |
493 if is_current: | |
494 stdscr.addstr("%s(%s)" % ( | |
495 current_time_str, | |
496 human_time(project.total + current_delta))) | |
497 else: | |
498 stdscr.addstr("%s(%s)" % ( | |
499 current_time_space, | |
500 human_time(project.total))) | |
501 | |
502 if is_current: stdscr.attroff(curses.A_UNDERLINE) | |
503 ofs += 1 | |
504 | |
3
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
505 total_str = "(%s)" % human_time(self.totalTime() + current_delta) |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
506 total_x_pos = ml + 8 + len(current_time_space) |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
507 |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
508 stdscr.addstr(ofs, total_x_pos, "=" * len(total_str)) |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
509 ofs += 1 |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
510 stdscr.addstr(ofs, total_x_pos, total_str) |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
511 ofs += 1 |
1513c716eef0
- Added total sum of all projects.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2
diff
changeset
|
512 |
0 | 513 return ofs |
514 | |
515 def writeLog(self, description = None): | |
516 if self.current_project is None: | |
517 return datetime.now() | |
518 cur = None | |
519 try: | |
520 cur = self.con.cursor() | |
521 now = self.current_project.writeLog(cur, description) | |
522 self.con.commit() | |
523 return now | |
524 finally: | |
525 tolerantClose(cur) | |
526 | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
527 def pausedState(self, c): |
7
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
528 c2 = ESC_MAP.get(c) |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
529 if c2: |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
530 self.pausedEscapeState(c2) |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
531 return |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
532 |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
533 global stdscr |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
534 if c in (curses.KEY_DC, curses.KEY_BACKSPACE): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
535 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
536 ofs = render_quit(self.render()) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
537 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
538 self.state = PRE_EXIT |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
539 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
540 elif c == curses.ascii.ESC: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
541 self.state = PAUSED_ESC |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
542 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
543 elif curses.ascii.isascii(c): |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
544 if c == ord('-'): |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
545 self.selection = self.tree |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
546 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
547 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
548 old_cur = cursor_visible(1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
549 curses.echo() |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
550 stdscr.addstr(ofs + 1, 3, "<key> <minutes>: ") |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
551 key = stdscr.getstr() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
552 curses.noecho() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
553 cursor_visible(old_cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
554 key = key.strip() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
555 if key: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
556 parts = SPACE.split(key, 1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
557 if len(parts) > 1: |
17
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
558 key, timespec = parts[0], parts[1] |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
559 try: |
17
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
560 seconds = human_seconds(timespec) |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
561 if seconds > 0: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
562 seconds = timedelta(seconds=seconds) |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
563 self.subtractTime(key, seconds) |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
564 except ValueError: |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
565 pass |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
566 stdscr.erase() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
567 self.render() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
568 stdscr.refresh() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
569 |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
570 elif c == ord('+'): |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
571 self.selection = self.tree |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
572 stdscr.erase() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
573 ofs = self.render() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
574 old_cur = cursor_visible(1) |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
575 curses.echo() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
576 stdscr.addstr(ofs + 1, 3, "<key> <minutes> [<description>]: ") |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
577 key = stdscr.getstr() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
578 curses.noecho() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
579 cursor_visible(old_cur) |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
580 key = key.strip() |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
581 if key: |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
582 parts = SPACE.split(key, 2) |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
583 if len(parts) > 1: |
17
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
584 key, timespec = parts[0], parts[1] |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
585 if len(parts) > 2: desc = parts[2] |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
586 else: desc = None |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
587 try: |
17
2712fc2b8276
human_seconds: Use timespec instead of seconds and document it.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14
diff
changeset
|
588 seconds = human_seconds(timespec) |
6
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
589 if seconds > 0: |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
590 seconds = timedelta(seconds=seconds) |
58a887531e6e
* Feature wish 4 and 10
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3
diff
changeset
|
591 self.addTime(key, seconds, desc) |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
592 except ValueError: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
593 pass |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
594 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
595 self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
596 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
597 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
598 else: |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
599 node = self.selection.findProject(chr(c)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
600 if not node: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
601 self.selection = self.tree |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
602 return |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
603 if node.isLeaf(): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
604 self.selection = self.tree |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
605 nproject = node.project |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
606 self.current_project = nproject |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
607 nproject.start_time = datetime.now() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
608 stdscr.erase() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
609 ofs = self.render() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
610 stdscr.refresh() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
611 self.state = RUNNING |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
612 signal.signal(signal.SIGALRM, alarm_handler) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
613 signal.alarm(1) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
614 else: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
615 self.selection = node |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
616 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
617 def runningState(self, c): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
618 global stdscr |
7
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
619 c2 = ESC_MAP.get(c) |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
620 if c2: |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
621 self.runningEscapeState(c2) |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
622 return |
80f0e17208ba
Feature wish 8. Fn is like <ESC>-n
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6
diff
changeset
|
623 |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
624 if c == curses.ascii.ESC: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
625 self.state = RUNNING_ESC |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
626 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
627 elif c == curses.ascii.NL: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
628 signal.signal(signal.SIGALRM, signal.SIG_IGN) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
629 self.state = PAUSED |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
630 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
631 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
632 old_cur = cursor_visible(1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
633 curses.echo() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
634 stdscr.addstr(ofs + 1, 3, "Description: ") |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
635 description = stdscr.getstr() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
636 curses.noecho() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
637 cursor_visible(old_cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
638 self.writeLog(description) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
639 self.current_project = None |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
640 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
641 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
642 stdscr.refresh() |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
643 signal.signal(signal.SIGALRM, alarm_handler) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
644 signal.alarm(1) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
645 elif c == ord('+'): |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
646 signal.signal(signal.SIGALRM, signal.SIG_IGN) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
647 stdscr.erase() |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
648 ofs = self.render() |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
649 if self.stack: |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
650 timespec = self.fetchStack() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
651 else: |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
652 old_cur = cursor_visible(1) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
653 curses.echo() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
654 stdscr.addstr(ofs + 1, 3, "Enter time to add: ") |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
655 timespec = stdscr.getstr() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
656 curses.noecho() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
657 cursor_visible(old_cur) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
658 stdscr.erase() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
659 ofs = self.render() |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
660 try: |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
661 seconds = human_seconds(timespec) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
662 if seconds > 0: |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
663 seconds = timedelta(seconds=seconds) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
664 self.current_project.start_time -= seconds |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
665 stdscr.addstr(ofs + 1, 3, "added %s" % human_time(seconds)) |
21
a06e068e3de8
Handle empty input when adding/subtracting time of the running project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
20
diff
changeset
|
666 except (ValueError, IndexError): |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
667 pass |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
668 stdscr.refresh() |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
669 signal.signal(signal.SIGALRM, alarm_handler) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
670 signal.alarm(1) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
671 elif c == ord('-'): |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
672 signal.signal(signal.SIGALRM, signal.SIG_IGN) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
673 stdscr.erase() |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
674 ofs = self.render() |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
675 if self.stack: |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
676 timespec = self.fetchStack() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
677 else: |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
678 old_cur = cursor_visible(1) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
679 curses.echo() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
680 stdscr.addstr(ofs + 1, 3, "Enter time to subtract: ") |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
681 timespec = stdscr.getstr() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
682 curses.noecho() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
683 cursor_visible(old_cur) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
684 stdscr.erase() |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
685 ofs = self.render() |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
686 try: |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
687 seconds = human_seconds(timespec) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
688 if seconds > 0: |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
689 now = datetime.now() |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
690 seconds = timedelta(seconds=seconds) |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
691 self.current_project.start_time += seconds |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
692 stdscr.addstr(ofs + 1, 3, "subtracted %s" % human_time(seconds)) |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
693 if self.current_project.start_time > now: |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
694 seconds = self.current_project.start_time - now |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
695 self.current_project.start_time = now |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
696 cur = None |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
697 try: |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
698 cur = self.con.cursor() |
19
a9d58053bef7
rename substract to subtract
Thomas Arendsen Hein <thomas@intevation.de>
parents:
18
diff
changeset
|
699 self.current_project.subtractTime(cur, seconds) |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
700 finally: |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
701 tolerantClose(cur) |
21
a06e068e3de8
Handle empty input when adding/subtracting time of the running project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
20
diff
changeset
|
702 except (ValueError, IndexError): |
18
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
703 pass |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
704 stdscr.refresh() |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
705 signal.signal(signal.SIGALRM, alarm_handler) |
4242b263fad4
allow adding/subtracting times while a project is running
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17
diff
changeset
|
706 signal.alarm(1) |
20
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
707 elif self.stack or curses.ascii.isdigit(c): |
28489e672e61
Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
Thomas Arendsen Hein <thomas@intevation.de>
parents:
19
diff
changeset
|
708 self.stack.append(c) |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
709 elif curses.ascii.isascii(c): |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
710 project_node = self.selection.findProject(chr(c)) |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
711 if project_node is None: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
712 self.selection = self.tree |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
713 return |
12
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
714 |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
715 if project_node.isLeaf(): |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
716 self.selection = self.tree |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
717 nproject = project_node.project |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
718 if nproject == self.current_project: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
719 return |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
720 nproject.start_time = self.writeLog() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
721 self.current_project = nproject |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
722 stdscr.erase() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
723 ofs = self.render() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
724 stdscr.refresh() |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
725 else: |
2ccae1e872e9
Initial checkin for project trees. !!!Work in progress!!!
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7
diff
changeset
|
726 self.selection = project_node |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
727 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
728 def pausedEscapeState(self, c): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
729 global stdscr |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
730 if curses.ascii.isdigit(c): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
731 pnum = c - ord('0') |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
732 nproject = self.findAnonymProject(pnum) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
733 if nproject is None: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
734 nproject = Project() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
735 self.projects.append(nproject) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
736 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
737 nproject.start_time = self.writeLog() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
738 self.current_project = nproject |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
739 self.state = RUNNING |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
740 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
741 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
742 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
743 signal.signal(signal.SIGALRM, alarm_handler) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
744 signal.alarm(1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
745 elif curses.ascii.isalpha(c): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
746 if c == ord('n'): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
747 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
748 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
749 old_cur = cursor_visible(1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
750 curses.echo() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
751 stdscr.addstr(ofs + 1, 3, "<num> <key> <description>: ") |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
752 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
753 description = stdscr.getstr() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
754 curses.noecho() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
755 cursor_visible(old_cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
756 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
757 description = description.strip() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
758 if description: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
759 num, key, description = SPACE.split(description, 2) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
760 try: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
761 num = int(num) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
762 self.renameAnonymProject(num, key, description) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
763 except ValueError: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
764 pass |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
765 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
766 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
767 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
768 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
769 self.state = PAUSED |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
770 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
771 elif c == ord('a'): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
772 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
773 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
774 old_cur = cursor_visible(1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
775 curses.echo() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
776 stdscr.addstr(ofs + 1, 3, "<num> <key>: ") |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
777 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
778 key = stdscr.getstr() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
779 curses.noecho() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
780 cursor_visible(old_cur) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
781 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
782 key = key.strip() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
783 if key: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
784 num, key = SPACE.split(key, 1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
785 try: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
786 num = int(num) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
787 self.assignLogs(num, key) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
788 except ValueError: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
789 pass |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
790 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
791 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
792 ofs = self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
793 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
794 self.state = PAUSED |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
795 else: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
796 self.state = PAUSED |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
797 else: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
798 self.state = PAUSED |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
799 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
800 def runningEscapeState(self, c): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
801 global stdscr |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
802 if curses.ascii.isdigit(c): |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
803 signal.signal(signal.SIGALRM, signal.SIG_IGN) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
804 pnum = c - ord('0') |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
805 nproject = self.findAnonymProject(pnum) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
806 if nproject is None: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
807 nproject = Project() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
808 self.projects.append(nproject) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
809 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
810 nproject.start_time = self.writeLog() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
811 self.current_project = nproject |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
812 self.state = RUNNING |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
813 stdscr.erase() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
814 self.render() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
815 stdscr.refresh() |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
816 signal.signal(signal.SIGALRM, alarm_handler) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
817 signal.alarm(1) |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
818 else: |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
819 self.state = RUNNING |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
820 |
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
821 |
0 | 822 def run(self): |
823 global stdscr | |
824 | |
825 stdscr.erase() | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
826 self.render() |
0 | 827 stdscr.refresh() |
828 | |
829 while True: | |
830 c = stdscr.getch() | |
831 if c == -1: continue | |
832 | |
833 if self.state == PAUSED: | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
834 self.pausedState(c) |
0 | 835 |
836 elif self.state == RUNNING: | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
837 self.runningState(c) |
0 | 838 |
839 elif self.state == PAUSED_ESC: | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
840 self.pausedEscapeState(c) |
0 | 841 |
842 elif self.state == RUNNING_ESC: | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
843 self.runningEscapeState(c) |
0 | 844 |
845 elif self.state == PRE_EXIT: | |
1
a3fe8e4e9184
- To exit getan you now can use double BACKSPACE, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
0
diff
changeset
|
846 if c in (curses.KEY_DC, curses.KEY_BACKSPACE): |
0 | 847 break |
848 else: | |
849 stdscr.erase() | |
2
49aa271aa3d0
Added +/- time to tasks.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1
diff
changeset
|
850 self.render() |
0 | 851 stdscr.refresh() |
852 self.state = PAUSED | |
853 | |
854 def alarm_handler(flag, frame): | |
855 global worklog | |
856 global stdscr | |
857 | |
858 stdscr.erase() | |
859 worklog.render() | |
860 stdscr.refresh() | |
861 if worklog.isRunning(): | |
862 signal.alarm(1) | |
863 | |
864 def exit_handler(flag, frame): | |
865 exit_code = 0 | |
866 global worklog | |
867 try: | |
868 worklog.shutdown() | |
869 except: | |
870 traceback.print_exc(file=sys.stderr) | |
871 exit_code = 1 | |
872 | |
873 restore_cursor() | |
874 curses.nocbreak() | |
875 stdscr.keypad(0) | |
876 curses.echo() | |
877 curses.endwin() | |
878 sys.exit(exit_code) | |
879 | |
880 def main(): | |
881 | |
882 database = len(sys.argv) < 2 and DEFAULT_DATABASE or sys.argv[1] | |
883 # TODO: create database file if it does not exist. | |
884 | |
885 global worklog | |
886 try: | |
887 worklog = Worklog(database) | |
888 except: | |
889 traceback.print_exc(file=sys.stderr) | |
890 sys.exit(1) | |
891 | |
892 global stdscr | |
893 stdscr = curses.initscr() | |
894 curses.noecho() | |
895 curses.cbreak() | |
896 stdscr.keypad(1) | |
897 cursor_visible(0) | |
898 | |
899 signal.signal(signal.SIGHUP, exit_handler) | |
900 signal.signal(signal.SIGINT, exit_handler) | |
901 signal.signal(signal.SIGQUIT, exit_handler) | |
902 signal.signal(signal.SIGTERM, exit_handler) | |
903 | |
904 try: | |
905 try: | |
906 worklog.run() | |
907 except: | |
908 traceback.print_exc(file=sys.stderr) | |
909 finally: | |
910 exit_handler(0, None) | |
911 | |
912 if __name__ == '__main__': | |
913 main() | |
914 | |
915 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |