Mercurial > getan
changeset 41:f44f808e7d47
Make getan runnable if there is no project in database.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 15 Dec 2010 11:55:25 +0100 |
parents | e4759cc8f5e7 |
children | a5439795ef09 |
files | ChangeLog getan.py getan/states.py getan/view.py |
diffstat | 4 files changed, 25 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Dec 15 11:37:46 2010 +0100 +++ b/ChangeLog Wed Dec 15 11:55:25 2010 +0100 @@ -1,3 +1,10 @@ +2010-12-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + Make getan runnable if there is no project in database. + + * getan.py, getan/states.py, getan/view.py: Various checks + to ensure you really have a project. + 2010-12-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> * getan/backend.py: Create database file if it does
--- a/getan.py Wed Dec 15 11:37:46 2010 +0100 +++ b/getan.py Wed Dec 15 11:55:25 2010 +0100 @@ -26,7 +26,10 @@ self.pv_class = pv_class self.projects = backend.load_projects() - entries = backend.load_entries(self.projects[0].id) + if self.projects: + entries = backend.load_entries(self.projects[0].id) + else: + entries = [] self.running = [] self.backend = backend @@ -119,6 +122,7 @@ return None def start_project(self, project): + if not project: return self.running.append(project) project.start = datetime.now() logger.info("Start project '%s' at %s." @@ -128,6 +132,7 @@ def stop_project(self, desc='-no description-'): project = self.running.pop() + if not project: return logger.info("Stop project '%s' at %s." % (project.desc, format_time(datetime.now()))) project.stop = datetime.now()
--- a/getan/states.py Wed Dec 15 11:37:46 2010 +0100 +++ b/getan/states.py Wed Dec 15 11:55:25 2010 +0100 @@ -138,6 +138,7 @@ def handle_signal(self, signum, frame): proj = self.view.item_in_focus() + if not proj: return if not self.break_start: self.controller.view.set_footer_text(self.msg('running') % (human_time(self.sec), @@ -179,11 +180,12 @@ return self if ' ' in key and self.break_start: self.view._total_time() - proj = self.view.item_in_focus() - proj.start += datetime.now() - self.break_start - self.break_start = None - signal.signal(signal.SIGALRM, self.handle_signal) - signal.alarm(1) + proj = self.view.item_in_focus() + if proj: + proj.start += datetime.now() - self.break_start + self.break_start = None + signal.signal(signal.SIGALRM, self.handle_signal) + signal.alarm(1) return self def stop(self):
--- a/getan/view.py Wed Dec 15 11:37:46 2010 +0100 +++ b/getan/view.py Wed Dec 15 11:55:25 2010 +0100 @@ -54,7 +54,9 @@ return len(self.rows) def item_in_focus(self): - return self.rows[self.focused].get_item() + if self.rows: + return self.rows[self.focused].get_item() + return None def up(self): logger.debug("ListWidget: navigate to upper row.") @@ -69,6 +71,7 @@ self.update_focus(self.focused, self.focused-1) def select(self): + if not self.rows: return None node = self.rows[self.focused] logger.debug("ListWidget: select row '%s'" % self.focused) node.select() @@ -182,6 +185,7 @@ self._total_time() def _total_time(self): + if not self.rows: return logger.debug("ProjectList: update projects total time.") total = 0 for proj in self.rows: