Fixed KeyboardInterrupt management

This commit is contained in:
Goffi 2010-09-28 14:54:13 +08:00
parent 8980b5899d
commit 42efd0d775
1 changed files with 33 additions and 22 deletions

13
gcp
View File

@ -300,16 +300,21 @@ class GCP():
@param source_fd: file descriptor of the file to copy @param source_fd: file descriptor of the file to copy
@param condition: condition which launched the callback (glib.IO_IN) @param condition: condition which launched the callback (glib.IO_IN)
@param data: tuple with (destination file descriptor, copying options)""" @param data: tuple with (destination file descriptor, copying options)"""
try:
dest_fd,options = data dest_fd,options = data
try: try:
buff = source_fd.read(self.buffer_size) buff = source_fd.read(self.buffer_size)
except KeyboardInterrupt:
raise KeyboardInterrupt
except: except:
self.__copyFailed("can't read source", source_fd, dest_fd) self.__copyFailed("can't read source", source_fd, dest_fd)
return False return False
try: try:
dest_fd.write(buff) dest_fd.write(buff)
except KeyboardInterrupt:
raise KeyboardInterrupt
except: except:
self.__copyFailed("can't write to dest", source_fd, dest_fd) self.__copyFailed("can't write to dest", source_fd, dest_fd)
return False return False
@ -325,6 +330,8 @@ class GCP():
self.journal.closeFile() self.journal.closeFile()
return False return False
return True return True
except KeyboardInterrupt:
self._userInterruption()
def __filename_fix(self, filename, options, no_journal=False): def __filename_fix(self, filename, options, no_journal=False):
"""Fix filenames incompatibilities/mistake according to options """Fix filenames incompatibilities/mistake according to options
@ -481,13 +488,17 @@ class GCP():
self.__launched = True self.__launched = True
return (True,'') return (True,'')
def _userInterruption(self):
info(_("User interruption: good bye"))
exit(1)
def go(self): def go(self):
"""Launch main loop""" """Launch main loop"""
self.loop = gobject.MainLoop() self.loop = gobject.MainLoop()
try: try:
self.loop.run() self.loop.run()
except KeyboardInterrupt: except KeyboardInterrupt:
info(_("User interruption: good bye")) self._userInterruption()
if __name__ == "__main__": if __name__ == "__main__":