Merge branch 'backend_manual' of gitlab2.kylin.com:kylin-desktop/update-manager-group/kylin-system-updater into backend_manual
This commit is contained in:
commit
d9ae0ceaa9
|
@ -4,11 +4,13 @@ from math import log10
|
|||
import os
|
||||
import re
|
||||
import json
|
||||
import yaml
|
||||
import shutil
|
||||
import sqlite3
|
||||
import logging
|
||||
import datetime
|
||||
from gettext import gettext as _
|
||||
from sys import exec_prefix
|
||||
from SystemUpdater.Core.DataAcquisition import PHPSeverSend
|
||||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
|
||||
|
@ -151,9 +153,9 @@ class Sqlite3Server(object):
|
|||
logging.info(_("Inserting data into the database... "))
|
||||
try:
|
||||
self.cursor.execute(
|
||||
"insert into updateinfos (appname, version, description, date, status, keyword, errorcode, appname_cn) values(?,"
|
||||
"?,?,?,?,?,?,?)",
|
||||
(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]))
|
||||
"insert into updateinfos (appname, version, description, date, status, keyword, errorcode, appname_cn, status_cn, changelog) values(?,"
|
||||
"?,?,?,?,?,?,?,?,?)",
|
||||
(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]))
|
||||
self.connect.commit()
|
||||
except Exception as e:
|
||||
logging.error("Insert error: %s.", str(e))
|
||||
|
@ -163,6 +165,7 @@ class Sqlite3Server(object):
|
|||
def insert_info(self, mode, pkg_list=[], pkg_group=[], adjust_pkg=[], success = False, error_string = '', error_desc = ''):
|
||||
errstr = error_string + " " + error_desc
|
||||
status = " "
|
||||
status_cn = " "
|
||||
appname_cn = ""
|
||||
UpdateInfos = {}
|
||||
InstallInfos = {}
|
||||
|
@ -178,8 +181,11 @@ class Sqlite3Server(object):
|
|||
|
||||
if success:
|
||||
status = 'success'
|
||||
status_cn = '成功'
|
||||
else:
|
||||
status = 'failed'
|
||||
status_cn = '失败'
|
||||
changeLog = ""
|
||||
# 判断更新方式
|
||||
if mode == InstallBackend.MODE_INSTALL_PARTIAL: # 部分更新
|
||||
pkg_adj = ""
|
||||
|
@ -213,7 +219,14 @@ class Sqlite3Server(object):
|
|||
|
||||
#FIXME: 临时方案 PHP
|
||||
PHPSeverSend(_send_log = self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_upgrade_log", False), _appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100")
|
||||
with open(self.window_main.config_path + str(pkgname) + ".yaml", "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:
|
||||
|
@ -259,23 +272,23 @@ class Sqlite3Server(object):
|
|||
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))
|
||||
# 软件商店获取中文名insert_into_displayr(pkgname))
|
||||
#FIXME: 临时方案 PHP
|
||||
PHPSeverSend(_send_log = self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_upgrade_log", False), _appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100")
|
||||
try:
|
||||
self.insert_into_updateinfo(pkgname, pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn)
|
||||
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)
|
||||
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:
|
||||
|
@ -307,12 +320,12 @@ class Sqlite3Server(object):
|
|||
try:
|
||||
# 软件商店获取中文名
|
||||
appname_cn = self.get_cn_appname(str(i))
|
||||
self.insert_into_updateinfo(str(i), pkgversion, pkgdescription, timestr, status, "1", errstr, appname_cn)
|
||||
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)
|
||||
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(_send_log = self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_upgrade_log", False), _appname=pkg.name, _appversion=pkgversion, _statue=status, _errorcode="10000100")
|
||||
|
@ -338,13 +351,20 @@ class Sqlite3Server(object):
|
|||
self.window_main.collector.Upgrade_Process_Msg("finish-install", InstallInfos.copy())
|
||||
#FIXME: 临时方案 PHP
|
||||
PHPSeverSend(_send_log = self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_upgrade_log", False), _appname=i, _appversion=pkgversion, _statue=status, _errorcode="10000100")
|
||||
|
||||
with open(self.window_main.config_path + str(i) + ".yaml", "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)
|
||||
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)
|
||||
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)
|
||||
|
||||
# 系统升级完成 ..判断版本号
|
||||
|
@ -353,7 +373,7 @@ class Sqlite3Server(object):
|
|||
self._refresh_system_version(str(pkgversion))
|
||||
|
||||
elif mode == InstallBackend.MODE_INSTALL_SYSTEM: # 全盘升级
|
||||
self.insert_into_updateinfo(str("Upgrade System"), "", "This is a complete system upgrade, equivalent to the implementation of apt dist-upgrade", timestr, status, "1", errstr, str("全盘升级"))
|
||||
self.insert_into_updateinfo(str("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(str("Upgrade System"), timestr)
|
||||
# 全盘更新完成 ..判断版本号
|
||||
if status == "success":
|
||||
|
@ -523,9 +543,52 @@ class Sqlite3Server(object):
|
|||
logging.error(_("Failed to initialize the database: %s"), str(e))
|
||||
return ''
|
||||
|
||||
|
||||
def insert_upgrade_history(self, args, caller):
|
||||
caller_list = ['kylin-unattended-upgrade', "d-feet", "root"]
|
||||
_in_list = False
|
||||
for cl in caller_list:
|
||||
if caller in cl:
|
||||
_in_list = True
|
||||
if _in_list == False:
|
||||
logging.warning("Caller \" %s \": Operation without permission...", caller)
|
||||
return False
|
||||
# {"appname":GLib.Variant("s", "kylin-system-updater"), "version":GLib.Variant("s", "0.0")}
|
||||
# "description":GLib.Variant("s", "Update Manager for Kylin"), "date":GLib.Variant("s", "2022-07-27 15:23:51")
|
||||
# "status":GLib.Variant("s", "failed"), "keyword":GLib.Variant("s", "1")
|
||||
# "errorcode":GLib.Variant("s", "System upgrade is complete. "), "appname_cn":GLib.Variant("s", "音乐")
|
||||
upgrade_info = {}
|
||||
try:
|
||||
for it in args:
|
||||
upgrade_info[str(it)] = str(args[str(it)])
|
||||
logging.info("upgrade_info: %s", upgrade_info)
|
||||
|
||||
if "appname" in upgrade_info.keys() and "version" in upgrade_info.keys() \
|
||||
and "description" in upgrade_info.keys() \
|
||||
and "date" in upgrade_info.keys() \
|
||||
and "status" in upgrade_info.keys() \
|
||||
and "keyword" in upgrade_info.keys() \
|
||||
and "errorcode" in upgrade_info.keys() \
|
||||
and "appname_cn" in upgrade_info.keys() \
|
||||
and "status_cn" in upgrade_info.keys() \
|
||||
and "changelog" in upgrade_info.keys():
|
||||
self.insert_into_updateinfo( upgrade_info["appname"], upgrade_info["version"], \
|
||||
upgrade_info["description"], \
|
||||
upgrade_info["date"], \
|
||||
upgrade_info["status"], \
|
||||
upgrade_info["keyword"], \
|
||||
upgrade_info["errorcode"], \
|
||||
upgrade_info["appname_cn"], \
|
||||
upgrade_info["status_cn"], \
|
||||
upgrade_info["changelog"] )
|
||||
else:
|
||||
logging.warning("Incomplete field.")
|
||||
return False
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return False
|
||||
return True
|
||||
|
||||
def listtojsonstr(lists):
|
||||
import json
|
||||
jsonfile = json.dumps(lists)
|
||||
return jsonfile
|
||||
return jsonfile
|
||||
|
|
|
@ -269,8 +269,37 @@ class UpdateList():
|
|||
|
||||
upgrade_json.update({pkg:pkgs_json})
|
||||
|
||||
group_json = {}
|
||||
for ug in self.upgrade_meta.groups_pkgs:
|
||||
pkgs_json = {}
|
||||
with open(self.parent.config_path + str(ug) + ".yaml", "r") as stream:
|
||||
try:
|
||||
data_yaml = yaml.safe_load(stream)
|
||||
pkgs_json.update({"cur_version":""})
|
||||
pkgs_json.update({"new_version":data_yaml["version"]})
|
||||
pkgs_json.update({"changelog":data_yaml["changelog"]})
|
||||
except yaml.YAMLError as exc:
|
||||
logging.error(exc)
|
||||
group_json.update({ug:pkgs_json})
|
||||
|
||||
single_json = {}
|
||||
for us in self.upgrade_meta.single_pkgs:
|
||||
pkg_cache = cache[us]
|
||||
pkgs_json = {}
|
||||
pkgs_json.update({"cur_version":getattr(pkg_cache.installed, "version", '')})
|
||||
|
||||
if pkg in split_adjust_pkgs:
|
||||
version_adjust = _adjust_pkgs[split_adjust_pkgs.index(pkg)].split("=")[1]
|
||||
pkgs_json.update({"new_version":version_adjust})
|
||||
else:
|
||||
pkgs_json.update({"new_version":getattr(pkg_cache.candidate, "version", '')})
|
||||
pkgs_json.update({"changelog":""})
|
||||
single_json.update({us:pkgs_json})
|
||||
|
||||
output_json.update({"upgrade_list":upgrade_json})
|
||||
output_json.update({"install_list":install_info})
|
||||
output_json.update({"group_json":group_json})
|
||||
output_json.update({"single_json":single_json})
|
||||
|
||||
#产生JSON文件
|
||||
with open(output_config_name, 'w', encoding='utf-8') as f:
|
||||
|
|
|
@ -679,6 +679,34 @@ def kill_process(path):
|
|||
return False
|
||||
return True
|
||||
|
||||
def whether_to_quit_uu():
|
||||
osreleasedict={}
|
||||
try:
|
||||
with open('/etc/os-release') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
ls = line.strip().split('=',1)
|
||||
osreleasedict.update({ls[0]:ls[1].strip('"')})
|
||||
except Exception as e:
|
||||
pass
|
||||
if 'SUB_PROJECT_CODENAME' not in osreleasedict.keys():
|
||||
osreleasedict.update({'SUB_PROJECT_CODENAME':''})
|
||||
if 'PROJECT_CODENAME' in osreleasedict:
|
||||
if osreleasedict['PROJECT_CODENAME']=='V10SP1-edu':
|
||||
if 'SUB_PROJECT_CODENAME' in osreleasedict:
|
||||
if osreleasedict['SUB_PROJECT_CODENAME']=='mavis':
|
||||
return False
|
||||
else:
|
||||
logging.info("SUB_PROJECT_CODENAME != mavis")
|
||||
else:
|
||||
logging.info("no SUB_PROJECT_CODENAME")
|
||||
else:
|
||||
logging.info("PROJECT_CODENAME != V10SP1-edu")
|
||||
else:
|
||||
logging.info("no PROJECT_CODENAME")
|
||||
|
||||
return True
|
||||
|
||||
def get_proc_from_dbus_name(dbus_name, bus=None):
|
||||
"""Return a deferred that gets the id of process owning the given
|
||||
system D-Bus name.
|
||||
|
|
|
@ -30,7 +30,7 @@ from .Core.DataAcquisition import UpdateMsgCollector
|
|||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
from SystemUpdater.Core.utils import kill_process
|
||||
from SystemUpdater.Core.DpkgInstallProgress import LogInstallProgress
|
||||
from SystemUpdater.Core.utils import deb_verify,PolicyKit_Authority,get_proc_from_dbus_name
|
||||
from SystemUpdater.Core.utils import deb_verify,PolicyKit_Authority,get_proc_from_dbus_name,whether_to_quit_uu
|
||||
|
||||
class UpdateManager():
|
||||
BACKEND_PKG_NAME = 'kylin-system-updater'
|
||||
|
@ -194,7 +194,8 @@ class UpdateManager():
|
|||
resolver_backend.start(upgrade_content)
|
||||
else:
|
||||
if not_resolver == True:
|
||||
kill_process(self.RUN_UNATTENDED_UPGRADE)
|
||||
if whether_to_quit_uu():
|
||||
kill_process(self.RUN_UNATTENDED_UPGRADE)
|
||||
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL,upgrade_mode)
|
||||
install_backend.start(upgrade_content)
|
||||
else:
|
||||
|
|
|
@ -1070,6 +1070,22 @@ class UpdateManagerDbusControllerUtils(dbus.service.Object):
|
|||
logging.info("All silent upgrade: %s.",pkglist)
|
||||
return pkglist
|
||||
|
||||
# 提供插入更新历史的接口
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature='a{sv}', out_signature='b', sender_keyword='sender')
|
||||
def InsertUpgradeHistory(self, arg = {}, sender=None):
|
||||
try:
|
||||
# {"appname":GLib.Variant("s", "kylin-system-updater"), "version":GLib.Variant("s", "string value")}
|
||||
# "description":GLib.Variant("s", "Update Manager for Kylin"), "date":GLib.Variant("s", "2022-07-27 15:23:51")
|
||||
# "status":GLib.Variant("s", "failed"), "keyword":GLib.Variant("s", "1")
|
||||
# "errorcode":GLib.Variant("s", "System upgrade is complete. "), "appname_cn":GLib.Variant("s", "音乐")
|
||||
sender_name = get_proc_from_dbus_name(sender)
|
||||
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' Call InsertUpgradeHistory from %s.', sender_name)
|
||||
if not self.parent.sqlite3_server.insert_upgrade_history(arg, sender_name) :
|
||||
return False
|
||||
except Exception as e:
|
||||
logging.error("InsertUpgradeHistory Failed: %s" % str(e), exc_info=True)
|
||||
return False
|
||||
return True
|
||||
|
||||
WRITABLE_PROPERTIES = ()
|
||||
|
||||
|
|
|
@ -18,4 +18,6 @@ if [ -f /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py ];th
|
|||
# /usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -m
|
||||
/usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -u appname_cn=
|
||||
/usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -t=tid_search
|
||||
/usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -u status_cn=
|
||||
/usr/share/kylin-system-updater/SystemUpdater/Core/DataMigration.py -u changelog=
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue