def start_transfer_op(self, op): logging.debug("Remote RPC: calling StartTransfer on '%s'" % (self.display_hostname)) start_time = GLib.get_monotonic_time() op.progress_tracker = transfers.OpProgressTracker(op) op.current_progress_report = None receiver = transfers.FileReceiver(op) op.set_status(OpStatus.TRANSFERRING) op.file_iterator = self.stub.StartTransfer( warp_pb2.OpInfo(timestamp=op.start_time, ident=self.local_ident, readable_name=util.get_hostname(), use_compression=op.use_compression and prefs.use_compression())) def report_receive_error(error): op.set_error(error) try: # If we leave an io stream open, it locks the location. For instance, # if this was a mounted location, we wouldn't be able to terminate until # we closed warp. if receiver.current_stream != None: receiver.current_stream.close() except GLib.Error: pass logging.critical("An error occurred receiving data from %s: %s" % (op.sender, op.error_msg)) op.set_status(OpStatus.FAILED) op.stop_transfer() try: for data in op.file_iterator: receiver.receive_data(data) except grpc.RpcError: if op.file_iterator.code() == grpc.StatusCode.CANCELLED: op.file_iterator = None return else: report_receive_error(op.file_iterator) return except Exception as e: report_receive_error(e) return op.file_iterator = None receiver.receive_finished() logging.debug("Remote: receipt of %s files (%s) finished in %s" % \ (op.total_count, GLib.format_size(op.total_size),\ util.precise_format_time_span(GLib.get_monotonic_time() - start_time))) op.set_status(OpStatus.FINISHED)
def transfer_done(): if sender.error != None: op.set_error(sender.error) op.stop_transfer() op.set_status(OpStatus.FAILED_UNRECOVERABLE) elif op.file_send_cancellable.is_set(): print("File send cancelled") else: print("Transfer of %s files (%s) finished in %s" % \ (op.total_count, GLib.format_size(op.total_size),\ util.precise_format_time_span(GLib.get_monotonic_time() - start_time)))
def _update_progress(self, cb_info): if cb_info.finished: with self.proxy.lock: # Don't send NeverStartedSending errors to the other end. if cb_info.error and isinstance(cb_info.error, Aborted): e_str = str(cb_info.error) else: e_str = None self.proxy.update_progress(self.app_name, 0, "", "", cb_info.finished, e_str) GLib.idle_add(self.progress_callback, cb_info, priority=GLib.PRIORITY_DEFAULT) print("finished: %s" % util.precise_format_time_span(GLib.get_monotonic_time() - self.start_time)) return if cb_info.is_informational(): GLib.idle_add(self.progress_callback, cb_info, priority=GLib.PRIORITY_DEFAULT) return cb_info.progress = self.current_transfer_size / self.total_transfer_size cur_time = GLib.get_monotonic_time() total_elapsed = cur_time - self.start_time if (cur_time - self.interval_start_time) > self.PROGRESS_INTERVAL: self.interval_start_time = cur_time bytes_per_micro = self.current_transfer_size / total_elapsed bytes_per_sec = int(bytes_per_micro * 1000 * 1000) bytes_left = self.total_transfer_size - self.current_transfer_size time_left_sec = bytes_left / bytes_per_sec cb_info.speed = _("%s/s") % GLib.format_size(bytes_per_sec) cb_info.time_left = util.format_time_span(time_left_sec) with self.proxy.lock: self.proxy.update_progress(self.app_name, cb_info.progress, cb_info.speed, cb_info.time_left, cb_info.finished, None) GLib.idle_add(self.progress_callback, cb_info, priority=GLib.PRIORITY_DEFAULT)