添加更新时候检测系统环境是否破损以及提示修复方案

This commit is contained in:
wangsong 2021-11-25 20:36:45 +08:00
parent 561232d079
commit ad08a33a06
3 changed files with 50 additions and 4 deletions

View File

@ -475,7 +475,26 @@ def error(parent, summary, message):
d.destroy()
return False
def get_broken_details(cache,now=False):
def get_lis_from_cache(cache):
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
#计算修复破损包 方案 需要删除 新装那些包
for pkg in cache:
try:
if pkg.marked_install :
pkgs_install.append(pkg.name)
elif pkg.marked_upgrade:
pkgs_upgrade.append(pkg.name)
elif pkg.marked_delete:
pkgs_remove.append(pkg.name)
except KeyError:
# pkg missing from fresh_cache can't be modified
pass
return pkgs_install,pkgs_upgrade,pkgs_remove
def get_broken_details(cache,now=True):
"""Return a message which provides debugging information about
broken packages.
@ -549,11 +568,11 @@ def get_broken_details(cache,now=False):
"be installed")
elif now:
# TRANSLATORS: %s is a version number
or_msg += (("but %s is installed") %
or_msg += (_("but %s is installed") %
dep_version.version)
else:
# TRANSLATORS: %s is a version number
or_msg += (("but %s is to be installed") %
or_msg += (_("but %s is to be installed") %
dep_version.version)
else:
# Only append an or-group if at least one of the

View File

@ -24,6 +24,7 @@ from gettext import gettext as _
from SystemUpdater.backend import DownloadBackend as downb
import apt_pkg
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
from SystemUpdater.Core.utils import get_broken_details,get_lis_from_cache
class UpdateManager():
SELF_PKG_NAME = 'kylin-system-updater'
@ -315,6 +316,8 @@ class UpdateManager():
"message:\n") + str(e)
_success = False
return _success,header,desc
self._check_cache_broken(self.cache)
#检查出现安装过程异常重启 出现的话 进行异常修复
if self.configs.getWithDefault("SystemStatus", "isabnormalreboot", False) == True:
@ -346,6 +349,30 @@ class UpdateManager():
return os.path.exists(os.path.join(apt_pkg.config.find_dir("Dir"),
"var/run/reboot-required"))
def _check_cache_broken(self,cache):
with cache.actiongroup():
if cache.get_changes():
cache.clear()
#获取出现破损状态包的数量
wouldDelete = cache._depcache.broken_count
if wouldDelete > 0:
#获取那些依赖关系不满足导致的问题
logging.info(get_broken_details(cache))
else:
return
try:
#计算依赖的解决方案
cache.fix_broken()
except SystemError as e:
logging.error(e)
return
pkgs_install,pkgs_upgrade,pkgs_remove = get_lis_from_cache(cache)
logging.warning("Fix broken Packages is need to install:%a and upgrade:%a and remove:%a",pkgs_install,pkgs_upgrade,pkgs_remove)
if cache.get_changes():
cache.clear()
def _setup_dbus(self):
# check if there is another g-a-i already and if not setup one

View File

@ -356,7 +356,7 @@ class InstallBackend():
desc = str(e)
logging.error(header + desc)
msg = get_broken_details(self.cache)
msg = get_broken_details(self.cache,False)
logging.error(msg)
return _success,[],[],header,desc