对部分日志进行整理
This commit is contained in:
parent
1e5ff1d8bd
commit
6f5a03b4a1
|
@ -38,6 +38,7 @@ import glob
|
||||||
import json
|
import json
|
||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
|
|
||||||
|
import shutil
|
||||||
from .utils import humanize_size
|
from .utils import humanize_size
|
||||||
from UpdateManager.Core import utils
|
from UpdateManager.Core import utils
|
||||||
from UpdateManager.Core import filter
|
from UpdateManager.Core import filter
|
||||||
|
@ -224,7 +225,7 @@ class UpdateList():
|
||||||
self.GROUPS_JSON_PKG = 'kylin-update-desktop-config'
|
self.GROUPS_JSON_PKG = 'kylin-update-desktop-config'
|
||||||
|
|
||||||
self.INPUT_CONFIG_PATH = '/usr/share/kylin-update-desktop-config/data'
|
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
|
# a stable machine uniq id
|
||||||
try:
|
try:
|
||||||
|
@ -501,6 +502,7 @@ class UpdateList():
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
output_json = {}
|
output_json = {}
|
||||||
|
#FIXME: 确定输出文件的文件名 以及放置位置
|
||||||
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
|
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
|
||||||
|
|
||||||
install_pkgs_list = data['install_list']
|
install_pkgs_list = data['install_list']
|
||||||
|
@ -577,6 +579,17 @@ class UpdateList():
|
||||||
output_json.update({"hold_list":hold_pkgs_list})
|
output_json.update({"hold_list":hold_pkgs_list})
|
||||||
output_json.update({"remove_list":remove_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文件
|
#6 产生JSON文件
|
||||||
with open(output_config_name, 'w', encoding='utf-8') as f:
|
with open(output_config_name, 'w', encoding='utf-8') as f:
|
||||||
json.dump(output_json, f, ensure_ascii=False, indent=4)
|
json.dump(output_json, f, ensure_ascii=False, indent=4)
|
||||||
|
@ -610,23 +623,26 @@ class UpdateList():
|
||||||
return False
|
return False
|
||||||
logging.info("Find all upgradeable packages finished...")
|
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: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
|
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
|
||||||
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
|
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
|
||||||
# eventloop_callback)
|
# 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: %s"%" ".join([i.name for i in allowed_origin_upgrade_pkgs]))
|
||||||
# logging.info("allowed_origin_upgrade_pkgs count: %s", len(allowed_origin_upgrade_pkgs))
|
# logging.info("allowed_origin_upgrade_pkgs count: %s", len(allowed_origin_upgrade_pkgs))
|
||||||
# pass
|
|
||||||
|
|
||||||
# #whitelist
|
#whitelist
|
||||||
# whitelist_filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(allowed_origin_upgrade_pkgs)
|
|
||||||
# logging.info("whitelist_filter_upgrade_pkgs: %s"%" ".join([i.name for i in whitelist_filter_upgrade_pkgs]))
|
# 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))
|
# logging.info("whitelist_filter_upgrade_pkgs count: %s", len(whitelist_filter_upgrade_pkgs))
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class UpdateListFilterCache(apt.Cache):
|
||||||
self.checkInCache()
|
self.checkInCache()
|
||||||
|
|
||||||
def checkInCache(self):
|
def checkInCache(self):
|
||||||
print("start Check in cache")
|
logging.info("start Check in cache")
|
||||||
tmplist = []
|
tmplist = []
|
||||||
cache = apt.Cache()
|
cache = apt.Cache()
|
||||||
for i in self.upgradeList:
|
for i in self.upgradeList:
|
||||||
|
@ -111,7 +111,7 @@ class UpdateListFilterCache(apt.Cache):
|
||||||
cache[i]
|
cache[i]
|
||||||
tmplist.append(i)
|
tmplist.append(i)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("not found pkg: ", str(e))
|
# print("not found pkg: ", str(e))
|
||||||
pass
|
pass
|
||||||
self.upgradeList = tmplist
|
self.upgradeList = tmplist
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class UpdateListFilterCache(apt.Cache):
|
||||||
with open(ImportantListPath, 'r') as f:
|
with open(ImportantListPath, 'r') as f:
|
||||||
text = f.read()
|
text = f.read()
|
||||||
importantList = text.split()
|
importantList = text.split()
|
||||||
print("importantList: %s"%importantList)
|
logging.info("importantList: %s",importantList)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if not importantList:
|
if not importantList:
|
||||||
|
@ -136,7 +136,7 @@ class UpdateListFilterCache(apt.Cache):
|
||||||
for i in files:
|
for i in files:
|
||||||
if ".json" in i:
|
if ".json" in i:
|
||||||
jsonfiles.append(i.split('.')[0])
|
jsonfiles.append(i.split('.')[0])
|
||||||
logging.info("all files: %s", jsonfiles)
|
# logging.info("all files: %s", jsonfiles)
|
||||||
|
|
||||||
# 找到importantlist中对应的json文件
|
# 找到importantlist中对应的json文件
|
||||||
for i in importantList:
|
for i in importantList:
|
||||||
|
@ -155,14 +155,13 @@ class UpdateListFilterCache(apt.Cache):
|
||||||
pkgdict = f.read()
|
pkgdict = f.read()
|
||||||
jsonfile = json.loads(pkgdict)
|
jsonfile = json.loads(pkgdict)
|
||||||
tmplist = jsonfile['install_list']
|
tmplist = jsonfile['install_list']
|
||||||
print("\ntmplist: ", tmplist)
|
# print("\ntmplist: ", tmplist)
|
||||||
for j in tmplist:
|
for j in tmplist:
|
||||||
if j not in self.upgradeList:
|
if j not in self.upgradeList:
|
||||||
self.upgradeList.append(j)
|
self.upgradeList.append(j)
|
||||||
f.close()
|
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'])
|
# print("jsonfile silent_install_list: ", jsonfile['silent_install_list'])
|
||||||
|
|
||||||
|
|
|
@ -104,11 +104,7 @@ class UpdateManager():
|
||||||
|
|
||||||
#进行更新的操作
|
#进行更新的操作
|
||||||
def start_update(self):
|
def start_update(self):
|
||||||
#不进行update 的操作
|
|
||||||
if self.options.no_update:
|
|
||||||
self.start_available()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.is_updating = True
|
self.is_updating = True
|
||||||
update_backend = get_backend(self, InstallBackend.ACTION_UPDATE)
|
update_backend = get_backend(self, InstallBackend.ACTION_UPDATE)
|
||||||
update_backend.start()
|
update_backend.start()
|
||||||
|
@ -193,18 +189,23 @@ class UpdateManager():
|
||||||
self.start_install_alone(pkgs_install = [self.update_list.GROUPS_JSON_PKG])
|
self.start_install_alone(pkgs_install = [self.update_list.GROUPS_JSON_PKG])
|
||||||
#直接退出
|
#直接退出
|
||||||
return
|
return
|
||||||
#FIXME: 错误处理未做
|
#FIXME: 错误处理未做 报告到控制面板
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning("groups JSON ConfigPkgs(%s) install failed...",self.update_list.GROUPS_JSON_PKG)
|
logging.warning("groups JSON ConfigPkgs(%s) install failed...",self.update_list.GROUPS_JSON_PKG)
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
|
_success = False
|
||||||
|
|
||||||
#判断目录是JSON配置文件夹是否缺失 缺失后进行修复 卸载重新安装步骤
|
#判断目录是JSON配置文件夹是否缺失 缺失后进行修复 卸载重新安装步骤
|
||||||
if not os.path.exists(self.update_list.INPUT_CONFIG_PATH):
|
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 进行判断是否安装未安装重新安装
|
#将软件包卸载 之后进行重新安装here --> purge --> start_available 进行判断是否安装未安装重新安装
|
||||||
self.start_install_alone(pkgs_purge = [self.update_list.GROUPS_JSON_PKG])
|
self.start_install_alone(pkgs_purge = [self.update_list.GROUPS_JSON_PKG])
|
||||||
#直接退出
|
#直接退出
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#FIXME: 待开发功能 根据监测存在配置文件 不存在进行重新安装包 再检测还是未存在的话 就判断此次没有可升级的
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_success = self.update_list.update(self.cache)
|
_success = self.update_list.update(self.cache)
|
||||||
except SystemError as e:
|
except SystemError as e:
|
||||||
|
|
|
@ -19,13 +19,11 @@ class InstallBackend():
|
||||||
def __init__(self, window_main, action):
|
def __init__(self, window_main, action):
|
||||||
self.window_main = window_main
|
self.window_main = window_main
|
||||||
self.action = action
|
self.action = action
|
||||||
# self.sleep_cookie = None
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
os.environ["APT_LISTCHANGES_FRONTEND"] = "none"
|
os.environ["APT_LISTCHANGES_FRONTEND"] = "none"
|
||||||
|
|
||||||
# Do not suspend during the update process
|
#FIXME: 在下载升级的能抑制系统关闭或者睡眠 参考ubuntu此部分代码
|
||||||
# self.sleep_cookie = inhibit_sleep()
|
|
||||||
|
|
||||||
if self.action == self.ACTION_INSTALL:
|
if self.action == self.ACTION_INSTALL:
|
||||||
# Get the packages which should be installed and update
|
# Get the packages which should be installed and update
|
||||||
|
@ -74,7 +72,7 @@ class InstallBackend():
|
||||||
"""Run a update to refresh the package list"""
|
"""Run a update to refresh the package list"""
|
||||||
raise NotImplementedError
|
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 """
|
"""Commit the cache changes """
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -94,13 +92,11 @@ class InstallBackend():
|
||||||
else:
|
else:
|
||||||
self.window_main.is_updating = False
|
self.window_main.is_updating = False
|
||||||
if error_string or error_desc:
|
if error_string or error_desc:
|
||||||
#失败的话直接退出
|
|
||||||
logging.warning(error_string + error_desc)
|
logging.warning(error_string + error_desc)
|
||||||
elif success == False:
|
elif success:
|
||||||
#FIXME: 出现错误时候的处理
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.window_main.start_available()
|
self.window_main.start_available()
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# try aptdaemon
|
# try aptdaemon
|
||||||
|
|
|
@ -36,6 +36,10 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
logging.info('kylin-update-manager starting ...')
|
logging.info('kylin-update-manager starting ...')
|
||||||
app = UpdateManager(options)
|
app = UpdateManager(options)
|
||||||
|
|
||||||
app.start_update()
|
app.start_update()
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue