Mercurial > getan
changeset 30:fea63a224065
Stop still running projects before getan quits - even if getan crashes.
author | Ingo Weinzierl <ingo_weinzierl@web.de> |
---|---|
date | Mon, 30 Aug 2010 22:21:47 +0200 |
parents | f5426961a380 |
children | fa5b3b1db867 |
files | ChangeLog getan.py getan/states.py |
diffstat | 3 files changed, 24 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo.weinzierl@intevation.de> + + * 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 <ingo.weinzierl@intevation.de> * getan/view.py: Bugfix: Unified parameter names in ProjectList - some
--- 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__':
--- 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)