# HG changeset patch # User Sascha L. Teichmann # Date 1217538339 -7200 # Node ID 58a887531e6e95bb3a75fa84fbe7826d011b1f0e # Parent e7245c2127e5cb337b0e7a43873bd4c89aa34fb1 * Feature wish 4 and 10 diff -r e7245c2127e5 -r 58a887531e6e ChangeLog --- 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 + + * 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 * contrib/wochenbericht: Applied patch from Stephan Holl to show diff -r e7245c2127e5 -r 58a887531e6e getan --- 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, " : ") + stdscr.addstr(ofs + 1, 3, " : ") 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 = 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()