# HG changeset patch # User Ingo Weinzierl # Date 1283199707 -7200 # Node ID fea63a2240655d20fa02dd7a56209c462ca7a568 # Parent f5426961a380b15edc091b18feed18ec8a2c6233 Stop still running projects before getan quits - even if getan crashes. diff -r f5426961a380 -r fea63a224065 ChangeLog --- a/ChangeLog Mon Aug 30 10:56:17 2010 +0200 +++ b/ChangeLog Mon Aug 30 22:21:47 2010 +0200 @@ -1,3 +1,16 @@ +2010-08-30 Ingo Weinzierl + + * getan.py: Added __enter__ and __exit__ methods. The exit method is used to + stop still running projects - even if getan crashes. Therefor it was + necessary to change the method signature of stop_project() in + GetanController. The description for the running project is given into the + method as parameter. If no desc parameter is specified, '-no description-' + is used as description. This is the case if there are still running + projects when we reach __exit__(). + + * getan/states.py: Added a description when calling stop_project() of + GetanController. + 2010-08-30 Ingo Weinzierl * getan/view.py: Bugfix: Unified parameter names in ProjectList - some diff -r f5426961a380 -r fea63a224065 getan.py --- a/getan.py Mon Aug 30 10:56:17 2010 +0200 +++ b/getan.py Mon Aug 30 22:21:47 2010 +0200 @@ -130,9 +130,8 @@ self.view.set_footer_text(" Running on '%s'" % project.desc, 'running') logger.debug('All running projects: %r' % self.running) - def stop_project(self): + def stop_project(self, desc='-no description-'): project = self.running.pop() - desc = self.view.get_frame().get_footer().get_edit_text() logger.info("Stop project '%s' at %s." % (project.desc, format_time(datetime.now()))) project.stop = datetime.now() @@ -141,6 +140,13 @@ self.update_project_list() logger.debug('Still running projects: %r' % self.running) + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + for project in self.running: + self.stop_project() + def main(): config.initialize() @@ -153,8 +159,8 @@ backend = Backend() logging.info("Use database '%s'." % DEFAULT_DATABASE) - controller = GetanController(backend, ProjectList, EntryList) - controller.main() + with GetanController(backend, ProjectList, EntryList) as controller: + controller.main() if __name__ == '__main__': diff -r f5426961a380 -r fea63a224065 getan/states.py --- a/getan/states.py Mon Aug 30 10:56:17 2010 +0200 +++ b/getan/states.py Mon Aug 30 22:21:47 2010 +0200 @@ -290,7 +290,7 @@ text = self.footer.get_edit_text() if text == '': return self - self.controller.stop_project() + self.controller.stop_project(text) self.controller.view.set_footer_text(self.msg('choose_proj'), 'question') return PausedProjectsState(self.controller, self.view)