diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index b22bbc8..1962d42 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -316,10 +316,8 @@ class UpdateManager(): "message:\n") + str(e) _success = False return _success,header,desc - - self._check_cache_broken(self.cache) - #检查出现安装过程异常重启 出现的话 进行异常修复 + #1、 检查出现安装过程异常重启 出现的话 进行异常修复 if self.configs.getWithDefault("SystemStatus", "isabnormalreboot", False) == True: header = self.INSTALL_ALONE_PROGRESS self.configs.setValue("SystemStatus","isabnormalreboot",str(False),True) @@ -327,6 +325,9 @@ class UpdateManager(): self.start_fix_broken() return False,header,desc + #检查当前系统的状态 是否存在系统为破损状态 导致出现异常 + self._check_cache_broken(self.cache) + self.update_list = UpdateList(self) #检查自己是否需要升级更新 diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 4883259..884217e 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -15,6 +15,7 @@ from SystemUpdater.Core.utils import ( ) import time from apt import Cache +from SystemUpdater.Core.UpdateList import LocalUpgradeDataList class NowUpgradePara: """ @@ -69,6 +70,10 @@ class InstallBackend(): if self.window_main.update_list != None: #本地维护的升级列表和需要升级的包 self.upgrade_data = window_main.update_list.local_upgrade_data + else: + #生成一个空的列表 防止出现错误 在更新和安装单包的时候这个对象还没生成 + self.upgrade_data = LocalUpgradeDataList({},[],[],[]) + #要拿到升级列表必须调用_make_upgrade_list self.now_upgrade = NowUpgradePara([],self.MODE_DEFAULT_STATUS,[]) @@ -84,7 +89,7 @@ class InstallBackend(): #拿到升级列表 self.now_upgrade.upgrade_groups,self.now_upgrade.single_pkgs = self._make_groups_list(self.upgrade_data,_upgrade_mode,partial_upgrade_list) - pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,_upgrade_mode) + pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,self.upgrade_data.adjust_pkgs,_upgrade_mode) logging.info("INSTALL install:%d , upgrade:%d remove:%d",len(pkgs_install),len(pkgs_upgrade),len(pkgs_remove)) @@ -125,7 +130,7 @@ class InstallBackend(): pkgs_install,pkgs_upgrade = self._make_pkgs_list(self.cache,self.upgrade_data.upgrade_groups_pkgs,self.now_upgrade.upgrade_groups,self.now_upgrade.single_pkgs) #计算解决依赖关系 _success,delete_pkgs,delete_desc,header,desc = self._make_problem_resolver(pkgs_install,pkgs_upgrade) - pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,_upgrade_mode) + pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,self.upgrade_data.adjust_pkgs,_upgrade_mode) pkgs_remove = delete_pkgs else: # 使用全盘升级 全盘使用dist-upgrade @@ -133,7 +138,7 @@ class InstallBackend(): if self.cache.get_changes(): self.cache.clear() _success = self.cache._depcache.upgrade(True) - pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,_upgrade_mode) + pkgs_install,pkgs_upgrade,pkgs_remove = self._get_mark_from_cache(self.cache,self.upgrade_data.adjust_pkgs,_upgrade_mode) except Exception as e: _success = False desc = str(e) @@ -217,17 +222,17 @@ class InstallBackend(): raise NotImplementedError #从cache中拿到标记的列表 - def _get_mark_from_cache(self,cache,upgrade_mode): + def _get_mark_from_cache(self,cache,_adjust_pkgs,upgrade_mode): pkgs_install = [] pkgs_upgrade = [] pkgs_remove = [] - - #全盘升级不做任何的调整 修复bug,出现调整版本,报错不需要更新升级退出 + + #全盘升级不做任何的调整 if upgrade_mode == self.MODE_UPGRADE_SYSTEM: adjust_pkgs = [] else: #获取调整包列表 去掉版本号 - adjust_pkgs = [i.split("=")[0] for i in self.upgrade_data.adjust_pkgs] + adjust_pkgs = [i.split("=")[0] for i in _adjust_pkgs] for pkg in cache: try: @@ -236,12 +241,12 @@ class InstallBackend(): if pkg.is_auto_installed: pkgname += "#auto" if pkg.name in adjust_pkgs: - pkgs_install.append(self.upgrade_data.adjust_pkgs[adjust_pkgs.index(pkg.name)]) + pkgs_install.append(_adjust_pkgs[adjust_pkgs.index(pkg.name)]) else: pkgs_install.append(pkgname) elif pkg.marked_upgrade: if pkg.name in adjust_pkgs: - pkgs_upgrade.append(self.upgrade_data.adjust_pkgs[adjust_pkgs.index(pkg.name)]) + pkgs_upgrade.append(_adjust_pkgs[adjust_pkgs.index(pkg.name)]) else: pkgs_upgrade.append(pkg.name) elif pkg.marked_delete: @@ -387,7 +392,7 @@ class InstallBackend(): else: #当单包升级的时候 升级本身时,让程序退出,再重新启动 if self.window_main.SELF_PKG_NAME in self.cache and self.cache[self.window_main.SELF_PKG_NAME] in self.cache.get_changes(): - self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.SELF_PKG_NAME],"更新管理器升级完成,请重启控制面板进行系统更新",error_desc) + self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.SELF_PKG_NAME],"更新管理器升级完成,请重启控制面板后再进行系统更新",error_desc) self.window_main.dbusController.Quit(None) else: #只有安装配置文件包 才会走到此处 @@ -395,8 +400,12 @@ class InstallBackend(): return #当更新过程中安装配置包时 失败时发送错误信号 elif success == False and self.now_upgrade.upgrade_mode == self.MODE_UPGRADE_SINGLE: - self.window_main.dbusController.DistUpdateDetectFinished(success,upgrade_content,error_string+','+error_desc,error_desc) - + # 防止错误结果太长导致出现控制面板显示太多 目前最多20字符 + if len(error_string + error_desc) > 20: + self.window_main.dbusController.DistUpdateDetectFinished(success,upgrade_content,error_string,error_desc) + else: + self.window_main.dbusController.DistUpdateDetectFinished(success,upgrade_content,error_string+','+error_desc,error_desc) + if error_string != '' or error_desc != '': logging.info(error_string + error_desc) @@ -429,7 +438,6 @@ class InstallBackend(): try: error_desc = error_desc +'\n\n'+self.trans_error_details - # is_single_groups = success == False and upgrade_mode == self.MODE_UPGRADE_PARTIAL and self.now_upgrade.upgrade_groups != [] and self.upgrade_data.single_pkgs == [] if (upgrade_mode == self.MODE_UPGRADE_ALL and success == False) or (upgrade_mode == self.MODE_UPGRADE_PARTIAL and self.now_upgrade.upgrade_groups != []): #获取当前系统中最新的cache