comparison gcp @ 14:21b38ed339a4

Fixed KeyboardInterrupt management
author Goffi <goffi@goffi.org>
date Tue, 28 Sep 2010 14:54:13 +0800
parents 894530949e30
children 8253a5ccbe9a
comparison
equal deleted inserted replaced
13:894530949e30 14:21b38ed339a4
298 def _copyFile(self, source_fd, condition, data): 298 def _copyFile(self, source_fd, condition, data):
299 """Actually copy the file, callback used with io_add_watch 299 """Actually copy the file, callback used with io_add_watch
300 @param source_fd: file descriptor of the file to copy 300 @param source_fd: file descriptor of the file to copy
301 @param condition: condition which launched the callback (glib.IO_IN) 301 @param condition: condition which launched the callback (glib.IO_IN)
302 @param data: tuple with (destination file descriptor, copying options)""" 302 @param data: tuple with (destination file descriptor, copying options)"""
303 dest_fd,options = data 303 try:
304 304 dest_fd,options = data
305 try: 305
306 buff = source_fd.read(self.buffer_size) 306 try:
307 except: 307 buff = source_fd.read(self.buffer_size)
308 self.__copyFailed("can't read source", source_fd, dest_fd) 308 except KeyboardInterrupt:
309 return False 309 raise KeyboardInterrupt
310 310 except:
311 try: 311 self.__copyFailed("can't read source", source_fd, dest_fd)
312 dest_fd.write(buff) 312 return False
313 except: 313
314 self.__copyFailed("can't write to dest", source_fd, dest_fd) 314 try:
315 return False 315 dest_fd.write(buff)
316 316 except KeyboardInterrupt:
317 self.bytes_copied += len(buff) 317 raise KeyboardInterrupt
318 if self.progress: 318 except:
319 self._pbar_update() 319 self.__copyFailed("can't write to dest", source_fd, dest_fd)
320 320 return False
321 if len(buff) != self.buffer_size: 321
322 source_fd.close() 322 self.bytes_copied += len(buff)
323 dest_fd.close() 323 if self.progress:
324 self.__post_copy(source_fd.name, dest_fd.name, options) 324 self._pbar_update()
325 self.journal.closeFile() 325
326 return False 326 if len(buff) != self.buffer_size:
327 return True 327 source_fd.close()
328 dest_fd.close()
329 self.__post_copy(source_fd.name, dest_fd.name, options)
330 self.journal.closeFile()
331 return False
332 return True
333 except KeyboardInterrupt:
334 self._userInterruption()
328 335
329 def __filename_fix(self, filename, options, no_journal=False): 336 def __filename_fix(self, filename, options, no_journal=False):
330 """Fix filenames incompatibilities/mistake according to options 337 """Fix filenames incompatibilities/mistake according to options
331 @param filename: full path to the file 338 @param filename: full path to the file
332 @param options: options as parsed on command line 339 @param options: options as parsed on command line
479 self.journal = Journal() 486 self.journal = Journal()
480 gobject.idle_add(self.__copyNextFile) 487 gobject.idle_add(self.__copyNextFile)
481 self.__launched = True 488 self.__launched = True
482 return (True,'') 489 return (True,'')
483 490
491 def _userInterruption(self):
492 info(_("User interruption: good bye"))
493 exit(1)
494
484 def go(self): 495 def go(self):
485 """Launch main loop""" 496 """Launch main loop"""
486 self.loop = gobject.MainLoop() 497 self.loop = gobject.MainLoop()
487 try: 498 try:
488 self.loop.run() 499 self.loop.run()
489 except KeyboardInterrupt: 500 except KeyboardInterrupt:
490 info(_("User interruption: good bye")) 501 self._userInterruption()
491 502
492 503
493 if __name__ == "__main__": 504 if __name__ == "__main__":
494 gcp = GCP() 505 gcp = GCP()
495 success,message = gcp.parseArguments() 506 success,message = gcp.parseArguments()