增加对openkylin的支持

This commit is contained in:
wangsong 2022-09-01 15:14:47 +08:00
parent d77f116b2b
commit 8ccfc0c9d5
2 changed files with 133 additions and 59 deletions

View File

@ -79,14 +79,11 @@ class UpdateList():
logging.info('Emptying the ConfigPath(%s) is complete...',self.OUTPUT_CONFIG_PATH)
#读取推送列表,判断分组和单包推送,再进行源过滤
def _read_important_list(self,cache,pkgs_upgrade):
def _make_important_list(self,cache,pkgs_upgrade,important_list = []):
upgradeable_pkgs = []
tmp = []
upgradeable_groups = []
with open(self.IMPORTANT_LIST_PATH, 'r') as f:
data = f.read()
important_list = data.split()
logging.info("The Server Push List: %a",important_list)
for pkg_name in important_list:
@ -95,8 +92,8 @@ class UpdateList():
pkg_obj = cache[pkg_name]
#在可升级的列表当中 此步骤为了排除已安装不需要升级的
if pkg_obj.is_installed:
if pkg_obj in pkgs_upgrade:
pkgs_upgrade.remove(pkg_obj)
if pkg_name in pkgs_upgrade:
pkgs_upgrade.remove(pkg_name)
tmp.append(pkg_obj)
else:
tmp.append(pkg_obj)
@ -356,7 +353,49 @@ class UpdateList():
return downgrade_raw,downgrade_pkgs
def _make_groups_upgrade(self,cache,group_list, pkgs_upgrade = []):
def _make_groups_pkgs(self,cache,data,pkgs_upgrade = []):
upgrade_pkgs_list = data['upgrade_list']
#检查包是否在cache中 以及是否已经安装 没有安装的话才添加到列表
new_install_list = self._check_pkg_in_cache(cache,data['install_list'])
downgrade_raw,downgrade_pkgs = self._get_downgrade_list(cache,data)
#被降级的软件包优先级最高
for pkg in downgrade_pkgs:
if pkg in upgrade_pkgs_list:
upgrade_pkgs_list.remove(pkg)
if pkg in new_install_list:
new_install_list.remove(pkg)
if pkg in self.upgrade_meta.single_pkgs:
self.upgrade_meta.single_pkgs.remove(pkg)
#进行交集 升级列表
new_upgrade_list = list(set(pkgs_upgrade) & set(upgrade_pkgs_list))
#进行源过滤
new_install_list,new_upgrade_list,adjust_pkgs = self._make_fiter_origin([cache[pkg] for pkg in new_install_list + new_upgrade_list],False)
self.upgrade_meta.adjust_pkgs.extend(adjust_pkgs)
#在总升级列表中移除这些包
for pkg in new_upgrade_list:
pkgs_upgrade.remove(pkg)
downgrade_pkg,adjust_pkgs = self._make_downgrade(cache,downgrade_raw)
self.upgrade_meta.adjust_pkgs.extend(adjust_pkgs)
new_upgrade_list.extend(downgrade_pkg)
#单包的优先级最高 从组中剔除此包
for pkg in self.upgrade_meta.single_pkgs:
if pkg in new_install_list:
new_install_list.remove(pkg)
return new_install_list,new_upgrade_list
def _make_groups_upgrade(self,cache,group_list,is_openkylin,pkgs_install,pkgs_upgrade):
upgrade_list = []
install_list = []
if os.path.isdir(self.config_path) == False:
logging.warning("configPath(%s) is not exists...",self.config_path)
return
@ -386,48 +425,20 @@ class UpdateList():
#过滤没有推送的配置文件
if not group_name in group_list:
continue
upgrade_pkgs_list = data['upgrade_list']
#检查包是否在cache中 以及是否已经安装 没有安装的话才添加到列表
new_install_list = self._check_pkg_in_cache(cache,data['install_list'])
downgrade_raw,downgrade_pkgs = self._get_downgrade_list(cache,data)
#被降级的软件包优先级最高
for pkg in downgrade_pkgs:
if pkg in upgrade_pkgs_list:
upgrade_pkgs_list.remove(pkg)
if pkg in new_install_list:
new_install_list.remove(pkg)
if pkg in self.upgrade_meta.single_pkgs:
self.upgrade_meta.single_pkgs.remove(pkg)
#进行交集 升级列表
new_upgrade_list = list(set(pkgs_upgrade) & set(upgrade_pkgs_list))
#进行源过滤
new_install_list,new_upgrade_list,adjust_pkgs = self._make_fiter_origin([cache[pkg] for pkg in new_install_list + new_upgrade_list],False)
self.upgrade_meta.adjust_pkgs.extend(adjust_pkgs)
#在总升级列表中移除这些包
for pkg in new_upgrade_list:
pkgs_upgrade.remove(pkg)
downgrade_pkg,adjust_pkgs = self._make_downgrade(cache,downgrade_raw)
self.upgrade_meta.adjust_pkgs.extend(adjust_pkgs)
new_upgrade_list.extend(downgrade_pkg)
#单包的优先级最高 从组中剔除此包
for pkg in self.upgrade_meta.single_pkgs:
if pkg in new_install_list:
new_install_list.remove(pkg)
if is_openkylin == True:
install_list,upgrade_list = pkgs_install,pkgs_upgrade
else:
install_list,upgrade_list = self._make_groups_pkgs(cache,data,pkgs_upgrade)
#判断当前是否可升级或者新装的包
if len(new_install_list) == 0 and len(new_upgrade_list) == 0:
if len(install_list) == 0 and len(upgrade_list) == 0:
continue
#3、生成升级的包列表JSON
upgrade_pkgs_json = self._make_pkg_info_json(cache,new_upgrade_list)
upgrade_pkgs_json = self._make_pkg_info_json(cache,upgrade_list)
#2、生成安装的软件列表
install_pkgs_json = self._make_pkg_info_json(cache,new_install_list)
install_pkgs_json = self._make_pkg_info_json(cache,install_list)
#输出JSON配置文件
self._make_group_output_json(data,data_yaml,upgrade_pkgs_json,install_pkgs_json)
@ -436,11 +447,38 @@ class UpdateList():
#添加到字典维护的升级列表
self.upgrade_meta.upgrade_groups.append(group_name)
self.upgrade_meta.groups_pkgs.update({group_name:{"pkgs_upgrade":new_upgrade_list,"pkgs_install":new_install_list}})
logging.info("Group(%s) upgrade:%d install:%d",group_name,len(new_upgrade_list),len(new_install_list))
self.upgrade_meta.groups_pkgs.update({group_name:{"pkgs_upgrade":upgrade_list,"pkgs_install":install_list}})
logging.info("Group(%s) upgrade:%d install:%d",group_name,len(upgrade_list),len(install_list))
else:
pass
def _make_openkylin_output_json(self,upgrade_pkgs_json,install_pkgs_json):
groups_base_info = {}
output_json = {}
#FIXME: 确定输出文件的文件名 以及放置位置
output_config_name = self.OUTPUT_CONFIG_PATH + "kylin-update-desktop-system.json"
#4、添加一些基础信息
groups_base_info.update({"package":"kylin-update-desktop-system"})
groups_base_info.update({"new_version":"33797.0001"})
groups_base_info.update({"name":{"zh_CN": "系统更新","en_US": "Kylin OS"}})
groups_base_info.update({"description":{"zh_CN": "Openkylin-系统更新包","en_US": "Openkylin-System Update Package"}})
groups_base_info.update({"icon":" "})
#添加读yaml文件
groups_base_info.update({"changelog":"Openkylin-系统更新包\n"})
#5、添加升级的内容
output_json.update(groups_base_info)
output_json.update({"upgrade_list":upgrade_pkgs_json})
output_json.update({"install_list":install_pkgs_json})
#6 产生JSON文件
with open(output_config_name, 'w', encoding='utf-8') as f:
json.dump(output_json, f, ensure_ascii=False, indent=4)
logging.info("Generate Jsonfile(%s) to complete... ",output_config_name)
def _rate_application_for_package(self, application, pkg):
score = 0
desktop_file = os.path.basename(application.get_filename())
@ -540,16 +578,22 @@ class UpdateList():
#6、保存单包版本号
self.upgrade_meta.versoin_pkgs['single_upgrade'].update({pkg_cache.name:getattr(pkg_cache.installed, "version", '')})
def update(self,cache):
def update_kylin(self,cache,important_data,is_openkylin = False):
pkgs_install = []
pkgs_upgrade = []
#查找所有可升级的包
for pkg in cache:
if pkg.is_upgradable and pkg.is_installed:
pkgs_upgrade.append(pkg)
if is_openkylin == True:
pkgs_install,pkgs_upgrade = self._make_distupgrade(cache)
else:
for pkg in cache:
if pkg.is_upgradable and pkg.is_installed:
pkgs_upgrade.append(pkg.name)
logging.info("System all upgradeable packages:upgrade:%d ",len(pkgs_upgrade))
group_important_list,self.upgrade_meta.single_pkgs = self._read_important_list(cache,pkgs_upgrade)
group_important_list,self.upgrade_meta.single_pkgs = self._make_important_list(cache,pkgs_upgrade,important_data)
#清空输出的目录
self._empty_output_dir()
@ -563,7 +607,7 @@ class UpdateList():
self._make_single_upgrade(cache,self.upgrade_meta.single_pkgs)
#分组的包的JSON
self._make_groups_upgrade(cache,group_important_list,[pkg.name for pkg in pkgs_upgrade])
self._make_groups_upgrade(cache,group_important_list,is_openkylin,pkgs_install,pkgs_upgrade)
self._make_autoupgrade_config(cache,self.upgrade_meta,self.upgrade_meta.adjust_pkgs)
@ -571,3 +615,21 @@ class UpdateList():
return
def _make_distupgrade(self,cache):
pkgs_upgrade = []
pkgs_install = []
if cache.get_changes():
cache.clear()
cache._depcache.upgrade(True)
#查找所有可升级的包
for pkg in cache:
try:
if pkg.marked_install:
pkgs_install.append(pkg.name)
elif pkg.marked_upgrade:
pkgs_upgrade.append(pkg.name)
except KeyError:
pass
return pkgs_install,pkgs_upgrade

View File

@ -198,7 +198,8 @@ class UpdateManager():
#检查优先自我升级
self._check_self_upgrade(self.cache)
self.update_list.update(self.cache)
self.update_list.update_kylin(self.cache,self.install_mode.get_important_data(),self.install_mode.is_openkylin_desktop())
if self.cache != None and self.cache.get_changes():
self.cache.clear()
@ -237,9 +238,8 @@ class UpdateManager():
def _check_self_upgrade(self,cache):
need_upgrade = False
self_upgrade = []
with open(UpdateList.IMPORTANT_LIST_PATH, 'r') as f:
data = f.read()
important_list = data.split()
important_list = self.install_mode.get_important_data()
for pkg_name in [self.BACKEND_PKG_NAME,self.APTD_PKG_NAME,self.FRONTEND_PKG_NAME]:
if pkg_name in cache:
@ -956,14 +956,15 @@ class UpdateSafeManager():
class UpdateInstallMode():
OPENKYLIN_DISTTRIBUTOR = "Openkylin"
KYLIN_DISTTRIBUTOR = "Kylin"
SYSTEM_UPDATE_GROUPS = "kylin-update-desktop-system"
DIR_MRDIA = "/media/"
MOUNT_SQUASHFS_PATH = "/media/kylin/kylin-test-upgrade/upgrade-pool/"
IMPORTANT_LIST_PATH = '/var/lib/kylin-software-properties/template/important.list'
def __init__(self,parent):
self.parent = parent
self.is_disc = False
self.is_mounted = False
self.dist = get_dist()
if self.shutdown_mode() == True:
@ -975,7 +976,8 @@ class UpdateInstallMode():
self.inhibit_lock = None
def is_openkylin_desktop(self):
return self.dist == self.OPENKYLIN_DISTTRIBUTOR
# return self.dist == self.OPENKYLIN_DISTTRIBUTOR
return True
def check_network(self):
if self.parent.options.no_check_network is False and self.is_disc == False:
@ -984,13 +986,23 @@ class UpdateInstallMode():
return False
def update_important(self):
if self.parent.options.no_update_source is False:
if self.parent.options.no_update_source is False and self.is_openkylin_desktop() == False:
return True
else:
return False
def get_important_data(self):
important_list = []
if self.is_openkylin_desktop() == False:
with open(self.IMPORTANT_LIST_PATH, 'r') as f:
data = f.read()
important_list = data.split()
else:
important_list = [self.SYSTEM_UPDATE_GROUPS,self.parent.BACKEND_PKG_NAME,self.parent.APTD_PKG_NAME,self.parent.FRONTEND_PKG_NAME]
return important_list
def check_filter(self):
if self.parent.options.close_filter == False and self.is_disc == False:
if self.parent.options.close_filter == False and self.is_disc == False and self.is_openkylin_desktop() == False:
return True
else:
return False