diff getan.py @ 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 5e4d2810a739
children fa5b3b1db867
line wrap: on
line diff
--- 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__':
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)