Merge branch 'backend_manual' into 'backend_uu'
Backend manual See merge request kylin-desktop/update-manager-group/kylin-system-updater!433
This commit is contained in:
commit
e5966358b5
|
@ -237,26 +237,44 @@ class UpdateList():
|
|||
def _make_autoupgrade_config(self,cache,upgrade_data,_adjust_pkgs):
|
||||
try:
|
||||
pkgs_install,pkgs_upgrade = self._make_pkgs_list(cache,upgrade_data.groups_pkgs,upgrade_data.upgrade_groups,upgrade_data.single_pkgs)
|
||||
|
||||
split_adjust_pkgs = [i.split("=")[0] for i in _adjust_pkgs]
|
||||
|
||||
pkgs_upgrade_str = ''
|
||||
pkgs_list = pkgs_upgrade + pkgs_install
|
||||
if pkgs_list:
|
||||
for pkg_str in pkgs_list:
|
||||
|
||||
#记录源过滤后调整的版本
|
||||
if pkg_str in split_adjust_pkgs:
|
||||
pkg_str = _adjust_pkgs[split_adjust_pkgs.index(pkg_str)]
|
||||
else:
|
||||
ver = getattr(cache[pkg_str].candidate, "version", '')
|
||||
pkg_str = pkg_str + "=" + ver
|
||||
pkgs_upgrade_str += (pkg_str + ',')
|
||||
output_config_name = self.OUTPUT_CONFIG_PATH + 'auto-upgrade-list.json'
|
||||
output_json = {}
|
||||
install_info = {}
|
||||
for pkg in pkgs_install:
|
||||
pkg_cache = cache[pkg]
|
||||
pkgs_json = {}
|
||||
pkgs_json.update({"cur_version":getattr(pkg_cache.installed, "version", '')})
|
||||
|
||||
pkgs_upgrade_str=pkgs_upgrade_str[:-1]
|
||||
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", '')})
|
||||
install_info.update({pkg:pkgs_json})
|
||||
|
||||
self.parent.configs.setValue("AutoUpgrade","upgradelist",pkgs_upgrade_str,True)
|
||||
logging.info("Generate AutoUpgrade Configfile to Complete and Upgradable Number:%d...",len(pkgs_list))
|
||||
upgrade_json = {}
|
||||
for pkg in pkgs_upgrade:
|
||||
pkg_cache = cache[pkg]
|
||||
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", '')})
|
||||
|
||||
upgrade_json.update({pkg:pkgs_json})
|
||||
|
||||
output_json.update({"upgrade_list":upgrade_json})
|
||||
output_json.update({"install_list":install_info})
|
||||
|
||||
#产生JSON文件
|
||||
with open(output_config_name, 'w', encoding='utf-8') as f:
|
||||
json.dump(output_json, f, ensure_ascii=False, indent=4)
|
||||
logging.info("Generate AutoUpgrade Configfile to Complete and Jsonfile(%s) to complete... ",output_config_name)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@ class UpgradeConfig(SafeConfigParser):
|
|||
self.read(self.config_files)
|
||||
logging.info("Initialize Upgrade ConfigFile(%s) to success",str(self.config_files))
|
||||
|
||||
def optionxform(self, optionstr):
|
||||
return optionstr
|
||||
|
||||
def reReadConfigFiles(self):
|
||||
self.read(self.config_files)
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ import struct
|
|||
# 禁止关机锁文件路径
|
||||
FILELOCK_PATH = "/tmp/lock/"
|
||||
SHUTDOWN_BLOCK_FILELOCK = "kylin-update.lock"
|
||||
pidfile = None
|
||||
inhibit_lock = None
|
||||
VERIFY_SO = "libkylin_signtool.so"
|
||||
|
||||
class ExecutionTime(object):
|
||||
|
@ -662,62 +662,40 @@ def get_package_label(pkg):
|
|||
|
||||
#安装时禁止关机 进行加锁
|
||||
def LockedPreventShutdown():
|
||||
global pidfile
|
||||
|
||||
#不为空是表示以及被锁
|
||||
if pidfile != None:
|
||||
logging.error("pidfile file disc not is None,Has been locked...")
|
||||
return False
|
||||
|
||||
if not os.path.exists(FILELOCK_PATH):
|
||||
#不存在创建
|
||||
logging.info("File(%s) is not exists and will be create",FILELOCK_PATH)
|
||||
os.makedirs(FILELOCK_PATH)
|
||||
else:
|
||||
#当目录存在时进行删除 不删除进行创建文件的话会报错
|
||||
# file cannot be locked.[Errno 11] Resource temporarily unavailable
|
||||
# 资源被占用报错
|
||||
shutil.rmtree(FILELOCK_PATH)
|
||||
logging.info("File(%s) is exists and will be delete and create",FILELOCK_PATH)
|
||||
os.makedirs(FILELOCK_PATH)
|
||||
|
||||
global inhibit_lock
|
||||
"""
|
||||
Send a dbus signal to logind to not suspend the system, it will be
|
||||
released when the return value drops out of scope
|
||||
"""
|
||||
try:
|
||||
pidfile = open(os.path.join(FILELOCK_PATH, SHUTDOWN_BLOCK_FILELOCK), "w+")
|
||||
fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
from gi.repository import Gio, GLib
|
||||
connection = Gio.bus_get_sync(Gio.BusType.SYSTEM)
|
||||
|
||||
var, fdlist = connection.call_with_unix_fd_list_sync(
|
||||
'org.freedesktop.login1', '/org/freedesktop/login1',
|
||||
'org.freedesktop.login1.Manager', 'Inhibit',
|
||||
GLib.Variant('(ssss)',
|
||||
('shutdown',
|
||||
'Kylin System Updater', 'Installing Packages',
|
||||
'block')),
|
||||
None, 0, -1, None, None)
|
||||
inhibit_lock = Gio.UnixInputStream(fd=fdlist.steal_fds()[var[0]])
|
||||
logging.info("Shutdown Has been locked...")
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error("file cannot be locked." + str(e))
|
||||
pidfile.close()
|
||||
pidfile = None
|
||||
return False
|
||||
logging.error(e)
|
||||
|
||||
#解锁禁止关机
|
||||
def unLockedEnableShutdown():
|
||||
global pidfile
|
||||
#未加锁退出
|
||||
if not pidfile:
|
||||
logging.info("Not locked and Quitting ...")
|
||||
return False
|
||||
global inhibit_lock
|
||||
try:
|
||||
fcntl.flock(pidfile, fcntl.LOCK_UN)
|
||||
logging.info("Shutdown Has been unlocked...")
|
||||
pidfile.close()
|
||||
pidfile = None
|
||||
|
||||
# Fix 修复权限问题 当普通用户无法使用 所以直接删除目录
|
||||
if os.path.exists(FILELOCK_PATH):
|
||||
shutil.rmtree(FILELOCK_PATH)
|
||||
logging.info('Emptying the lockPath(%s) is complete...',FILELOCK_PATH)
|
||||
if inhibit_lock != None:
|
||||
inhibit_lock.close()
|
||||
logging.info("Shutdown Has been unlocked...")
|
||||
inhibit_lock == None
|
||||
else:
|
||||
logging.info("Emptying the lockPath(%s) is Failed...",FILELOCK_PATH)
|
||||
|
||||
return True
|
||||
logging.info("Not locked and Quitting ...")
|
||||
except Exception as e:
|
||||
logging.error("unlock failed." + str(e))
|
||||
pidfile.close()
|
||||
pidfile = None
|
||||
return False
|
||||
|
||||
# 查看uu进程是否需要kill
|
||||
def kill_process(path):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# UpdateManager.py
|
||||
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
|
||||
from email.header import Header
|
||||
import os
|
||||
import subprocess
|
||||
from apt import Cache
|
||||
|
@ -41,45 +42,64 @@ class UpdateManager():
|
|||
RETRY_LIMIT_NUM = 2
|
||||
|
||||
def __init__(self,options):
|
||||
try:
|
||||
self.options = options
|
||||
self.cache = None
|
||||
self.update_list = None
|
||||
#表示后端的状态 注意:这个状态很重要 用不好整个后端代码就会卡住
|
||||
self.now_working = InstallBackend.ACTION_DEFUALT_STATUS
|
||||
self.config_path = self.check_config_patch()
|
||||
#建立dbus
|
||||
self.dbusController = self._setup_dbus()
|
||||
self.options = options
|
||||
self.cache = None
|
||||
self.update_list = None
|
||||
#表示后端的状态 注意:这个状态很重要 用不好整个后端代码就会卡住
|
||||
self.now_working = InstallBackend.ACTION_DEFUALT_STATUS
|
||||
self.config_path = self.check_config_patch()
|
||||
#建立dbus
|
||||
self.dbusController = self._setup_dbus()
|
||||
|
||||
#配置文件
|
||||
self.configs = UpgradeConfig("/var/lib/kylin-system-updater/")
|
||||
self.uuconfigs = UpgradeConfig(datadir = "/var/lib/unattended-upgrades/", name = "unattended-upgrades-policy.conf")
|
||||
#配置文件
|
||||
self.configs = UpgradeConfig("/var/lib/kylin-system-updater/")
|
||||
self.uuconfigs = UpgradeConfig(datadir = "/var/lib/unattended-upgrades/", name = "unattended-upgrades-policy.conf")
|
||||
|
||||
#连接数据库
|
||||
self.sqlite3_server = Sqlite3Server(self)
|
||||
#连接数据库
|
||||
self.sqlite3_server = Sqlite3Server(self)
|
||||
|
||||
#是否重启apt
|
||||
self.init_config_aptdeamon = False
|
||||
#是否重启apt
|
||||
self.init_config_aptdeamon = False
|
||||
|
||||
#数据采集器
|
||||
self.collector = UpdateMsgCollector(self)
|
||||
#数据采集器
|
||||
self.collector = UpdateMsgCollector(self)
|
||||
|
||||
#后台aptdaemon的语言环境
|
||||
self.aptdaemonLang = os.environ["LANGUAGE"]
|
||||
|
||||
#失败后重启进行安装的限制次数 目前在自适应升级上面使用
|
||||
self.retry_limit = self.RETRY_LIMIT_NUM
|
||||
|
||||
#光盘源
|
||||
self.source_info = UpdateSourceInfo()
|
||||
#后台aptdaemon的语言环境
|
||||
self.aptdaemonLang = os.environ["LANGUAGE"]
|
||||
|
||||
#失败后重启进行安装的限制次数 目前在自适应升级上面使用
|
||||
self.retry_limit = self.RETRY_LIMIT_NUM
|
||||
|
||||
#光盘源
|
||||
self.source_info = UpdateSourceInfo()
|
||||
|
||||
self.update_essential = UpdateEssentialItem(self)
|
||||
|
||||
self.install_mode = UpdateInstallMode(self)
|
||||
self.update_essential = UpdateEssentialItem(self)
|
||||
|
||||
self.install_mode = UpdateInstallMode(self)
|
||||
|
||||
self.refresh_cache()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
self.apt_p2p_config = AptP2pConfigManager()
|
||||
#加载Cache
|
||||
self.refresh_cache()
|
||||
self._reload_options_config()
|
||||
|
||||
def _reload_options_config(self):
|
||||
#添加默认保留旧配置
|
||||
apt_pkg.config["DPkg::Options::"] = "--force-confold"
|
||||
options_new = list(set(apt_pkg.config.value_list("DPkg::Options")))
|
||||
for option in ("--force-confnew","--force-confdef"):
|
||||
if option in options_new:
|
||||
options_new.remove(option)
|
||||
#清除所有配置重新加载
|
||||
apt_pkg.config.clear("DPkg::Options")
|
||||
for option in options_new:
|
||||
apt_pkg.config["DPkg::Options::"] = option
|
||||
#去除安装推荐和建议的软件包
|
||||
if apt_pkg.config.find_b("APT::Install-Recommends",False) == True:
|
||||
apt_pkg.config.clear("APT::Install-Recommends")
|
||||
if apt_pkg.config.find_b("APT::Install-Suggests",False) == True:
|
||||
apt_pkg.config.clear("APT::Install-Suggests")
|
||||
|
||||
apt_pkg.init_system()
|
||||
|
||||
def check_config_patch(self):
|
||||
NOW_UPDATE_CONFIG = '/usr/share/kylin-update-desktop-config/config/'
|
||||
|
@ -835,6 +855,27 @@ class UpdateSourceInfo():
|
|||
self.is_disc = False
|
||||
return
|
||||
|
||||
class AptP2pConfigManager():
|
||||
APT_P2P_FILE = "/etc/apt-p2p/apt-p2p.conf"
|
||||
HEADER_DSC = "apt-p2p config(/etc/apt-p2p/apt-p2p.conf) is not exists..."
|
||||
def __init__(self):
|
||||
if os.path.exists(self.APT_P2P_FILE):
|
||||
self.p2pConfigs = UpgradeConfig(datadir = "/etc/apt-p2p/", name = "apt-p2p.conf")
|
||||
else:
|
||||
self.p2pConfigs = None
|
||||
|
||||
def get_bootstrap(self):
|
||||
if self.p2pConfigs == None:
|
||||
return self.HEADER_DSC
|
||||
|
||||
return self.p2pConfigs.getWithDefault("apt_p2p_Khashmir", "BOOTSTRAP", "Failed")
|
||||
|
||||
def set_bootstrap(self,value):
|
||||
if self.p2pConfigs == None:
|
||||
return self.HEADER_DSC
|
||||
self.p2pConfigs.setValue("apt_p2p_Khashmir","BOOTSTRAP",str(value))
|
||||
|
||||
|
||||
class UpdateInstallMode():
|
||||
def __init__(self,parent):
|
||||
self.parent = parent
|
||||
|
|
|
@ -1004,6 +1004,8 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
if iface == UPDATER_DBUS_INTERFACE:
|
||||
if name == "ShutdownInstall":
|
||||
self.parent.configs.setValue("InstallMode","shutdown_install",str(bool(value)))
|
||||
elif name == "P2pBootstrap":
|
||||
self.parent.apt_p2p_config.set_bootstrap(str(value))
|
||||
else:
|
||||
raise dbus.exceptions.DBusException("Unknown or read only "
|
||||
"property: %s" % name)
|
||||
|
@ -1016,6 +1018,9 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
if iface == UPDATER_DBUS_INTERFACE:
|
||||
return {
|
||||
"ShutdownInstall": dbus.Boolean(
|
||||
self.parent.configs.getWithDefault("InstallMode", "shutdown_install", False))}
|
||||
self.parent.configs.getWithDefault("InstallMode", "shutdown_install", False)),
|
||||
|
||||
"P2pBootstrap": dbus.String(self.parent.apt_p2p_config.get_bootstrap())
|
||||
}
|
||||
else:
|
||||
return {}
|
|
@ -410,7 +410,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
logging.info("Config file conflict oldconf = %s , newconf = %s...",str(old),str(new))
|
||||
logging.info("Default To Replace Old Configfile...")
|
||||
#默认替换旧的配置文件
|
||||
transaction.resolve_config_file_conflict(old, "replace")
|
||||
transaction.resolve_config_file_conflict(old, "keep")
|
||||
# transaction.resolve_config_file_conflict(old, "keep")
|
||||
|
||||
#增加记录当产生错误的时候 详细信息
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
[AutoUpgrade]
|
||||
upgradelist =
|
||||
|
||||
[SystemStatus]
|
||||
abnormal_reboot = False
|
||||
close_source_filter = False
|
||||
|
|
|
@ -85,15 +85,18 @@ if __name__ == "__main__":
|
|||
|
||||
logging.info('kylin-system-updater(lang:%s) starting ...',os.environ["LANGUAGE"])
|
||||
|
||||
app = UpdateManager(options)
|
||||
try:
|
||||
app = UpdateManager(options)
|
||||
|
||||
#当出现安装过程中异常的重启时 开机直接进行修复操作
|
||||
if app.configs.getWithDefault("ConfigPkgStatus", "check_frontend_pkg", False) == True:
|
||||
app.configs.setValue("ConfigPkgStatus","check_frontend_pkg",str(False),True)
|
||||
app.check_frontend_pkg()
|
||||
#当出现安装过程中异常的重启时 开机直接进行修复操作
|
||||
if app.configs.getWithDefault("ConfigPkgStatus", "check_frontend_pkg", False) == True:
|
||||
app.configs.setValue("ConfigPkgStatus","check_frontend_pkg",str(False),True)
|
||||
app.check_frontend_pkg()
|
||||
|
||||
#当出现安装过程中异常的重启时 开机直接进行修复操作
|
||||
if app.configs.getWithDefault("SystemStatus", "abnormal_reboot", False) == True:
|
||||
app.start_update()
|
||||
#当出现安装过程中异常的重启时 开机直接进行修复操作
|
||||
if app.configs.getWithDefault("SystemStatus", "abnormal_reboot", False) == True:
|
||||
app.start_update()
|
||||
|
||||
app.run()
|
||||
app.run()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
|
@ -1,11 +1,27 @@
|
|||
kylin-system-updater (2.0.4.1kord) v101; urgency=medium
|
||||
kylin-system-updater (2.0.4.3) v101; urgency=medium
|
||||
|
||||
* BUG: 无
|
||||
* BUG: # 118021 【在线更新】中文环境下,安装和卸载应用时弹出授权界面,提示内容未汉化
|
||||
# 118026 【在线更新】英文环境下,安装和卸载应用时弹出授权界面,提示内容表述方式不一致
|
||||
# 122799 【在线更新】配置项中的源地址错误时,客户端重启后打开设置更新,提示后台程序未启动
|
||||
# 119435 【更新升级】配置组包json格式错误时,system-updater、自动更新服务均不能启动,更新功能失效,需要增加异常处理机制
|
||||
# 121781 【在线更新】中文环境下,静默更新完成后,右上角及侧边栏通知未汉化
|
||||
* 需求号: 无
|
||||
* 其他改动说明: 可选更新通知机制优化
|
||||
* 其他改动说明: 无
|
||||
* 其他改动影响域:系统更新
|
||||
|
||||
-- luoxueyi <luoxueyi@kylinos.cn> Tue, 10 May 2022 19:13:31 +0800
|
||||
-- luoxueyi <luoxueyi@kylinos.cn> Mon, 06 Jun 2022 11:15:22 +0800
|
||||
|
||||
kylin-system-updater (2.0.4.2kord) v101; urgency=medium
|
||||
|
||||
* BUG: # 118021 【在线更新】中文环境下,安装和卸载应用时弹出授权界面,提示内容未汉化
|
||||
# 118026 【在线更新】英文环境下,安装和卸载应用时弹出授权界面,提示内容表述方式不一致
|
||||
# 122799 【在线更新】配置项中的源地址错误时,客户端重启后打开设置更新,提示后台程序未启动
|
||||
# 119435 【更新升级】配置组包json格式错误时,system-updater、自动更新服务均不能启动,更新功能失效,需要增加异常处理机制
|
||||
* 需求号: 无
|
||||
* 其他改动说明: 无
|
||||
* 其他改动影响域:系统更新
|
||||
|
||||
-- luoxueyi <luoxueyi@kylinos.cn> Thu, 02 Jun 2022 17:36:29 +0800
|
||||
|
||||
kylin-system-updater (2.0.3.2kord) v101; urgency=medium
|
||||
|
||||
|
|
Loading…
Reference in New Issue