优化数据插入,全部更新的方式筛选出那些升级成功,那些包升级失败,再将这个数据插入到数据库

This commit is contained in:
wangsong 2021-11-27 15:11:39 +08:00
parent 89b4d68d72
commit a9cb53e225
1 changed files with 69 additions and 9 deletions

View File

@ -14,6 +14,7 @@ from SystemUpdater.Core.utils import (
get_broken_details
)
import time
from apt import Cache
class NowUpgradePara:
"""
@ -369,14 +370,9 @@ class InstallBackend():
upgrade_content = self.now_upgrade.upgrade_groups + self.now_upgrade.single_pkgs
# unLockedEnableShutdown()
# 信息插入数据库
self.window_main.sqlite3_server.insert_info(
self.now_upgrade.upgrade_mode,
self.now_upgrade.single_pkgs,
self.now_upgrade.upgrade_groups,
self.upgrade_data.adjust_pkgs,
success,
error_string, error_desc)
self._make_insert_info(success,self.now_upgrade.upgrade_mode,error_string,error_desc)
if success:
#当组列表为空时 表示现在的单独进行安装某些包或卸载,不发信号到控制面板
if self.now_upgrade.upgrade_mode != self.MODE_UPGRADE_SINGLE:
@ -426,7 +422,71 @@ class InstallBackend():
elif action == self.ACTION_INSTALL_DEB:
pass
# unLockedEnableShutdown()
def _make_insert_info(self,success,upgrade_mode,error_string,error_desc):
try:
if upgrade_mode == self.MODE_UPGRADE_ALL and success == False:
#获取当前系统中最新的cache
fresh_cache = Cache(rootdir=self.window_main.cache.rootdir)
adjust_pkgs = [i.split("=")[0] for i in self.upgrade_data.adjust_pkgs]
#此种情况只有全部更新一个组,不需要考虑有没有安装完成的 直接走安装失败
if self.now_upgrade.single_pkgs == [] and self.now_upgrade.upgrade_groups != []:
# 信息插入数据库
self.window_main.sqlite3_server.insert_info(upgrade_mode,[],self.now_upgrade.upgrade_groups,[],success,error_string, error_desc)
return
#升级存在单包更新 失败后计算每一个包是否安装完成 相应判断进行插入
if self.now_upgrade.single_pkgs != []:
#获取调整包列表 去掉版本号
for pkg in self.now_upgrade.single_pkgs:
pkg_obj = fresh_cache[pkg]
#判断是否是源过滤调整的包 调整的话 判断安装版本 来解决是否安装成功
if pkg in adjust_pkgs:
if pkg_obj.is_installed == True and pkg_obj.name + '=' + pkg_obj.installed.source_version in self.upgrade_data.adjust_pkgs:
self.window_main.sqlite3_server.insert_info(upgrade_mode,[pkg],[],self.upgrade_data.adjust_pkgs,True,'', '')
else:
logging.warning("This single-package(%s) is not install or upgrade",pkg)
self.window_main.sqlite3_server.insert_info(upgrade_mode,[pkg],[],self.upgrade_data.adjust_pkgs,False,error_string, error_desc)
else:
#非调整版本的计算方式
if pkg_obj.is_installed == True and pkg_obj.is_upgradable == False:
self.window_main.sqlite3_server.insert_info(upgrade_mode,[pkg],[],self.upgrade_data.adjust_pkgs,True,'', '')
else:
logging.warning("This single-package(%s) is not install or upgrade",pkg)
self.window_main.sqlite3_server.insert_info(upgrade_mode,[pkg],[],self.upgrade_data.adjust_pkgs,False,error_string, error_desc)
#组的计算是否升级成功的方式 将组按照单包来计算的
if self.now_upgrade.upgrade_groups != []:
pkgs_install,pkgs_upgrade = self._make_pkgs_list(self.cache,self.upgrade_data.upgrade_groups_pkgs,self.now_upgrade.upgrade_groups,[])
total_pkg = pkgs_install + pkgs_upgrade
for pkg in pkgs_install + pkgs_upgrade:
pkg_obj = fresh_cache[pkg]
if pkg in adjust_pkgs:
if pkg_obj.is_installed == True and pkg_obj.installed.source_version + pkg_obj.name in self.upgrade_data.adjust_pkgs:
total_pkg.remove(pkg)
else:
logging.warning("This groups-package(%s) is not install or upgrade",pkg)
else:
if pkg_obj.is_installed == True and pkg_obj.is_upgradable == False:
total_pkg.remove(pkg)
else:
logging.warning("This groups-package(%s) is not install or upgrade",pkg)
#如果没有
if total_pkg == []:
self.window_main.sqlite3_server.insert_info(upgrade_mode,[],self.now_upgrade.upgrade_groups,self.upgrade_data.adjust_pkgs,True,'', '')
else:
self.window_main.sqlite3_server.insert_info(upgrade_mode,[],self.now_upgrade.upgrade_groups,self.upgrade_data.adjust_pkgs,False,error_string, error_desc)
#其他的部分升级直接存入数据库 不需要进行计算
else:
self.window_main.sqlite3_server.insert_info(upgrade_mode,self.now_upgrade.single_pkgs,self.now_upgrade.upgrade_groups,self.upgrade_data.adjust_pkgs,success,error_string, error_desc)
except Exception as e:
logging.error(str(e))
# try aptdaemon
if os.path.exists("/usr/sbin/aptd") \