开发单包显示

支持单包升级的方式

去除重复判断

完成单包安装的开发
This commit is contained in:
wangsong 2021-09-24 17:23:11 +08:00
parent 9d7fcf9e60
commit b67818df86
6 changed files with 101 additions and 56 deletions

View File

@ -219,9 +219,6 @@ class UpdateList():
self.OUTPUT_CONFIG_PATH = '/var/lib/kylin-system-upgrade'
self.IMPORTANT_LIST_PATH="/var/lib/kylin-software-properties/template/important.list"
# important推送列表
self.important_list = []
#所有的组升级安装列表
self.local_upgrade_list = {}
@ -490,21 +487,38 @@ class UpdateList():
return app_groups + pkg_groups
def _read_important_list(self):
def _read_important_list(self,cache,pkgs_upgrade):
header = ''
desc = ''
pkg_important_list = []
group_important_list = []
# 获取importantlist 本次更新推送
try:
with open(self.IMPORTANT_LIST_PATH, 'r') as f:
data = f.read()
self.important_list = data.split()
logging.info("importantList: %s",self.important_list)
return True
important_list = data.split()
for pkg_name in important_list:
#检查是否在cache 没有在cache中属于组
if pkg_name in cache:
pkg_obj = cache[pkg_name]
#在可升级的列表当中 此步骤为了排除已安装不需要升级的
if pkg_obj.is_installed:
if pkg_name in pkgs_upgrade:
pkg_important_list.append(pkg_name)
else:
pkg_important_list.append(pkg_name)
else:
group_important_list.append(pkg_name)
logging.info("pkg_important_list: %a, group_important_list:%a",pkg_important_list,group_important_list)
return True,group_important_list,pkg_important_list
except Exception as e:
header = _("read important list failed")
desc = ("%s",str(e))
logging.info(header + desc)
return False,header,desc
return False,[],[]
def _make_pkg_info_json(self,cache,pkgs_list):
total_download_size = 0
@ -535,11 +549,11 @@ class UpdateList():
pkgs_info_json.update({"total_installed_size":total_installed_size})
return pkgs_info_json
#检查包是否在cache中 返回新得列表
#检查包是否在cache中 返回新得列表没 有安装的话才添加到列表
def _check_pkg_in_cache(self,cache,pkgs_list):
new_pkgs_list = []
for pkg_name in pkgs_list:
#检查是否在cache 以及 是否安装检查
#检查是否在cache 以及 是否安装检查
if pkg_name in cache and not cache[pkg_name].is_installed:
new_pkgs_list.append(pkg_name)
else:
@ -573,7 +587,7 @@ class UpdateList():
json.dump(output_json, f, ensure_ascii=False, indent=4)
logging.info("Generate Jsonfile(%s) to complete... ",output_config_name)
def _make_groups_upgrade(self,cache,pkgs_install = [], pkgs_upgrade = [], pkgs_remove = []):
def _make_groups_upgrade(self,cache,group_list,pkgs_install = [], pkgs_upgrade = [], pkgs_remove = []):
try:
files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表
upgrade_groups_list = []
@ -586,7 +600,7 @@ class UpdateList():
group_name = data['package']
#过滤没有推送的配置文件
if not group_name in self.important_list:
if not group_name in group_list:
continue
upgrade_pkgs_list = data['upgrade_list']
@ -595,7 +609,7 @@ class UpdateList():
#这个安装升级列表中包含当前系统的cache中没有的包 需要过滤
remove_pkgs_list = data['remove_list']
#检查包是否在cache中 以及是否已经安装
#检查包是否在cache中 以及是否已经安装 没有安装的话才添加到列表
new_install_pkgs_list = self._check_pkg_in_cache(cache,data['install_list'])
#进行交集 升级列表
@ -640,15 +654,6 @@ class UpdateList():
header = ''
desc = ''
self._read_important_list()
#important_list 为空时此次不需要升级
if not self.important_list:
#不需要升级 全部的软件都是新的
header = _("No software updates are available.")
desc = _('important_list is Empty')
return True,header,desc
#查找所有可升级的包
for pkg in cache:
try:
@ -663,23 +668,33 @@ class UpdateList():
logging.info("System all upgradeable packages:new_install:%d upgrade:%d remove:%d",len(pkgs_install),len(pkgs_upgrade),len(pkgs_remove))
success,group_important_list,pkg_important_list=self._read_important_list(cache,[pkg.name for pkg in pkgs_upgrade])
#important_list 为空时此次不需要升级
if not group_important_list and not pkg_important_list:
#不需要升级 全部的软件都是新的
header = _("No software updates are available.")
desc = _('important_list is Empty')
return True,header,desc
#源过滤
# fu = filter.UpdateListFilterCache()
# allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade)
self._make_groups_upgrade(cache,pkgs_upgrade = ([pkg.name for pkg in pkgs_upgrade]))
self._make_groups_upgrade(cache,group_list = group_important_list,pkgs_upgrade = ([pkg.name for pkg in pkgs_upgrade]))
#是否存在可升级的组
if self.local_upgrade_list.get('upgrade_groups_list',[]):
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({"pkg_important_list":[pkg for pkg in pkg_important_list]})
return True,header,desc
else:
#不需要升级 全部的软件都是新的
header = _("The software on this computer is up to date.")
desc = ''
return True,header,desc
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
# eventloop_callback)

View File

@ -143,8 +143,12 @@ class UpdateManager():
if _success == True and header == INSTALL_ALONE_PROGRESS:
return
else:
#组的升级列表
upgrade_groups_list = self.update_list.local_upgrade_list.get('upgrade_groups_list',[])
#单包的升级列表
pkg_important_list = self.update_list.local_upgrade_list.get('pkg_important_list',[])
#发送更新升级列表完成的标志
self.dbusController.UpdateDetectFinished(_success,self.update_list.local_upgrade_list.get('upgrade_groups_list',[]),header,desc)
self.dbusController.UpdateDetectFinished(_success,upgrade_groups_list,pkg_important_list,header,desc)
#检查安装完成之后需要重启吗
if os.path.exists(REBOOT_REQUIRED_FILE):

View File

@ -99,16 +99,13 @@ class UpdateManagerDbusController(dbus.service.Object):
return False,'In the process of updating or Upgrading...'
else:
partial_upgrade_list = [str(i) for i in _partial_upgrade_list]
#本地维护的可升级的组
upgrade_groups_list = self.parent.update_list.local_upgrade_list.get('upgrade_groups_list',[])
upgrade_list = list(set(partial_upgrade_list) & set(upgrade_groups_list))
if upgrade_list:
logging.info('dbus partial_upgrade(%s)',upgrade_list)
self.parent.start_install(upgrade_list)
if partial_upgrade_list:
logging.info('dbus partial_upgrade(%s)',partial_upgrade_list)
self.parent.start_install(partial_upgrade_list)
return True,'dbus upgrading'
else:
logging.info('input upgrade list(%s) not in local upgrade_list(%s)',partial_upgrade_list,upgrade_groups_list)
logging.info('input upgrade list(%s) not in local upgrade_list(%s)',partial_upgrade_list,partial_upgrade_list)
return False,'upgrade_list is empty'
except Exception as e:
return False,e
@ -136,10 +133,10 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.info("emit progress = %d , status = %s",progress,status)
#更新完成的信号
@dbus.service.signal(INTERFACE,signature='basss')
def UpdateDetectFinished(self, success, upgrade_group,error_string='',error_desc='',):
logging.info("emit update success = %r , upgrade_group = %a, error_string = %s , error_desc = %s ",\
success,upgrade_group, error_string,error_desc)
@dbus.service.signal(INTERFACE,signature='basasss')
def UpdateDetectFinished(self, success, upgrade_group,upgrade_pkg,error_string='',error_desc='',):
logging.info("emit update success = %r , upgrade_group = %a,upgrade_pkg = %a, error_string = %s , error_desc = %s ",\
success,upgrade_group,upgrade_pkg,error_string,error_desc)
#升级的进度信息 0~100 进度信息 101为非预期的信号
@dbus.service.signal(INTERFACE,signature='asis')

View File

@ -87,7 +87,7 @@ class InstallBackendAptdaemon(InstallBackend):
if action == self.ACTION_UPDATE:
self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status)
else:
self.window_main.dbusController.UpdateDloadAndInstStaChanged(self.upgrade_groups_list,self.trans_progress,self.trans_status)
self.window_main.dbusController.UpdateDloadAndInstStaChanged(self.now_upgrade_list,self.trans_progress,self.trans_status)
#同步状态回调
def _on_status_changed(self, trans, status,action):
@ -98,7 +98,7 @@ class InstallBackendAptdaemon(InstallBackend):
self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status)
else:
#升级的时候发送状态信号时需要上传更新组信息self.upgrade_groups_list
self.window_main.dbusController.UpdateDloadAndInstStaChanged(self.upgrade_groups_list,self.trans_progress,self.trans_status)
self.window_main.dbusController.UpdateDloadAndInstStaChanged(self.now_upgrade_list,self.trans_progress,self.trans_status)
def _on_details_changed(self, trans, details):
logging.info(details)

View File

@ -10,6 +10,8 @@ import logging
import os
from gettext import gettext as _
from apt import cache
class InstallBackend():
ACTION_UPDATE = 0
@ -18,7 +20,8 @@ class InstallBackend():
def __init__(self, window_main, action):
self.window_main = window_main
self.action = action
self.upgrade_groups_list = []
#记录当前正在升级的组或者单包
self.now_upgrade_list = []
def start(self,partial_upgrade_list = []):
@ -29,31 +32,57 @@ 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',[])
try:
#可选升级不为空
#可选升级
if partial_upgrade_list:
self.upgrade_groups_list = 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:
self.upgrade_groups_list = self.window_main.update_list.local_upgrade_list.get('upgrade_groups_list',[])
local_groups_list = upgrade_groups_list
local_pkg_list = pkg_important_list
#遍历升级组列表
if self.upgrade_groups_list:
for group_name in self.upgrade_groups_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",[])
else:
logging.info("no upgradeable packages")
return
#目前不确定#auto含义 大概是自动安装新包 类似加-y ubuntu这样做
#单包的升级方式
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)
except Exception as e:
@ -87,24 +116,24 @@ class InstallBackend():
self.window_main.is_upgrading = False
if success:
#当组列表为空时 表示现在的单独进行安装某些包或卸载,不发信号到控制面板
if self.upgrade_groups_list:
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,'','')
if self.now_upgrade_list:
self.window_main.dbusController.UpdateDownloadFinished(success,self.now_upgrade_list,'','')
else:
self.window_main.start_available()
elif error_string or error_desc:
logging.warning(error_string + error_desc)
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,error_string,error_desc)
self.window_main.dbusController.UpdateDownloadFinished(success,self.now_upgrade_list,error_string,error_desc)
else:
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,'','')
self.window_main.dbusController.UpdateDownloadFinished(success,self.now_upgrade_list,'','')
else:
self.window_main.is_updating = False
if success:
self.window_main.start_available()
elif error_string or error_desc:
logging.warning(error_string + error_desc)
self.window_main.dbusController.UpdateDetectFinished(success,[],error_string,error_desc)
self.window_main.dbusController.UpdateDetectFinished(success,[],[],error_string,error_desc)
else:
self.window_main.dbusController.UpdateDetectFinished(success,[],'','')
self.window_main.dbusController.UpdateDetectFinished(success,[],[],'','')
# try aptdaemon
if os.path.exists("/usr/sbin/aptd") \

View File

@ -32,7 +32,7 @@ if __name__ == "__main__":
else:
logging.basicConfig(format=FORMAT,level=logging.INFO)
logging.info('kylin-update-manager starting ...')
logging.info('kylin-update-manager starting ...')
bus_loop = DBusGMainLoop(set_as_default=True)
app = UpdateManager(options)