添加修复功能解决系统的依赖问题

xiugai

xiugai
This commit is contained in:
wangsong 2021-09-28 11:39:41 +08:00
parent c428ba7b64
commit 01844585d0
3 changed files with 83 additions and 68 deletions

View File

@ -647,9 +647,7 @@ class UpdateList():
def update(self, cache, eventloop_callback=None):
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
header = ''
desc = ''
@ -657,16 +655,12 @@ class UpdateList():
#查找所有可升级的包
for pkg in cache:
try:
if pkg.marked_install:
pkgs_install.append(pkg)
elif pkg.marked_upgrade:
if pkg.is_upgradable:
pkgs_upgrade.append(pkg)
elif pkg.marked_delete:
pkgs_remove.append(pkg)
except Exception as e:
logging.error(e)
logging.info("System all upgradeable packages:new_install:%d upgrade:%d remove:%d",len(pkgs_install),len(pkgs_upgrade),len(pkgs_remove))
logging.info("System all upgradeable packages:upgrade:%d ",len(pkgs_upgrade))
success,group_important_list,pkg_important_list=self._read_important_list(cache,[pkg.name for pkg in pkgs_upgrade])
@ -686,7 +680,7 @@ class UpdateList():
#是否存在可升级的组
if self.local_upgrade_list.get('upgrade_groups_list',[]) or pkg_important_list:
#增加需要移除的包列表
self.local_upgrade_list.update({"pkgs_remove":[pkg.name for pkg in pkgs_remove]})
# self.local_upgrade_list.update({"pkgs_remove":[pkg.name for pkg in pkgs_remove]})
self.local_upgrade_list.update({"pkg_important_list":[pkg for pkg in pkg_important_list]})
return True,header,desc
else:

View File

@ -183,12 +183,6 @@ class UpdateManager():
_success = False
return _success,header,desc
'''1、
dist-upgrade 标记在此处进行
来判断将要删除的包 如果存在要删除的break的包的话 会从dist-upgrade切换到upgrade 目前此功能不使用 默认使用dist-upgrade
'''
self.distUpgradeWouldDelete = self.cache.saveDistUpgrade()
#2、 安装JSON分组配置文件包 安装完毕会重新调start_available --> here 安装失败就直接退出不会进行下面的操作
try:
pkg_json = self.cache[self.update_list.GROUPS_JSON_PKG]

View File

@ -10,8 +10,7 @@ import logging
import os
from gettext import gettext as _
from apt import cache
import apt_pkg
class InstallBackend():
ACTION_UPDATE = 0
@ -23,6 +22,81 @@ class InstallBackend():
#记录当前正在升级的组或者单包
self.now_upgrade_list = []
def _make_commit_list(self,partial_upgrade_list):
pkgs_install = []
pkgs_upgrade = []
local_groups_list = []
local_pkg_list = []
upgrade_groups_list = self.window_main.update_list.local_upgrade_list.get('upgrade_groups_list',[])
pkg_important_list = self.window_main.update_list.local_upgrade_list.get('pkg_important_list',[])
try:
#可选升级
if partial_upgrade_list:
for i in partial_upgrade_list:
#组升级方式
if i in upgrade_groups_list:
local_groups_list.append(i)
#单包升级方式
elif i in pkg_important_list:
local_pkg_list.append(i)
else:
logging.warning("this package(%s) not in selected list",i)
#全部升级列表
else:
local_groups_list = upgrade_groups_list
local_pkg_list = pkg_important_list
#遍历升级组列表
if local_groups_list:
self.now_upgrade_list += local_groups_list
for group_name in local_groups_list:
pkgs_install += self.window_main.update_list.local_upgrade_list.get(group_name,[]).get('pkgs_install',[])
pkgs_upgrade += self.window_main.update_list.local_upgrade_list.get(group_name,[]).get('pkgs_upgrade',[])
#单包的升级方式
if local_pkg_list:
self.now_upgrade_list += local_pkg_list
for pkg in local_pkg_list:
if self.window_main.cache[pkg].is_installed:
pkgs_upgrade.append(pkg)
else:
pkgs_install.append(pkg)
self.window_main.cache._initDepCache()
Fix = apt_pkg.ProblemResolver(self.window_main.cache._depcache)
# for pkg in pkgs_install:
# self.window_main.cache[pkg].mark_install()
for pkg in pkgs_upgrade:
self.window_main.cache[pkg].mark_upgrade()
Fix.resolve()
new_pkgs_install = []
new_pkgs_upgrade = []
new_pkgs_remove = []
for pkg in self.window_main.cache:
try:
if pkg.marked_install:
pkgname = pkg.name
if pkg.is_auto_installed:
pkgname += "#auto"
new_pkgs_install.append(pkgname)
elif pkg.marked_upgrade:
new_pkgs_upgrade.append(pkg.name)
elif pkg.marked_delete:
new_pkgs_remove.append(pkg.name)
except KeyError:
# pkg missing from fresh_cache can't be modified
pass
logging.info("commit install")
return new_pkgs_install,new_pkgs_upgrade,new_pkgs_remove
except Exception as e:
logging.error(e)
def start(self,partial_upgrade_list = []):
#FIXME: 在下载升级的能抑制系统关闭或者睡眠 参考ubuntu此部分代码
@ -32,64 +106,17 @@ class InstallBackend():
pkgs_upgrade = []
pkgs_remove = []
pkgs_purge = []
local_groups_list = []
local_pkg_list = []
upgrade_groups_list = self.window_main.update_list.local_upgrade_list.get('upgrade_groups_list',[])
pkg_important_list = self.window_main.update_list.local_upgrade_list.get('pkg_important_list',[])
logging.info("commit install")
pkgs_install,pkgs_upgrade,pkgs_remove = self._make_commit_list(partial_upgrade_list)
try:
#可选升级
if partial_upgrade_list:
for i in partial_upgrade_list:
#组升级方式
if i in upgrade_groups_list:
local_groups_list.append(i)
#单包升级方式
elif i in pkg_important_list:
local_pkg_list.append(i)
else:
logging.warning("this package(%s) not in selected list",i)
#全部升级列表
else:
local_groups_list = upgrade_groups_list
local_pkg_list = pkg_important_list
#遍历升级组列表
if local_groups_list:
self.now_upgrade_list += local_groups_list
for group_name in local_groups_list:
pkgs_install += self.window_main.update_list.local_upgrade_list.get(group_name,[]).get('pkgs_install',[])
pkgs_upgrade += self.window_main.update_list.local_upgrade_list.get(group_name,[]).get('pkgs_upgrade',[])
pkgs_remove = self.window_main.update_list.local_upgrade_list.get("pkgs_remove",[])
#单包的升级方式
if local_pkg_list:
self.now_upgrade_list += local_pkg_list
for pkg in local_pkg_list:
if self.window_main.cache[pkg].is_installed:
pkgs_upgrade.append(pkg)
else:
pkgs_install.append(pkg)
#目前不确定#auto含义
new_pkgs_install = []
for pkgname in pkgs_install:
pkgname += "#auto"
new_pkgs_install.append(pkgname)
if not new_pkgs_install and not pkgs_upgrade:
return
logging.info("commit install:%d , upgrade:%d remove:%d",len(pkgs_install),len(pkgs_upgrade),len(pkgs_remove))
self.commit(new_pkgs_install, pkgs_upgrade, pkgs_remove,pkgs_purge)
self.commit(pkgs_install, pkgs_upgrade, pkgs_remove,pkgs_purge)
except Exception as e:
logging.error(e)
else:
self.update()
#调用此接口进行安装升级包的话,安装完成或者升级完成会重新调用升级
def start_alone(self,pkgs_install = [], pkgs_upgrade = [], pkgs_remove = [],pkgs_purge = []):
os.environ["APT_LISTCHANGES_FRONTEND"] = "none"