From b3ebb0123da4bbff32387b1470620b0f18afb466 Mon Sep 17 00:00:00 2001 From: luoxueyi Date: Sat, 30 Oct 2021 16:11:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E6=A4=8D=E6=9B=B4=E6=94=B9apt?= =?UTF-8?q?=E9=99=90=E9=80=9F=E6=8E=A5=E5=8F=A3=20update=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=8E=A8=E8=BF=9F=E8=87=B3=E6=BA=90=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/UpdateManager.py | 3 ++ backend/SystemUpdater/UpdateManagerDbus.py | 32 +++++++++++++++++++ .../backend/InstallBackendAptdaemon.py | 10 +++--- backend/SystemUpdater/backend/__init__.py | 4 +++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index 5f24ddf..42e5932 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -21,6 +21,7 @@ import time from gettext import gettext as _ from SystemUpdater.backend import DownloadBackend as downb from SystemUpdater.Core.Database import MODE_UPGRADE_SINGLE +from aptdaemon.enums import get_status_string_from_enum import apt_pkg GROUPS_PKG_NAME = 'kylin-update-desktop-config' @@ -104,8 +105,10 @@ class UpdateManager(): return else: upgrade_list = [] + trans_status = get_status_string_from_enum('status-finished') if self.update_list != None: upgrade_list = self.update_list.local_upgrade_data.upgrade_groups + self.update_list.local_upgrade_data.single_pkgs + self.dbusController.UpdateDetectStatusChanged(100,'status-finished') #发送更新升级列表完成的标志 self.dbusController.UpdateDetectFinished(_success,upgrade_list,header,desc) #检查安装完成之后需要重启吗 diff --git a/backend/SystemUpdater/UpdateManagerDbus.py b/backend/SystemUpdater/UpdateManagerDbus.py index 19a6991..a1b6da0 100755 --- a/backend/SystemUpdater/UpdateManagerDbus.py +++ b/backend/SystemUpdater/UpdateManagerDbus.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 +import os import dbus import dbus.service import logging @@ -227,6 +228,35 @@ class UpdateManagerDbusController(dbus.service.Object): self.parent.start_download(pkgs) times -= 1 return True + + # + # dbus接口:改变apt下载速度 + # + @dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature='sb') + def set_downloadspeed_max(self, speed, set): + if set: + with open("/etc/apt/apt.conf.d/80apt-download", "w+") as f: + text = f.write("Acquire::http::Dl-Limit" + " \"" + "%s" % str(speed) + "\";\n") + text = f.write("Acquire::https::Dl-Limit" + " \"" + "%s" % str(speed) + "\";\n") + return True + else: + if os.path.exists("/etc/apt/apt.conf.d/80apt-download"): + os.remove("/etc/apt/apt.conf.d/80apt-download") + return False + else: + return False + + # + # dbus接口:获取apt下载速度 + # + @dbus.service.method(UPDATER_DBUS_INTERFACE, out_signature='bs') + def get_downloadspeed_limit_value(self): + try: + f = open("/etc/apt/apt.conf.d/80apt-download", "r") + value = f.readline().split() + return True, int(value[1][1:-2]) + except: + return False, 0 #更新进度信息 0~100 进度信息 101为非预期的信号 @dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='is') @@ -282,3 +312,5 @@ class UpdateManagerDbusController(dbus.service.Object): def UpdateSqlitSingle(self, appname, date): logging.info(COLORLOG_PREFIX + "emit" + COLORLOG_SUFFIX +" UpdateSqlitSingle: [ %s ]: date: %s .",\ appname, date) + + diff --git a/backend/SystemUpdater/backend/InstallBackendAptdaemon.py b/backend/SystemUpdater/backend/InstallBackendAptdaemon.py index 378fff7..2fdb051 100644 --- a/backend/SystemUpdater/backend/InstallBackendAptdaemon.py +++ b/backend/SystemUpdater/backend/InstallBackendAptdaemon.py @@ -167,8 +167,9 @@ class InstallBackendAptdaemon(InstallBackend): if progress == 101: return self.trans_progress = progress - if action == self.ACTION_UPDATE: - self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status) + if action == self.ACTION_UPDATE: # 更新进度100后推迟发出100%的信号 -- 等待源过滤完成 + if progress != 100: + self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status) else: if progress >= 50 and action != self.ACTION_DOWNLOADONLY: LockedPreventShutdown() @@ -181,8 +182,9 @@ class InstallBackendAptdaemon(InstallBackend): #转化词条 self.trans_status = get_status_string_from_enum(status) - if action == self.ACTION_UPDATE: - self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status) + if action == self.ACTION_UPDATE: # 更新进度100后推迟发出100%的信号 -- 等待源过滤完成 + if self.trans_progress != 100: + self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status) elif action == self.ACTION_INSTALL and action == self.ACTION_INSTALL_DEB: #升级的时候发送状态信号时需要上传更新组信息self.upgrade_groups_list upgrade_content = self.now_upgrade.upgrade_groups+self.now_upgrade.single_pkgs diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index dd28231..8ec8e2b 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -15,6 +15,7 @@ from SystemUpdater.Core.utils import ( unLockedEnableShutdown, check_free_space ) +from aptdaemon.enums import get_status_string_from_enum from ..Core.Database import MODE_DEFAULT_STATUS,MODE_UPGRADE_PARTIAL,MODE_UPGRADE_ALL,MODE_UPGRADE_SYSTEM,MODE_UPGRADE_SINGLE class NowUpgradePara: @@ -318,13 +319,16 @@ class InstallBackend(): self.window_main.dbusController.UpdateInstallFinished(success,upgrade_content,error_string,error_desc) elif action == self.ACTION_UPDATE: self.window_main.is_updating = False + trans_status = get_status_string_from_enum('status-finished') if success: #开始生成列表 self.window_main.start_available() elif error_string or error_desc: + self.window_main.dbusController.UpdateDetectStatusChanged(100,trans_status) logging.warning(error_string + error_desc) self.window_main.dbusController.UpdateDetectFinished(success,[],error_string,error_desc) else: + self.window_main.dbusController.UpdateDetectStatusChanged(100,trans_status) self.window_main.dbusController.UpdateDetectFinished(success,[],'','') elif action == self.ACTION_DOWNLOADONLY: self.window_main.is_upgrading = False