Mercurial > gcp
changeset 14:21b38ed339a4
Fixed KeyboardInterrupt management
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Sep 2010 14:54:13 +0800 |
parents | 894530949e30 |
children | 8253a5ccbe9a |
files | gcp |
diffstat | 1 files changed, 33 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/gcp Tue Sep 28 14:40:27 2010 +0800 +++ b/gcp Tue Sep 28 14:54:13 2010 +0800 @@ -300,31 +300,38 @@ @param source_fd: file descriptor of the file to copy @param condition: condition which launched the callback (glib.IO_IN) @param data: tuple with (destination file descriptor, copying options)""" - dest_fd,options = data + try: + dest_fd,options = data - try: - buff = source_fd.read(self.buffer_size) - except: - self.__copyFailed("can't read source", source_fd, dest_fd) - return False + try: + buff = source_fd.read(self.buffer_size) + except KeyboardInterrupt: + raise KeyboardInterrupt + except: + self.__copyFailed("can't read source", source_fd, dest_fd) + return False - try: - dest_fd.write(buff) - except: - self.__copyFailed("can't write to dest", source_fd, dest_fd) - return False + try: + dest_fd.write(buff) + except KeyboardInterrupt: + raise KeyboardInterrupt + except: + self.__copyFailed("can't write to dest", source_fd, dest_fd) + return False - self.bytes_copied += len(buff) - if self.progress: - self._pbar_update() + self.bytes_copied += len(buff) + if self.progress: + self._pbar_update() - if len(buff) != self.buffer_size: - source_fd.close() - dest_fd.close() - self.__post_copy(source_fd.name, dest_fd.name, options) - self.journal.closeFile() - return False - return True + if len(buff) != self.buffer_size: + source_fd.close() + 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): """Fix filenames incompatibilities/mistake according to options @@ -481,13 +488,17 @@ self.__launched = True return (True,'') + def _userInterruption(self): + info(_("User interruption: good bye")) + exit(1) + def go(self): """Launch main loop""" self.loop = gobject.MainLoop() try: self.loop.run() except KeyboardInterrupt: - info(_("User interruption: good bye")) + self._userInterruption() if __name__ == "__main__":