Mercurial > getan
comparison getan.py @ 90:04dbf4c9f297
Handle KeyboardInterrupt and shutdown getan carefully afterwards
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 30 May 2011 18:13:34 +0200 |
parents | f0e4637ad4e4 |
children | 99639833968d |
comparison
equal
deleted
inserted
replaced
89:3bea335c0f30 | 90:04dbf4c9f297 |
---|---|
131 logger.info("Start project '%s' at %s." | 131 logger.info("Start project '%s' at %s." |
132 % (project.desc, format_time(datetime.now()))) | 132 % (project.desc, format_time(datetime.now()))) |
133 self.view.set_footer_text(" Running on '%s'" % project.desc, 'running') | 133 self.view.set_footer_text(" Running on '%s'" % project.desc, 'running') |
134 logger.debug('All running projects: %r' % self.running) | 134 logger.debug('All running projects: %r' % self.running) |
135 | 135 |
136 def stop_project(self, desc='-no description-'): | 136 def stop_project(self, desc='-no description-', display=True): |
137 if not self.running: return | 137 if not self.running: return |
138 project = self.running.pop() | 138 project = self.running.pop() |
139 if not project: return | 139 if not project: return |
140 logger.info("Stop project '%s' at %s." | 140 logger.info("Stop project '%s' at %s." |
141 % (project.desc, format_time(datetime.now()))) | 141 % (project.desc, format_time(datetime.now()))) |
142 project.stop = datetime.now() | 142 project.stop = datetime.now() |
143 self.backend.insert_project_entry(project, datetime.now(), desc) | 143 self.backend.insert_project_entry(project, datetime.now(), desc) |
144 self.update_entries(project) | 144 if display: |
145 self.update_project_list() | 145 self.update_entries(project) |
146 self.update_project_list() | |
146 logger.debug('Still running projects: %r' % self.running) | 147 logger.debug('Still running projects: %r' % self.running) |
147 | 148 |
148 def add_project(self, key, description): | 149 def add_project(self, key, description): |
149 if not key or not description: | 150 if not key or not description: |
150 return | 151 return |
154 def update_entry(self, entry): | 155 def update_entry(self, entry): |
155 self.backend.update_entry(entry) | 156 self.backend.update_entry(entry) |
156 | 157 |
157 def shutdown(self): | 158 def shutdown(self): |
158 for project in self.running: | 159 for project in self.running: |
159 self.stop_project() | 160 self.stop_project(display=False) |
160 | 161 |
161 | 162 |
162 def main(): | 163 def main(): |
163 | 164 |
164 usage = "usage: %prog [options] [databasefile (default: " + \ | 165 usage = "usage: %prog [options] [databasefile (default: " + \ |
187 | 188 |
188 controller = GetanController(backend, ProjectList, EntryList) | 189 controller = GetanController(backend, ProjectList, EntryList) |
189 | 190 |
190 try: | 191 try: |
191 controller.main() | 192 controller.main() |
193 except KeyboardInterrupt: | |
194 pass | |
192 finally: | 195 finally: |
193 controller.shutdown() | 196 controller.shutdown() |
194 | 197 |
195 | 198 |
196 if __name__ == '__main__': | 199 if __name__ == '__main__': |