Fixed KeyboardInterrupt management
This commit is contained in:
parent
8980b5899d
commit
42efd0d775
55
gcp
55
gcp
|
@ -300,31 +300,38 @@ 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)"""
|
||||||
dest_fd,options = data
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
buff = source_fd.read(self.buffer_size)
|
dest_fd,options = data
|
||||||
except:
|
|
||||||
self.__copyFailed("can't read source", source_fd, dest_fd)
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dest_fd.write(buff)
|
buff = source_fd.read(self.buffer_size)
|
||||||
except:
|
except KeyboardInterrupt:
|
||||||
self.__copyFailed("can't write to dest", source_fd, dest_fd)
|
raise KeyboardInterrupt
|
||||||
return False
|
except:
|
||||||
|
self.__copyFailed("can't read source", source_fd, dest_fd)
|
||||||
|
return False
|
||||||
|
|
||||||
self.bytes_copied += len(buff)
|
try:
|
||||||
if self.progress:
|
dest_fd.write(buff)
|
||||||
self._pbar_update()
|
except KeyboardInterrupt:
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
except:
|
||||||
|
self.__copyFailed("can't write to dest", source_fd, dest_fd)
|
||||||
|
return False
|
||||||
|
|
||||||
if len(buff) != self.buffer_size:
|
self.bytes_copied += len(buff)
|
||||||
source_fd.close()
|
if self.progress:
|
||||||
dest_fd.close()
|
self._pbar_update()
|
||||||
self.__post_copy(source_fd.name, dest_fd.name, options)
|
|
||||||
self.journal.closeFile()
|
if len(buff) != self.buffer_size:
|
||||||
return False
|
source_fd.close()
|
||||||
return True
|
dest_fd.close()
|
||||||
|
self.__post_copy(source_fd.name, dest_fd.name, options)
|
||||||
|
self.journal.closeFile()
|
||||||
|
return False
|
||||||
|
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__":
|
||||||
|
|
Loading…
Reference in New Issue