From da6c96f06aec5e32334f21a5d10a1450843c0f85 Mon Sep 17 00:00:00 2001 From: luoxueyi Date: Fri, 14 Oct 2022 15:20:35 +0800 Subject: [PATCH] check_change --- .../SystemUpdater/Core/DpkgInstallProgress.py | 1 + backend/SystemUpdater/UpdateManager.py | 18 ++-- .../SystemUpdater/UpgradeStrategiesDbus.py | 98 +++++++++++-------- 3 files changed, 68 insertions(+), 49 deletions(-) diff --git a/backend/SystemUpdater/Core/DpkgInstallProgress.py b/backend/SystemUpdater/Core/DpkgInstallProgress.py index a32acd8..67c4b83 100755 --- a/backend/SystemUpdater/Core/DpkgInstallProgress.py +++ b/backend/SystemUpdater/Core/DpkgInstallProgress.py @@ -17,6 +17,7 @@ class LogInstallProgress(apt.progress.base.InstallProgress): self.filename=file self.error_pkg="" self.errormsg="" + # raise Exception("for test!!!") def error(self,pkg, errormsg): logging.error(("Install mode - dpkg, Install error: %s"), errormsg) diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index e27797f..9eeef9d 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -639,7 +639,7 @@ class UpdateManager(): if depends.split('_')[0] == debfile.split('_')[0] and depends.split('_')[1] == debfile.split('_')[1] and debfile not in satisfy_list: depends_count += 1 satisfy_list.append(debfile) - if depends_count < len(noSatisfyList): + if depends_count < len(noSatisfyList) or depends_count < len(depends_pkg): #本地依赖不满足 error_string = str(debname.split("_")[0])+_("dependency is not satisfied")+", ".join(noSatisfyList) logging.error(error_string) @@ -687,12 +687,12 @@ class UpdateManager(): # 检查本地破损 try: deb_cache = Cache() - logging.info("Install deb package, check broken") + logging.info("Install deb_package, check broken") broken_count = deb_cache._depcache.broken_count - deb = DebPackage(deb_path, deb_cache) - deb.check(allow_downgrade=True) - logging.info("Install deb package, required changes") - (install, remove, unauth) = deb.required_changes # need in cach + debPackage = DebPackage(deb_path, deb_cache) + debPackage.check(allow_downgrade=True) + logging.info("Install deb_package, required changes") + (install, remove, unauth) = debPackage.required_changes # need in cach if broken_count > 0: self._is_broken = True else : @@ -712,7 +712,7 @@ class UpdateManager(): raise UpdateBaseError(ERROR_INSTALL_DEB_BASE) self._need_downgrade = False # 不满足的依赖列表 - depends = deb.depends + depends = debPackage.depends self.noSatisfyList = self._gen_noSatisfyList(depends, deb_cache) _list = [] # cache是否满足 @@ -736,8 +736,8 @@ class UpdateManager(): _group_satify = False providers = [] for or_group in depends: - for deb in or_group: - debname,ver,oper = deb + for deb_info in or_group: + debname,ver,oper = deb_info if ":" in debname: debname=debname.split(":")[0] try: diff --git a/backend/SystemUpdater/UpgradeStrategiesDbus.py b/backend/SystemUpdater/UpgradeStrategiesDbus.py index 321ffd4..814597a 100644 --- a/backend/SystemUpdater/UpgradeStrategiesDbus.py +++ b/backend/SystemUpdater/UpgradeStrategiesDbus.py @@ -54,6 +54,13 @@ class UpgradeStrategiesDbusController(dbus.service.Object): self.transaction = None + def __check_change__(self, _config = None, _section = "", _option = "", _value = ""): + if _config == None: + return False + if _value == _config.getWithDefault(_section,_option,_value," "): + return True + return False + @dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature="", out_signature="", sender_keyword="caller_name") @@ -74,13 +81,16 @@ class UpgradeStrategiesDbusController(dbus.service.Object): logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' SetPreDownloadState, state is %r, time: %s, sender name: %s .',state,time,sender_name) try: if state: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "preDownload", "on", True) - self.parent.uuconfigs.setValue("autoUpgradePolicy", "preDownloadTime", time, True) - self.PropertyChanged("preDownload","on") - self.PropertyChanged("preDownloadTime",time) + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "preDownload", "on"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "preDownload", "on", True) + self.PropertyChanged("preDownload","on") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "preDownloadTime", time): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "preDownloadTime", time, True) + self.PropertyChanged("preDownloadTime",time) else: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "preDownload", "off", True) - self.PropertyChanged("preDownload","off") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "preDownload", "off"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "preDownload", "off", True) + self.PropertyChanged("preDownload","off") except Exception as e: logging.error(str(e)) return False @@ -94,8 +104,9 @@ class UpgradeStrategiesDbusController(dbus.service.Object): logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' SetUpdateDays, days: %d , sender:%s .'\ ,_days,sender_name) try: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "updateDays", _days, True) - self.PropertyChanged("updateDays",str(_days)) + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "updateDays", _days): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "updateDays", str(_days), True) + self.PropertyChanged("updateDays",str(_days)) except Exception as e: logging.error(str(e)) return False @@ -106,11 +117,12 @@ class UpgradeStrategiesDbusController(dbus.service.Object): def SetAutoUpgradeRandomRange(self,randomRange,sender=None): _randomRange = str(randomRange) sender_name = get_proc_from_dbus_name(sender) - logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' SetAutoUpgradeRandomRange will be set value %d, sender: %s .',\ + logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' SetAutoUpgradeRandomRange will be set value %s, sender: %s .',\ _randomRange,sender_name) try: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "randomRange", _randomRange, True) - self.PropertyChanged("randomRange",_randomRange) + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "randomRange", _randomRange): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "randomRange", _randomRange, True) + self.PropertyChanged("randomRange",_randomRange) except Exception as e: logging.error(str(e)) return True,"success" @@ -125,13 +137,16 @@ class UpgradeStrategiesDbusController(dbus.service.Object): ,_state,_reboot_time,sender_name) try: if _state: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "automaticReboot", "on", True) - self.parent.uuconfigs.setValue("autoUpgradePolicy", "automaticRebootTime", _reboot_time, True) - self.PropertyChanged("automaticReboot","on") - self.PropertyChanged("preDownloadTime",_reboot_time) + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "automaticReboot", "on"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "automaticReboot", "on", True) + self.PropertyChanged("automaticReboot","on") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "automaticRebootTime", _reboot_time): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "automaticRebootTime", _reboot_time, True) + self.PropertyChanged("automaticRebootTime",_reboot_time) else: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "automaticReboot", "off", True) - self.PropertyChanged("automaticReboot","off") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "automaticReboot", "off"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "automaticReboot", "off", True) + self.PropertyChanged("automaticReboot","off") except Exception as e: logging.error(str(e)) return False @@ -144,15 +159,17 @@ class UpgradeStrategiesDbusController(dbus.service.Object): logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' SetAutoUpgradeState, state is %r ...',state) try: if state: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "autoUpgradeState", "on", True) - self.parent.sqlite3_server.insert_into_display("autoupdate_allow", "true") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "autoUpgradeState", "on"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "autoUpgradeState", "on", True) + self.parent.sqlite3_server.insert_into_display("autoupdate_allow", "true") + self.PropertyChanged("autoUpgradeState","on") self.ButtonStatusChange("autoUpgradeStatus", "true") - self.PropertyChanged("autoUpgradeState","on") else : - self.parent.uuconfigs.setValue("autoUpgradePolicy", "autoUpgradeState", "off", True) - self.parent.sqlite3_server.insert_into_display("autoupdate_allow", "false") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "autoUpgradeState", "off"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "autoUpgradeState", "off", True) + self.parent.sqlite3_server.insert_into_display("autoupdate_allow", "false") + self.PropertyChanged("autoUpgradeState","off") self.ButtonStatusChange("autoUpgradeStatus", "false") - self.PropertyChanged("autoUpgradeState","off") except Exception as e: logging.error(str(e)) return False @@ -165,27 +182,28 @@ class UpgradeStrategiesDbusController(dbus.service.Object): logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' SetAutoUpgradeMode, mode is %s, time is %s ...',mode,_time) try: if mode == UU_UPGRADE_MODE_AUTOMATIC_DOWNLOAD: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "downloadMode", "timing", True) - self.parent.uuconfigs.setValue("autoUpgradePolicy", "downloadTime", str(_time), True) - + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "downloadMode", "timing"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "downloadMode", "timing", True) + self.PropertyChanged("downloadMode","timing") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "downloadTime", str(_time)): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "downloadTime", str(_time), True) + self.PropertyChanged("downloadTime",str(_time)) self.ButtonStatusChange("autoUpgradeTime", str(_time)) - self.PropertyChanged("downloadMode","timing") - self.PropertyChanged("downloadTime",str(_time)) elif mode == UU_UPGRADE_MODE_AUTOMATIC_INSTALL: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "installMode", "timing", True) - self.parent.uuconfigs.setValue("autoUpgradePolicy", "installTime", str(_time), True) - - self.PropertyChanged("installMode","timing") - self.PropertyChanged("installTime",str(_time)) + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "installMode", "timing"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "installMode", "timing", True) + self.PropertyChanged("installMode","timing") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "installTime", str(_time)): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "installTime", str(_time), True) + self.PropertyChanged("installTime",str(_time)) elif mode == UU_UPGRADE_MODE_BEFORE_SHUTDOWN: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "installMode", "bshutdown", True) - - self.PropertyChanged("installMode","bshutdown") + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "installTime", "bshutdown"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "installMode", "bshutdown", True) + self.PropertyChanged("installMode","bshutdown") elif mode == UU_UPGRADE_MODE_MANUAL: - self.parent.uuconfigs.setValue("autoUpgradePolicy", "downloadMode", "manual", True) - - self.PropertyChanged("downloadMode","manual") - + if not self.__check_change__(self.parent.uuconfigs, "autoUpgradePolicy", "downloadMode", "manual"): + self.parent.uuconfigs.setValue("autoUpgradePolicy", "downloadMode", "manual", True) + self.PropertyChanged("downloadMode","manual") except Exception as e: logging.error(str(e)) return False