捕获异常

This commit is contained in:
luoxueyi 2022-10-28 13:53:30 +08:00
parent 9b06d4aa81
commit acd1c8ac47
1 changed files with 205 additions and 202 deletions

View File

@ -220,218 +220,221 @@ class Sqlite3Server(object):
status_cn = '失败'
changeLog = ""
# 判断更新方式
if mode == InstallBackend.MODE_INSTALL_PARTIAL: # 部分更新
pkg_adj = ""
# 判断更新包为单包或更新组
if pkg_group:
# 更新组
pkgname = pkg_group.pop(0)
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(pkgname)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkgname:
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(pkgversion)
#移除step-two标记
self._removal_of_marker()
try:
# 判断更新方式
if mode == InstallBackend.MODE_INSTALL_PARTIAL: # 部分更新
pkg_adj = ""
# 判断更新包为单包或更新组
if pkg_group:
# 更新组
pkgname = pkg_group.pop(0)
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(pkgname)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkgname:
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(pkgversion)
#移除step-two标记
self._removal_of_marker()
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(pkgname) + ".yaml")
with open(file_path, "r") as stream:
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(pkgname) + ".yaml")
with open(file_path, "r") as stream:
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
elif pkg_list:
changeLog = " "
# 单包更新 # 获取单包数据插入数据库
pkgname = pkg_list.pop(0)
for adj in adjust_pkg:
if pkgname in adj:
# 该部分升级的单包为调整版本,与候选版本不一致
pkg_adj = adj
break
if pkg_adj: # 有调整的情况
try:
pkg = self.window_main.cache[pkg_adj.split("=")[0]]
for ver in pkg.versions:
if ver.version == pkg_adj.split("=")[1]:
pkg_inst_ver = ver
break
pkgname = pkg_adj.split("=")[0]
pkgversion = str(pkg_inst_ver.source_version)
pkgdescription = str(pkg_inst_ver.description)
except Exception as e:
logging.error(_("%s could not be detected in the source because the source was changed or for other reasons."), \
str(pkgname))
logging.error(str(e))
else: # 没有调整的情况
try:
pkg = self.window_main.cache[pkgname]
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
except Exception as e:
logging.error(str(e))
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(pkgname))
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
try:
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 发送插入数据库成功的信号local_upgrade_list
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 这里也需要, 发送插入数据库成功的信号
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
elif mode == InstallBackend.MODE_INSTALL_ALL: # 系统全部升级
# # insert signal deb first
for i in pkg_list:
changeLog = ""
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
elif pkg_list:
changeLog = " "
# 单包更新 # 获取单包数据插入数据库
pkgname = pkg_list.pop(0)
for adj in adjust_pkg:
if pkgname in adj:
# 该部分升级的单包为调整版本,与候选版本不一致
pkg_adj = adj
break
if pkg_adj: # 有调整的情况
try:
pkg = self.window_main.cache[pkg_adj.split("=")[0]]
for ver in pkg.versions:
if ver.version == pkg_adj.split("=")[1]:
pkg_inst_ver = ver
break
pkgname = pkg_adj.split("=")[0]
pkgversion = str(pkg_inst_ver.source_version)
pkgdescription = str(pkg_inst_ver.description)
pkg = self.window_main.cache[i]
except Exception as e:
logging.error(_("%s could not be detected in the source because the source was changed or for other reasons."), \
str(pkgname))
logging.error(str(e))
else: # 没有调整的情况
str(i))
continue
if not pkg:
continue
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkg.name)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkg.name)})
if pkg.name in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkg.name])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
try:
pkg = self.window_main.cache[pkgname]
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(i))
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
logging.error(str(e))
#更新信息update-infos
UpdateInfos.update({"appname":str(pkgname)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkgname)})
if pkgname in self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['single_upgrade'][pkgname])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(pkgname))
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
try:
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 发送插入数据库成功的信号local_upgrade_list
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
# FIXME: 这里也需要, 发送插入数据库成功的信号
self.window_main.dbusController.UpdateSqlitSingle(pkgname, timestr)
elif mode == InstallBackend.MODE_INSTALL_ALL: # 系统全部升级
# # insert signal deb first
for i in pkg_list:
changeLog = ""
try:
pkg = self.window_main.cache[i]
except Exception as e:
logging.error(_("%s could not be detected in the source because the source was changed or for other reasons."), \
str(i))
continue
if not pkg:
continue
pkgversion = str(pkg.candidate.version)
pkgdescription = str(pkg.candidate.raw_description)
#更新信息update-infos
UpdateInfos.update({"appname":str(pkg.name)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(pkg.name)})
if pkg.name in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][pkg.name])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
try:
# 软件商店获取中文名
appname_cn = self.get_cn_appname(str(i))
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkg.name, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
# insert group deb next
for i in pkg_group:
# FIXME: 获取组信息
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(i)
#更新信息update-infos
UpdateInfos.update({"appname":str(i)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(i)})
if i in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][i])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
json_file = json.dumps(InstallInfos.copy())
try:
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
except:
pass
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=i, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(i) + ".yaml")
with open(file_path, "r") as stream:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=pkg.name, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
# insert group deb next
for i in pkg_group:
# FIXME: 获取组信息
pkgversion,pkgdescription,appname_cn = self.GetGroupmsg(i)
#更新信息update-infos
UpdateInfos.update({"appname":str(i)})
UpdateInfos.update({"source":"Kylin System Updater"})
UpdateInfos.update({"status":status})
UpdateInfos.update({"errorCode":str(error_string+" "+error_desc)})
self.window_main.collector.Upgrade_Process_Msg("finish-update", UpdateInfos.copy())
#安装信息install-infos
InstallInfos.update({"appname":str(i)})
if i in self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'].keys():
InstallInfos.update({"old_version":str(self.window_main.update_list.upgrade_meta.versoin_pkgs['groups_upgrade'][i])})
else:
InstallInfos.update({"old_version":'UnKnown'})
InstallInfos.update({"new_version":str(pkgversion)})
InstallInfos.update({"status":status})
InstallInfos.update({"errorCode":str(error_string+" "+error_desc)})
json_file = json.dumps(InstallInfos.copy())
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
try:
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkg_group:
self.window_main.collector.UpdateMsg("InstallInfos", json_file)
except:
pass
#FIXME: 临时方案 PHP
PHPSeverSend(_appname=i, _appversion=pkgversion, _statue=status, _errorcode="10000100", _errorstring=errstr)
file_path = os.path.join(get_config_patch(), str(i) + ".yaml")
with open(file_path, "r") as stream:
try:
data_yaml = yaml.safe_load(stream)
changeLog = data_yaml['changelog']
except yaml.YAMLError as exc:
logging.error(exc)
try:
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 数据库文件被删除或者新增字段导致需要重新初始化数据库再写入
except Exception as e:
self.init_sqlit()
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn, status_cn, changeLog)
self.window_main.dbusController.UpdateSqlitSingle(str(i), timestr)
# 系统升级完成 ..判断版本号
if status == "success" and "kylin-update-desktop-system" in pkg_group:
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(str(pkgversion))
#移除step-two标记
self._removal_of_marker()
elif mode == InstallBackend.MODE_INSTALL_SYSTEM: # 全盘升级
self.insert_into_updateinfo(_("Upgrade System"), "", "This is a complete system upgrade, equivalent to the implementation of apt dist-upgrade", timestr, status, "1", errstr, str("全盘升级"), status_cn, " ")
self.window_main.dbusController.UpdateSqlitSingle("Upgrade System", timestr)
# 全盘更新完成 ..判断版本号
if status == "success":
# 更新版本号
if "=" in str(pkgversion):
pkgversion = str(pkgversion).split('=')[-1]
logging.info("Complete system upgrade, refresh system version ...")
self._refresh_system_version(str(pkgversion))
self._refresh_system_version(pseudo_version=True)
#移除step-two标记
self._removal_of_marker()
elif mode == InstallBackend.MODE_INSTALL_SYSTEM: # 全盘升级
self.insert_into_updateinfo(_("Upgrade System"), "", "This is a complete system upgrade, equivalent to the implementation of apt dist-upgrade", timestr, status, "1", errstr, str("全盘升级"), status_cn, " ")
self.window_main.dbusController.UpdateSqlitSingle("Upgrade System", timestr)
# 全盘更新完成 ..判断版本号
if status == "success":
# 更新版本号
self._refresh_system_version(pseudo_version=True)
#移除step-two标记
self._removal_of_marker()
else:
logging.warning("Cache is None.")
else:
logging.warning("Cache is None.")
except Exception as e:
logging.error("record update error: %s.",str(e))
# 获取group信息
def GetGroupmsg(self, appname):