对部分日志进行整理

This commit is contained in:
wangsong 2021-09-08 15:32:29 +08:00
parent 1e5ff1d8bd
commit 6f5a03b4a1
5 changed files with 47 additions and 31 deletions

View File

@ -38,6 +38,7 @@ import glob
import json
from gi.repository import Gio
import shutil
from .utils import humanize_size
from UpdateManager.Core import utils
from UpdateManager.Core import filter
@ -224,7 +225,7 @@ class UpdateList():
self.GROUPS_JSON_PKG = 'kylin-update-desktop-config'
self.INPUT_CONFIG_PATH = '/usr/share/kylin-update-desktop-config/data'
self.OUTPUT_CONFIG_PATH = '/home/kylin/wangsong/outconfig'
self.OUTPUT_CONFIG_PATH = os.getenv('HOME') + '/.config' +'/update_manager_config'
# a stable machine uniq id
try:
@ -501,6 +502,7 @@ class UpdateList():
data = json.load(f)
output_json = {}
#FIXME: 确定输出文件的文件名 以及放置位置
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
install_pkgs_list = data['install_list']
@ -577,6 +579,17 @@ class UpdateList():
output_json.update({"hold_list":hold_pkgs_list})
output_json.update({"remove_list":remove_pkgs_list})
#判断目录是否存在不存在创建 存在时删除 再创建 清空上次产生的文件 保持最新
#FIXME: 使用直接将目录删除的办法 或者使用清除目录下的文件的方法
try:
if not os.path.exists(self.OUTPUT_CONFIG_PATH):
os.makedirs(self.OUTPUT_CONFIG_PATH)
else:
shutil.rmtree(self.OUTPUT_CONFIG_PATH)
os.makedirs(self.OUTPUT_CONFIG_PATH)
except Exception as e:
logging.warning(e)
#6 产生JSON文件
with open(output_config_name, 'w', encoding='utf-8') as f:
json.dump(output_json, f, ensure_ascii=False, indent=4)
@ -610,23 +623,26 @@ class UpdateList():
return False
logging.info("Find all upgradeable packages finished...")
# self._make_json(cache,self.pkgs_install,self.pkgs_upgrade,self.pkgs_remove)
fu = filter.UpdateListFilterCache()
#源过滤
allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(upgrade_pkgs)
whitelist_filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(allowed_origin_upgrade_pkgs)
pass
self._make_json(cache,self.pkgs_install,self.pkgs_upgrade,self.pkgs_remove)
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
# eventloop_callback)
# fu = filter.UpdateListFilterCache()
# #源过滤
# allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(upgrade_pkgs)
# 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))
# pass
# #whitelist
# whitelist_filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(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))

View File

@ -103,7 +103,7 @@ class UpdateListFilterCache(apt.Cache):
self.checkInCache()
def checkInCache(self):
print("start Check in cache")
logging.info("start Check in cache")
tmplist = []
cache = apt.Cache()
for i in self.upgradeList:
@ -111,7 +111,7 @@ class UpdateListFilterCache(apt.Cache):
cache[i]
tmplist.append(i)
except Exception as e:
print("not found pkg: ", str(e))
# print("not found pkg: ", str(e))
pass
self.upgradeList = tmplist
@ -123,7 +123,7 @@ class UpdateListFilterCache(apt.Cache):
with open(ImportantListPath, 'r') as f:
text = f.read()
importantList = text.split()
print("importantList: %s"%importantList)
logging.info("importantList: %s",importantList)
f.close()
if not importantList:
@ -136,7 +136,7 @@ class UpdateListFilterCache(apt.Cache):
for i in files:
if ".json" in i:
jsonfiles.append(i.split('.')[0])
logging.info("all files: %s", jsonfiles)
# logging.info("all files: %s", jsonfiles)
# 找到importantlist中对应的json文件
for i in importantList:
@ -155,14 +155,13 @@ class UpdateListFilterCache(apt.Cache):
pkgdict = f.read()
jsonfile = json.loads(pkgdict)
tmplist = jsonfile['install_list']
print("\ntmplist: ", tmplist)
# print("\ntmplist: ", tmplist)
for j in tmplist:
if j not in self.upgradeList:
self.upgradeList.append(j)
f.close()
logging.info("self.upgradeList: %s", self.upgradeList)
# logging.info("self.upgradeList: %s", self.upgradeList)
print("\n\n")
#
# print("jsonfile silent_install_list: ", jsonfile['silent_install_list'])

View File

@ -104,11 +104,7 @@ class UpdateManager():
#进行更新的操作
def start_update(self):
#不进行update 的操作
if self.options.no_update:
self.start_available()
return
self.is_updating = True
update_backend = get_backend(self, InstallBackend.ACTION_UPDATE)
update_backend.start()
@ -193,18 +189,23 @@ class UpdateManager():
self.start_install_alone(pkgs_install = [self.update_list.GROUPS_JSON_PKG])
#直接退出
return
#FIXME: 错误处理未做
#FIXME: 错误处理未做 报告到控制面板
except Exception as e:
logging.warning("groups JSON ConfigPkgs(%s) install failed...",self.update_list.GROUPS_JSON_PKG)
logging.error(e)
_success = False
#判断目录是JSON配置文件夹是否缺失 缺失后进行修复 卸载重新安装步骤
if not os.path.exists(self.update_list.INPUT_CONFIG_PATH):
logging.info("groups JSON Config Path(%s) Missing and Trying to fix...",self.update_list.INPUT_CONFIG_PATH)
#将软件包卸载 之后进行重新安装here --> purge --> start_available 进行判断是否安装未安装重新安装
self.start_install_alone(pkgs_purge = [self.update_list.GROUPS_JSON_PKG])
#直接退出
return
#FIXME: 待开发功能 根据监测存在配置文件 不存在进行重新安装包 再检测还是未存在的话 就判断此次没有可升级的
try:
_success = self.update_list.update(self.cache)
except SystemError as e:

View File

@ -19,13 +19,11 @@ class InstallBackend():
def __init__(self, window_main, action):
self.window_main = window_main
self.action = action
# self.sleep_cookie = None
def start(self):
os.environ["APT_LISTCHANGES_FRONTEND"] = "none"
# Do not suspend during the update process
# self.sleep_cookie = inhibit_sleep()
#FIXME: 在下载升级的能抑制系统关闭或者睡眠 参考ubuntu此部分代码
if self.action == self.ACTION_INSTALL:
# Get the packages which should be installed and update
@ -74,7 +72,7 @@ class InstallBackend():
"""Run a update to refresh the package list"""
raise NotImplementedError
def commit(self, pkgs_install, pkgs_upgrade, pkgs_remove,pkgs_reinstall):
def commit(self, pkgs_install, pkgs_upgrade, pkgs_remove,pkgs_purge):
"""Commit the cache changes """
raise NotImplementedError
@ -94,13 +92,11 @@ class InstallBackend():
else:
self.window_main.is_updating = False
if error_string or error_desc:
#失败的话直接退出
logging.warning(error_string + error_desc)
elif success == False:
#FIXME: 出现错误时候的处理
pass
else:
elif success:
self.window_main.start_available()
else:
pass
# try aptdaemon

View File

@ -36,6 +36,10 @@ if __name__ == "__main__":
logging.info('kylin-update-manager starting ...')
app = UpdateManager(options)
app.start_update()
Gtk.main()