From 2b5c667cf9a1dae112618f5dd1f433273dc78ba3 Mon Sep 17 00:00:00 2001 From: wangsong Date: Tue, 30 Nov 2021 10:34:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E5=80=99=E7=9A=84?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E8=BF=9B=E5=BA=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/InstallBackendAptdaemon.py | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/backend/SystemUpdater/backend/InstallBackendAptdaemon.py b/backend/SystemUpdater/backend/InstallBackendAptdaemon.py index 2c0679a..f8be9e1 100644 --- a/backend/SystemUpdater/backend/InstallBackendAptdaemon.py +++ b/backend/SystemUpdater/backend/InstallBackendAptdaemon.py @@ -34,19 +34,31 @@ class InstallBackendAptdaemon(InstallBackend): self.client = client.AptClient() self.trans_failed_msg = None + #模拟发送使用的进度 + self.simulation_progress = 0 + #aptdeamon的实时进度 self.trans_progress = 0 - self.static_progress = 0 + # 活跃性检查 才使用的进度 + self.check_progress = 0 self.trans_status = '' self.details = '' self.on_install_stage = False self.trans_cancelable = False self.last_action_timestamp = time.time() - - if self.action == self.ACTION_INSTALL: + + #定时模拟发送进度 为了让进度更加线性 + if self.action == self.ACTION_UPDATE: #超时检查轮询 - logging.info("timeout_add_seconds init...") - GLib.timeout_add_seconds(UPDATER_IDLE_CHECK_INTERVAL, - self._check_for_inactivity) + GLib.timeout_add_seconds(1,self._check_simulation_progress) + + def _check_simulation_progress(self): + self.simulation_progress += 20 + + if self.trans_progress >= 90 or self.simulation_progress > 80: + return False + else: + self._dist_status_changed(self.action,[],self.simulation_progress,self.trans_status,self.details) + return True def _check_for_inactivity(self): """Shutdown the daemon if it has been inactive for time specified @@ -58,14 +70,14 @@ class InstallBackendAptdaemon(InstallBackend): logging.info("Installing to exit and timeout check quit...") return False #进度不同时 更新时间戳 - if self.trans_progress != self.static_progress: - self.static_progress = self.trans_progress + if self.trans_progress != self.check_progress: + self.check_progress = self.trans_progress self.last_action_timestamp = time.time() #只有安装的时候启用 下载时候不使用 timestamp = self.last_action_timestamp if (time.time() - timestamp > UPDATER_IDLE_TIMEOUT - and self.static_progress > 50): + and self.check_progress > 50): logging.error("Quitting due to inactivity(%s)",self.details) self._action_done(self.ACTION_INSTALL, is_cancelled=False, success=False, @@ -242,6 +254,10 @@ class InstallBackendAptdaemon(InstallBackend): def _on_progress_changed(self, trans,progress,action): if progress == 101: return + + if progress == 11: + progress = 10 + self.trans_progress = progress self._dist_status_changed(action,self.now_upgrade.upgrade_groups+self.now_upgrade.single_pkgs,\ self.trans_progress,self.trans_status,self.details)