Mercurial > getan
changeset 6:58a887531e6e
* Feature wish 4 and 10
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 31 Jul 2008 23:05:39 +0200 |
parents | e7245c2127e5 |
children | 80f0e17208ba |
files | ChangeLog getan |
diffstat | 2 files changed, 48 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Jul 31 10:45:11 2008 +0200 +++ b/ChangeLog Thu Jul 31 23:05:39 2008 +0200 @@ -1,3 +1,10 @@ +2008-07-31 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * getan: Feature wish 4: in +/- time defaults to minutes. + Strings like '1d:4h:3m', or '2m:4s' and so on are valid + times now. Feature wish 10: When adding time to project + is now possible to enter an optional description. + 2008-07-31 Sascha L. Teichmann <sascha.teichmann@intevation.de> * contrib/wochenbericht: Applied patch from Stephan Holl to show
--- a/getan Thu Jul 31 10:45:11 2008 +0200 +++ b/getan Thu Jul 31 23:05:39 2008 +0200 @@ -143,11 +143,13 @@ 'd': 24*60*60} def human_seconds(seconds): - factor = FACTORS.get(seconds[-1]) - if factor: seconds = seconds[:-1] - else: factor = 1 - return int(seconds) * factor - + total = 0 + for v in seconds.split(':'): + factor = FACTORS.get(v[-1]) + if factor: v = v[:-1] + else: factor = 60 + total += int(v) * factor + return total ZERO = timedelta(0) @@ -252,13 +254,13 @@ self.total -= substractTimeed return substractTimeed - def addTime(self, cur, seconds): + def addTime(self, cur, seconds, description): now = datetime.now() cur.execute(WRITE_LOG, { 'project_id' : self.getId(cur), 'start_time' : now - seconds, 'stop_time' : now, - 'description': None + 'description': description }) cur.connection.commit() self.total += seconds @@ -332,13 +334,13 @@ finally: tolerantClose(cur) - def addTime(self, key, seconds): + def addTime(self, key, seconds, description = None): project = self.findProject(key) if project is None: return cur = None try: cur = self.con.cursor() - project.addTime(cur, seconds) + project.addTime(cur, seconds, description) finally: tolerantClose(cur) @@ -439,12 +441,12 @@ self.state = PAUSED_ESC elif curses.ascii.isascii(c): - if c in (ord('-'), ord('+')): + if c == ord('-'): stdscr.erase() ofs = self.render() old_cur = cursor_visible(1) curses.echo() - stdscr.addstr(ofs + 1, 3, "<key> <seconds>: ") + stdscr.addstr(ofs + 1, 3, "<key> <minutes>: ") key = stdscr.getstr() curses.noecho() cursor_visible(old_cur) @@ -457,10 +459,34 @@ seconds = human_seconds(seconds) if seconds > 0: seconds = timedelta(seconds=seconds) - if c == ord('-'): - self.substractTime(key, seconds) - else: - self.addTime(key, seconds) + self.substractTime(key, seconds) + except ValueError: + pass + stdscr.erase() + self.render() + stdscr.refresh() + + elif c == ord('+'): + stdscr.erase() + ofs = self.render() + old_cur = cursor_visible(1) + curses.echo() + stdscr.addstr(ofs + 1, 3, "<key> <minutes> [<description>]: ") + key = stdscr.getstr() + curses.noecho() + cursor_visible(old_cur) + key = key.strip() + if key: + parts = SPACE.split(key, 2) + if len(parts) > 1: + key, seconds = parts[0], parts[1] + if len(parts) > 2: desc = parts[2] + else: desc = None + try: + seconds = human_seconds(seconds) + if seconds > 0: + seconds = timedelta(seconds=seconds) + self.addTime(key, seconds, desc) except ValueError: pass stdscr.erase()