def update_progress(self, size_read): self.total_transferred += size_read now = GLib.get_monotonic_time() if ((now - self.last_update_time) > util.PROGRESS_UPDATE_FREQ): self.last_update_time = now progress = self.total_transferred / self.total_size elapsed = now - self.transfer_start_time bytes_per_micro = self.total_transferred / elapsed bytes_per_sec = int(bytes_per_micro * 1000 * 1000) if bytes_per_sec == 0: bytes_per_sec = 1 # no a/0 time_left_sec = (self.total_size - self.total_transferred) / bytes_per_sec print("%s time left, %s/s" % (util.format_time_span(time_left_sec), GLib.format_size(bytes_per_sec))) progress_report = Progress(progress, time_left_sec, bytes_per_sec) self.op.progress_report(progress_report)
def progress_report(self, report): self.current_progress_report = report report.progress_text = _("%(time_left)s (%(bytes_per_sec)s/s)") \ % ({ "time_left": util.format_time_span(report.time_left_sec), "bytes_per_sec": GLib.format_size(report.bytes_per_sec) }) if report.progress == 1.0: self.status = OpStatus.FINISHED self.emit_status_changed() return self.emit("progress-changed")
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)
def __init__(self, progress, time_left_sec, bytes_per_sec): self.progress = progress self.time_left_sec = time_left_sec self.bytes_per_sec = bytes_per_sec self.progress_text = _("%s (%s/s)") % (util.format_time_span( time_left_sec), GLib.format_size(bytes_per_sec))