增加安装器日志上传

This commit is contained in:
luoxueyi 2022-08-24 16:17:15 +08:00
parent 3b2dcf6024
commit 22d65ef011
6 changed files with 69 additions and 19 deletions

View File

@ -75,6 +75,7 @@ class UpdateMsgCollector():
action_map = {
ACTION_CHECK_RESOLVER:enums.MONIT_DEPRESOLUT,
ACTION_INSTALL:enums.MONIT_INSTALL,
ACTION_INSTALL_DEB:enums.MONIT_INSTALLDEB,
10:enums.MONIT_FINISH,
"finish-update":enums.MONIT_FINISH,
"finish-install":enums.MONIT_FINISH
@ -85,7 +86,8 @@ class UpdateMsgCollector():
# InstallBackend.ACTION_CHECK_RESOLVER:"Downloading",
ACTION_INSTALL:"Installing",
# InstallBackend.ACTION_CHECK_RESOLVER:"UpgradeFinish",
10:"Background-upgrade",
ACTION_INSTALL_DEB:"InstallerInfo",
10:"Background-Upgrade",
"finish-update":"UpdateInfos",
"finish-install":"InstallInfos"
}
@ -116,6 +118,8 @@ class UpdateMsgCollector():
# 获取将要上传的数据,获取东八区时间
UploadMessage['createTimeStamp'] = get_east_8_time()
try:
if "packageName" in dict_message.keys():
dict_message.pop("packageName")
for key in dict_message.keys():
UploadMessage[key] = dict_message[key]
if local_uuid != '':
@ -200,9 +204,14 @@ class UpdateMsgCollector():
json_file = json.dumps(tmp_dict.copy())
self.UpdateMsg(self.messageType_map.get(action, ""), json_file, self.uuid)
else:
tmp_dict.update(self.UpdateInfos)
json_file = json.dumps(tmp_dict.copy())
self.UpdateMsg(self.messageType_map.get(action, ""), json_file, self.uuid)
if action == self.ACTION_INSTALL_DEB:
tmp_dict.update({"step":self.action_map.get(action, "")})
json_file = json.dumps(tmp_dict.copy())
self.UpdateMsg(self.messageType_map.get(action, ""), json_file, self.uuid)
else:
tmp_dict.update(self.UpdateInfos)
json_file = json.dumps(tmp_dict.copy())
self.UpdateMsg(self.messageType_map.get(action, ""), json_file, self.uuid)
except Exception as e:
logging.error(e)
tmp_dict.clear()

View File

@ -483,6 +483,8 @@ class UpdateManager():
header = ''
desc = ''
absolute_path, debname = os.path.split(deb_path)
self.deb_obj = {}
UpdateMsg = {}
try:
if not os.path.isfile(deb_path):
logging.info("No such file or directory: %s.",deb_path)
@ -496,14 +498,29 @@ class UpdateManager():
if not status:
self.dbusController.InstalldebFinished(False,error_string,'')
return
self.deb_obj.update({"debname":str(debname)})
self.deb_obj.update({"old_version":""})
self.deb_obj.update({"source":str(caller)})
UpdateMsg.update({"appname":str(self.deb_obj.get("debname","None").split("_")[0])})
UpdateMsg.update({"source":str(self.deb_obj.get("source","kylin-system-updater"))})
UpdateMsg.update({"new_version":str(self.deb_obj.get("debname","None").split("_")[1])})
deb_cache, ins, _isinstall = self._suit_install_mode(deb_path)
if self._is_broken > 0 or not self.cacheSatisfy or self._need_downgrade:
# 走 dpkg 安装流程说明本地apt环境已经损坏,or dep not satisfied or need downgrade
dep_satisfy, header, desc = self._deb_install(deb_cache, deb_path, _check_local_dep, ins)
if dep_satisfy:
if dep_satisfy:
self.dbusController.InstalldebFinished(True, header, desc)
UpdateMsg.update({"status":"success"})
UpdateMsg.update({"errorCode":" "})
else:
self.dbusController.InstalldebFinished(False, header, desc)
UpdateMsg.update({"status":"failed"})
UpdateMsg.update({"errorCode":str(header+" "+desc)})
#dpkg发送数据
if self.configs_uncover.getWithDefault("SystemStatus", "upload_installer_log", False) == True:
UpdateMsg.update({"old_version":str(self.deb_obj.get("old_version","None"))})
self.collector.Upgrade_Process_Msg(InstallBackend.ACTION_INSTALL_DEB, UpdateMsg.copy())
self.deb_obj = {}
else:
# apt 安装流程
dep_satisfy, header, desc = self._attempt_depends(deb_cache, deb_path, _check_local_dep,_auto_satisfy, ins)
@ -514,10 +531,18 @@ class UpdateManager():
self.dbusController.InstalldebFinished(False, header, desc)
except UpdateBaseError as excep:
self.dbusController.InstalldebFinished(False,excep.header,excep.desc)
UpdateMsg.update({"old_version":str(self.deb_obj.get("old_version","None"))})
UpdateMsg.update({"errorCode":str(excep.header+" "+excep.desc)})
UpdateMsg.update({"status":"failed"})
self.collector.Upgrade_Process_Msg(InstallBackend.ACTION_INSTALL_DEB, UpdateMsg.copy())
except Exception as e:
logging.info(str(e))
traceback.print_exc()
self.dbusController.InstalldebFinished(False, str(e), desc)
UpdateMsg.update({"old_version":str(self.deb_obj.get("old_version","None"))})
UpdateMsg.update({"errorCode":str(e)})
UpdateMsg.update({"status":"failed"})
self.collector.Upgrade_Process_Msg(InstallBackend.ACTION_INSTALL_DEB, UpdateMsg.copy())
#进行删除的操作
def start_purge_pkgs(self,pkgs_list):
@ -627,7 +652,6 @@ class UpdateManager():
satisfy_list = []
noSatisfyList = []
depends_count = 0
_status = False
error_string = ''
header = ''
desc = ''
@ -666,7 +690,6 @@ class UpdateManager():
satisfy_list.append(debfile)
if depends_count < len(noSatisfyList):
#本地依赖不满足
_status = False
error_string = str(debname.split("_")[0])+_("dependency is not satisfied")+", ".join(noSatisfyList)
logging.error(error_string)
header = error_string
@ -687,7 +710,6 @@ class UpdateManager():
return False, str(e), desc
return True, header, desc
elif not _check_local_dep:
_status = False
if _install:
error_string = str(debname.split("_")[0])+_("dependency is not satisfied")+":".join(_install)
logging.error(error_string)
@ -713,18 +735,21 @@ class UpdateManager():
absolute_path, debname = os.path.split(deb_path)
# 检查本地破损
try:
logging.info("Install deb package, open cache")
deb_cache = Cache()
logging.info("Install deb package, check broken")
broken_count = deb_cache._depcache.broken_count
deb = DebPackage(deb_path, deb_cache)
deb.check(allow_downgrade=True)
logging.info("Install package, required changes")
logging.info("Install deb package, required changes")
(install, remove, unauth) = deb.required_changes # need in cach
if broken_count > 0:
self._is_broken = True
else :
self._is_broken = False
if debname.split("_")[0] in deb_cache:
pkg = deb_cache[debname.split("_")[0]]
if pkg.is_installed:
self.deb_obj.update({"old_version":str(pkg.installed.version)})
except apt_pkg.Error as e:
logging.error(str(e))
if "E:read" in str(e):

View File

@ -1079,7 +1079,6 @@ class UpdateManagerDbusControllerUtils(dbus.service.Object):
self.parent.collector.UpdateMsg(messageType, uploadMessage)
except Exception as e:
logging.error(str(e))
# 检查更新
@dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature='as', out_signature='as', sender_keyword='sender')

View File

@ -228,11 +228,10 @@ class InstallBackendAptdaemon(InstallBackend):
self._action_done(self.ACTION_INSTALL_DEB,
authorized=False, success=False,
error_string='', error_desc='')
except Exception:
pass
# self._action_done(self.ACTION_INSTALL_DEB,
# is_cancelled=False, success=False,
# error_string='', error_desc='')
except Exception as e:
self._action_done(self.ACTION_INSTALL_DEB,
is_cancelled=False, success=False,
error_string=str(e), error_desc='')
# raise
@inline_callbacks

View File

@ -784,13 +784,30 @@ class InstallBackend():
error_string = _("Package validation failed and installation was rejected.")
error_desc = ''
self.window_main.dbusController.InstalldebFinished(success,error_string,error_desc)
UpdateMsg = {}
if success:
status = 'success'
UpdateMsg.update({"errorCode":" "})
else:
status = 'failed'
UpdateMsg.update({"errorCode":str(error_string+" "+error_desc)})
#apt发送数据
if self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_installer_log", False) == True:
UpdateMsg.update({"appname":str(self.window_main.deb_obj.get("debname","None").split("_")[0])})
UpdateMsg.update({"source":str(self.window_main.deb_obj.get("source","kylin-system-updater"))})
UpdateMsg.update({"status":str(status)})
UpdateMsg.update({"new_version":str(self.window_main.deb_obj.get("debname","None").split("_")[1])})
UpdateMsg.update({"old_version":str(self.window_main.deb_obj.get("old_version","None"))})
self.window_main.collector.Upgrade_Process_Msg(self.action, UpdateMsg.copy())
self.window_main.deb_obj = {}
elif action == self.ACTION_BACKGROUND_UPGRADE:
self._release_install_lock()
UpdateMsg = {}
if success:
status = 'Success'
status = 'success'
else:
status = 'Failed'
status = 'failed'
self.window_main.collector.Generate_Msg(self.window_main.collector.background_list, self.action_mode)
for bl in self.window_main.collector.background_list:
pkg = self.window_main.collector.cache[bl]
@ -804,6 +821,7 @@ class InstallBackend():
# self.window_main.collector.Upgrade_Process_Msg(self.action, UpdateMsg.copy())
self.window_main.dbusController.UpdateInstallFinished(success,self.now_upgrade.upgrade_content,error_string,error_desc)
def _start_install_lock(self, caller='Kylin System Updater'):
self.window_main.configs_uncover.setValue("SystemStatus","abnormal_reboot",str(True))

View File

@ -83,7 +83,7 @@ if __name__ == "__main__":
signal.signal(signal.SIGINT,signal_handler_term)
if options.debug:
logging.basicConfig(format=FORMAT,level=logging.INFO,datefmt='%m-%d,%H:%M:%S')
logging.basicConfig(format=FORMAT,level=logging.DEBUG,datefmt='%m-%d,%H:%M:%S')
else:
logging.basicConfig(format=FORMAT,level=logging.DEBUG,datefmt='%m-%d,%H:%M:%S',filename = logfile(),filemode = 'a')