diff options
Diffstat (limited to 'rapid/copyfiles.py')
-rw-r--r-- | rapid/copyfiles.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/rapid/copyfiles.py b/rapid/copyfiles.py index f9ebc60..78fe8a3 100644 --- a/rapid/copyfiles.py +++ b/rapid/copyfiles.py @@ -64,16 +64,21 @@ class CopyFiles(multiprocessing.Process): def update_progress(self, amount_downloaded, total): - if (amount_downloaded - self.bytes_downloaded > self.batch_size_bytes) or (amount_downloaded == total): - chunk_downloaded = amount_downloaded - self.bytes_downloaded - self.bytes_downloaded = amount_downloaded - self.results_pipe.send((rpdmp.CONN_PARTIAL, (rpdmp.MSG_BYTES, (self.scan_pid, self.total_downloaded + amount_downloaded)))) + # first check if process is being terminated + if not self.terminate_queue.empty(): + # it is - cancel the current copy + self.cancel_copy.cancel() + else: + if (amount_downloaded - self.bytes_downloaded > self.batch_size_bytes) or (amount_downloaded == total): + chunk_downloaded = amount_downloaded - self.bytes_downloaded + self.bytes_downloaded = amount_downloaded + self.results_pipe.send((rpdmp.CONN_PARTIAL, (rpdmp.MSG_BYTES, (self.scan_pid, self.total_downloaded + amount_downloaded)))) def progress_callback(self, amount_downloaded, total): - if self.check_termination_request(): - # FIXME: cancel copy - pass + #~ if self.check_termination_request(): + #~ # FIXME: cancel copy + #~ pass self.update_progress(amount_downloaded, total) @@ -84,6 +89,8 @@ class CopyFiles(multiprocessing.Process): self.bytes_downloaded = 0 self.total_downloaded = 0 + self.cancel_copy = gio.Cancellable() + self.create_temp_dirs() # Send the location of both temporary directories, so they can be @@ -113,7 +120,7 @@ class CopyFiles(multiprocessing.Process): copy_succeeded = False try: - source.copy(dest, self.progress_callback, cancellable=None) + source.copy(dest, self.progress_callback, cancellable=self.cancel_copy) copy_succeeded = True except gio.Error, inst: rpd_file.add_problem(None, @@ -124,6 +131,12 @@ class CopyFiles(multiprocessing.Process): {'errorno': inst.code, 'strerror': inst.message}) rpd_file.status = config.STATUS_DOWNLOAD_FAILED + + rpd_file.error_title = rpd_file.problem.get_title() + rpd_file.error_msg = _("%(problem)s\nFile: %(file)s") % \ + {'problem': rpd_file.problem.get_problems(), + 'file': rpd_file.full_file_name} + logger.error("Failed to download file: %s", rpd_file.full_file_name) logger.error(inst) self.update_progress(rpd_file.size, rpd_file.size) @@ -132,7 +145,9 @@ class CopyFiles(multiprocessing.Process): # succeeded or not. It's neccessary to keep the user informed. self.total_downloaded += rpd_file.size - + if rpd_file.metadata is not None: + rpd_file.metadata = None + self.results_pipe.send((rpdmp.CONN_PARTIAL, (rpdmp.MSG_FILE, (copy_succeeded, rpd_file, i + 1, temp_full_file_name)))) |