安装功能修正
This commit is contained in:
parent
e7b5d400f0
commit
e311e05c43
|
@ -231,7 +231,7 @@ class UpdateList():
|
|||
|
||||
self.important_list = []
|
||||
|
||||
self.output_upgrade_list = []
|
||||
self.output_upgrade_list = {}
|
||||
# a stable machine uniq id
|
||||
try:
|
||||
with open(self.UNIQ_MACHINE_ID_FILE) as f:
|
||||
|
@ -509,88 +509,81 @@ class UpdateList():
|
|||
logging.info("read important list failed becauce: %s",e)
|
||||
return False
|
||||
|
||||
def _make_json(self,cache,pkgs_install = [], pkgs_upgrade = [], pkgs_remove = []):
|
||||
def _make_pkg_info_json(self,cache,pkgs_list):
|
||||
size = 0
|
||||
total_size = 0
|
||||
pkgs_info_json = {}
|
||||
for pkg_name in pkgs_list:
|
||||
try:
|
||||
pkg = cache[pkg_name]
|
||||
|
||||
#如果这个包已经安装则不计算在内
|
||||
if pkg.is_installed:
|
||||
continue
|
||||
|
||||
#获取下载大小
|
||||
size = getattr(pkg.candidate, "size", 0)
|
||||
total_size = total_size + size
|
||||
pkgs_info_json.update({pkg_name:{"size":size}})
|
||||
except Exception as e:
|
||||
pass
|
||||
pkgs_info_json.update({"total_size":humanize_size(total_size)})
|
||||
return pkgs_info_json
|
||||
|
||||
|
||||
def _make_groups_json(self,cache,pkgs_install = [], pkgs_upgrade = [], pkgs_remove = []):
|
||||
try:
|
||||
files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表
|
||||
for file in files:
|
||||
|
||||
upgrade_groups_list = []
|
||||
|
||||
for file in files:
|
||||
#判是否是目录以及是否以JSON结尾
|
||||
if not os.path.isdir(file) and file.endswith('.json'):
|
||||
with open(self.INPUT_CONFIG_PATH+"/"+file,'r') as f:
|
||||
data = json.load(f)
|
||||
package_name = data['package']
|
||||
|
||||
#过滤没有推送的配置文件
|
||||
if not data['package'] in self.important_list:
|
||||
if not package_name in self.important_list:
|
||||
continue
|
||||
|
||||
groups_base_info = {}
|
||||
output_json = {}
|
||||
#FIXME: 确定输出文件的文件名 以及放置位置
|
||||
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
|
||||
|
||||
install_pkgs_list = data['install_list']
|
||||
upgrade_pkgs_list = data['upgrade_list']
|
||||
hold_pkgs_list = data['hold_list']
|
||||
remove_pkgs_list = data['remove_list']
|
||||
|
||||
#1、生成需要升级的包的JSON内容
|
||||
#进行交集 查找两个列表同时存在的
|
||||
upgrade_intersection_pkgs = list(set(pkgs_upgrade) & set(upgrade_pkgs_list))
|
||||
#在总升级列表中移除这些包
|
||||
for pkg in upgrade_intersection_pkgs:
|
||||
pkgs_upgrade.remove(pkg)
|
||||
install_pkgs_list = data['install_list']
|
||||
|
||||
size = 0
|
||||
total_size = 0
|
||||
upgrade_pkgs_json = {}
|
||||
for pkg_name in upgrade_intersection_pkgs:
|
||||
try:
|
||||
pkg = cache[pkg_name]
|
||||
#获取下载大小
|
||||
size = getattr(pkg.candidate, "size", 0)
|
||||
total_size = total_size + size
|
||||
upgrade_pkgs_json.update({pkg_name:{"size":size}})
|
||||
except Exception as e:
|
||||
pass
|
||||
upgrade_pkgs_json.update({"total_size":humanize_size(total_size)})
|
||||
new_install_pkgs_list = []
|
||||
|
||||
|
||||
#2、生成安装的软件列表
|
||||
install_pkgs_json = {}
|
||||
total_size = 0
|
||||
for pkg_name in install_pkgs_list:
|
||||
try:
|
||||
#会存在不在cache的包直接抛出异常
|
||||
pkg = cache[pkg_name]
|
||||
#如果这个包已经安装则不计算在内
|
||||
if pkg.is_installed:
|
||||
continue
|
||||
# 标记为自动安装
|
||||
pkg.mark_auto()
|
||||
|
||||
#获取下载大小
|
||||
size = getattr(pkg.candidate, "size", 0)
|
||||
total_size = total_size + size
|
||||
install_pkgs_json.update({pkg_name:{"size":size}})
|
||||
new_install_pkgs_list.append(pkg_name)
|
||||
except Exception as e:
|
||||
pass
|
||||
install_pkgs_json.update({"total_size":humanize_size(total_size)})
|
||||
|
||||
#3、检索hold_pkgs 将包标记为mark_keep 不进行升级或安装
|
||||
for pkg in hold_pkgs_list:
|
||||
try:
|
||||
pkg = cache[pkg_name]
|
||||
|
||||
#未安装的话直接跳过
|
||||
if not pkg.is_installed:
|
||||
continue
|
||||
# 标记为自动安装
|
||||
pkg.mark_keep()
|
||||
except Exception as e:
|
||||
pass
|
||||
groups_base_info = {}
|
||||
output_json = {}
|
||||
#FIXME: 确定输出文件的文件名 以及放置位置
|
||||
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + package_name + '_output.json'
|
||||
|
||||
#进行交集 升级列表
|
||||
upgrade_intersection_pkgs = list(set(pkgs_upgrade) & set(upgrade_pkgs_list))
|
||||
#在总升级列表中移除这些包
|
||||
for pkg in upgrade_intersection_pkgs:
|
||||
pkgs_upgrade.remove(pkg)
|
||||
|
||||
#3、生成升级的包列表JSON
|
||||
upgrade_pkgs_json = self._make_pkg_info_json(cache,upgrade_intersection_pkgs)
|
||||
|
||||
#2、生成安装的软件列表
|
||||
install_pkgs_json = self._make_pkg_info_json(cache,install_pkgs_list)
|
||||
|
||||
#4、添加一些基础信息
|
||||
groups_base_info.update({"package":data['package']})
|
||||
groups_base_info.update({"package":package_name})
|
||||
groups_base_info.update({"version":data['version']})
|
||||
groups_base_info.update({"name":data['name']})
|
||||
groups_base_info.update({"description":data['description']})
|
||||
|
@ -603,16 +596,17 @@ class UpdateList():
|
|||
output_json.update({"hold_list":hold_pkgs_list})
|
||||
output_json.update({"remove_list":remove_pkgs_list})
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
upgrade_groups_list.append(package_name)
|
||||
#添加到输出升级列表
|
||||
self.output_upgrade_list.append(data['package'])
|
||||
self.output_upgrade_list.update({package_name:{"pkgs_upgrade":upgrade_intersection_pkgs,"pkgs_install":new_install_pkgs_list}})
|
||||
else:
|
||||
pass
|
||||
self.output_upgrade_list.update({"upgrade_groups_list":upgrade_groups_list})
|
||||
except Exception as e:
|
||||
logging.warning("Generate Jsonfile(%s) to failed... ",output_config_name)
|
||||
logging.error(e)
|
||||
|
@ -639,25 +633,17 @@ class UpdateList():
|
|||
logging.error(e)
|
||||
logging.info("Find all upgradeable packages finished...")
|
||||
|
||||
#源过滤 and 白名单过滤
|
||||
#源过滤
|
||||
fu = filter.UpdateListFilterCache()
|
||||
allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade)
|
||||
# filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(allowed_origin_upgrade_pkgs)
|
||||
|
||||
self._make_json(cache,pkgs_upgrade = ([i.name for i in allowed_origin_upgrade_pkgs]))
|
||||
self._make_groups_json(cache,pkgs_upgrade = ([i.name for i in allowed_origin_upgrade_pkgs]))
|
||||
|
||||
#增加需要移除的包列表
|
||||
# self.output_upgrade_list.update({"pkgs_remove":[i.name for i in pkgs_remove]})
|
||||
|
||||
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
|
||||
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
|
||||
# eventloop_callback)
|
||||
|
||||
|
||||
# logging.info("allowed_origin_upgrade_pkgs: %s"%" ".join([i.name for i in allowed_origin_upgrade_pkgs]))
|
||||
# logging.info("allowed_origin_upgrade_pkgs count: %s", len(allowed_origin_upgrade_pkgs))
|
||||
|
||||
#whitelist
|
||||
|
||||
# logging.info("whitelist_filter_upgrade_pkgs: %s"%" ".join([i.name for i in whitelist_filter_upgrade_pkgs]))
|
||||
# logging.info("whitelist_filter_upgrade_pkgs count: %s", len(whitelist_filter_upgrade_pkgs))
|
||||
|
||||
return True
|
|
@ -240,7 +240,7 @@ class UpdateManager():
|
|||
desc = _("important.list list is empty")
|
||||
|
||||
#发送更新升级列表完成的标志
|
||||
self.dbusController.update_finished_signal(_success,self.update_list.output_upgrade_list,header,desc)
|
||||
self.dbusController.update_finished_signal(_success,self.update_list.output_upgrade_list.get('upgrade_groups_list',''),header,desc)
|
||||
|
||||
def _setup_dbus(self):
|
||||
""" this sets up a dbus listener if none is installed already """
|
||||
|
|
|
@ -99,3 +99,4 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
def update_finished_signal(self, success, data,error_string='',error_desc='',):
|
||||
logging.info("emit success = %r , data = %a, error_string = %s , error_desc = %s ",success,data, error_string,error_desc)
|
||||
pass
|
||||
|
||||
|
|
|
@ -28,32 +28,19 @@ class InstallBackend():
|
|||
if self.action == self.ACTION_INSTALL:
|
||||
# Get the packages which should be installed and update
|
||||
pkgs_install = []
|
||||
|
||||
pkgs_upgrade = []
|
||||
pkgs_remove = []
|
||||
pkgs_purge = []
|
||||
|
||||
# upgrade_groups_list = ['kylin-update-desktop-system','dsdsd']
|
||||
upgrade_groups_list = self.window_main.update_list.output_upgrade_list['upgrade_groups_list']
|
||||
try:
|
||||
for group_name in upgrade_groups_list:
|
||||
pkgs_install = self.window_main.update_list.output_upgrade_list.get(group_name,'').get('pkgs_install','')
|
||||
pkgs_upgrade = self.window_main.update_list.output_upgrade_list.get(group_name,'').get('pkgs_upgrade','')
|
||||
|
||||
# Get a fresh cache in case update-manager's is outdated to
|
||||
# skip operations that already took place
|
||||
# fresh_cache = Cache(rootdir=self.window_main.cache.rootdir)
|
||||
# for pkg in self.window_main.cache:
|
||||
# try:
|
||||
# if pkg.marked_install \
|
||||
# and not fresh_cache[pkg.name].is_installed:
|
||||
# pkgname = pkg.name
|
||||
# if pkg.is_auto_installed:
|
||||
# pkgname += "#auto"
|
||||
# pkgs_install.append(pkgname)
|
||||
# elif (pkg.marked_upgrade
|
||||
# and fresh_cache[pkg.name].is_upgradable):
|
||||
# pkgs_upgrade.append(pkg.name)
|
||||
# elif (pkg.marked_delete
|
||||
# and fresh_cache[pkg.name].is_installed):
|
||||
# pkgs_remove.append(pkg.name)
|
||||
# except KeyError:
|
||||
# # pkg missing from fresh_cache can't be modified
|
||||
# pass
|
||||
# pkgs_remove.append(self.window_main.update_list.output_upgrade_list.get(pkgs_remove,''))
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
self.commit(pkgs_install, pkgs_upgrade, pkgs_remove,pkgs_purge)
|
||||
else:
|
||||
|
|
|
@ -39,3 +39,6 @@ if __name__ == "__main__":
|
|||
|
||||
app.start_update()
|
||||
Gtk.main()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue