Merge branch 'backend_manual' of gitlab2.kylin.com:kylin-desktop/update-manager-group/kylin-system-updater into backend_manual

This commit is contained in:
Xueyi Luo 2022-06-13 14:16:06 +08:00
commit 7b2a3ddf6f
11 changed files with 197 additions and 125 deletions

View File

@ -70,8 +70,6 @@ class UpdateList():
def _empty_output_dir(self):
try:
#清空 升级列表
self.parent.configs.setValue("AutoUpgrade","upgradelist",'',True)
if not os.path.exists(self.OUTPUT_CONFIG_PATH):
os.makedirs(self.OUTPUT_CONFIG_PATH)
logging.info('making the ConfigPath(%s) is complete...',self.OUTPUT_CONFIG_PATH)
@ -237,26 +235,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)

View File

@ -7,7 +7,7 @@ __all__ = (
"ERROR_NOT_INIT_PACKAGESINFIO","ERROR_READ_IMPORTANTLIST_FAILED","ERROR_RESOLVER_FAILED","ERROR_NOT_UPGRADE_PACKAGES",
"ERROR_REMOVE_ESSENTIAL_PACKAGES","ERROR_NOT_DISK_SPACE",
"ERROR_UPDATE_KEY_SIGNATURES",
"ERROR_UPDATE_KEY_SIGNATURES","ERROR_UPDATE_NET_AUTHENTICATION","ERROR_UPDATE_NOTREAD_SOURCES",
"get_error_description_from_enum", "get_error_string_from_enum", "get_source_name_from_enum")
@ -18,14 +18,8 @@ _ = gettext.gettext
#更新阶段
ERROR_UPDATE_KEY_SIGNATURES = "The following signatures"
#UPGRADE MONITOR STATUS
MONIT_DETECT = "step-updatedetect"
MONIT_DEPRESOLUT = "step-depresolution"
MONIT_DOWNLOAD = "step-downloading"
MONIT_INSTALL = "step-installing"
MONIT_FINISH = "step-finish"
ERROR_UPDATE_NET_AUTHENTICATION ="does the network require authentication?"
ERROR_UPDATE_NOTREAD_SOURCES = "The list of sources could not be read"
#自己的
ERROR_UPDATE_SOURCE_FAILED = "error-update-source-failed"
@ -39,6 +33,17 @@ ERROR_NOT_UPGRADE_PACKAGES = "error-not-upgrade-packages"
ERROR_REMOVE_ESSENTIAL_PACKAGES = "error-remove-essential-packages"
ERROR_NOT_DISK_SPACE = "error-not-disk-space"
_STRINGS_ERROR = {
ERROR_UPDATE_SOURCE_FAILED: _("Unable to access the source management server"),
ERROR_NETWORK_FAILED: _("Please check your network connection and retry."),
ERROR_NOT_GROUPS_CONFIG: _("Unable to get group configuration package, please contact administrator to solve"),
ERROR_SOFTWARE_INDEX_RROKEN: _("Software index is broken"),
ERROR_NOT_INIT_PACKAGESINFIO: _("Could not initialize the package information"),
ERROR_READ_IMPORTANTLIST_FAILED: _("read important list failed"),
ERROR_RESOLVER_FAILED: _("Could not calculate the upgrade"),
ERROR_NOT_UPGRADE_PACKAGES: _("There is an exception in the update package."),
ERROR_REMOVE_ESSENTIAL_PACKAGES: _("There is an exception in the update package."),
ERROR_NOT_DISK_SPACE: _("Disk space is insufficient, please clean the disk and then upgrade")}
_DESCS_ERROR = {
ERROR_UPDATE_SOURCE_FAILED: _("Check your source management server config"),
@ -57,20 +62,20 @@ _DESCS_ERROR = {
ERROR_RESOLVER_FAILED: _("nothing"),
ERROR_NOT_UPGRADE_PACKAGES: _("This update cannot detect the upgradeable package."),
ERROR_REMOVE_ESSENTIAL_PACKAGES: _("You request the removal of a system-essential package."),
ERROR_NOT_DISK_SPACE: _("test")}
ERROR_NOT_DISK_SPACE: _("test"),
ERROR_UPDATE_KEY_SIGNATURES: _("Check your source public key signature"),
ERROR_UPDATE_NET_AUTHENTICATION: _("Check if your network requires authentication?"),
_STRINGS_ERROR = {
ERROR_UPDATE_SOURCE_FAILED: _("Unable to access the source management server"),
ERROR_NETWORK_FAILED: _("Please check your network connection and retry."),
ERROR_NOT_GROUPS_CONFIG: _("Unable to get group configuration package, please contact administrator to solve"),
ERROR_SOFTWARE_INDEX_RROKEN: _("Software index is broken"),
ERROR_NOT_INIT_PACKAGESINFIO: _("Could not initialize the package information"),
ERROR_READ_IMPORTANTLIST_FAILED: _("read important list failed"),
ERROR_RESOLVER_FAILED: _("Could not calculate the upgrade"),
ERROR_NOT_UPGRADE_PACKAGES: _("There is an exception in the update package."),
ERROR_REMOVE_ESSENTIAL_PACKAGES: _("There is an exception in the update package."),
ERROR_NOT_DISK_SPACE: _("Disk space is insufficient, please clean the disk and then upgrade")}
ERROR_UPDATE_NOTREAD_SOURCES: _("Please check your source list and retry.")
}
#UPGRADE MONITOR STATUS
MONIT_DETECT = "step-updatedetect"
MONIT_DEPRESOLUT = "step-depresolution"
MONIT_DOWNLOAD = "step-downloading"
MONIT_INSTALL = "step-installing"
MONIT_FINISH = "step-finish"
SOURCE_NAME = {
'kylin-installer':_("Kylin Installer"),

View File

@ -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):

View File

@ -77,8 +77,30 @@ class UpdateManager():
self.install_mode = UpdateInstallMode(self)
self.apt_p2p_config = AptP2pConfigManager()
self._reload_options_config()
#加载Cache
self._refresh_cache_only()
self.refresh_cache()
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/'
@ -257,6 +279,17 @@ class UpdateManager():
logging.error(str(e))
raise UpdateBaseError(ERROR_NOT_INIT_PACKAGESINFIO)
def _refresh_cache_only(self):
try:
#第一次进入 之后update不进入
if self.cache is None:
self.cache = MyCache(None)
else:
self.cache.open(None)
self.cache._initDepCache()
except Exception as e:
logging.error(e)
def _check_self_upgrade(self,cache):
need_upgrade = False
@ -835,13 +868,23 @@ class UpdateSourceInfo():
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):
self.p2pConfigs = UpgradeConfig(datadir = "/etc/apt-p2p/", name = "apt-p2p.cof")
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))

View File

@ -894,7 +894,13 @@ class UpdateManagerDbusController(dbus.service.Object):
@dbus.service.signal(UPDATER_DBUS_INTERFACE)
def ChangeUpgradePolicy(self):
logging.info(COLORLOG_PREFIX + "Emitting" + COLORLOG_SUFFIX +" ChangeUpgradePolicy")
#下载安装前的状态检查信号
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='bs')
def InstallDetectStatus(self, success,error_code=''):
logging.info(COLORLOG_PREFIX + "Emitting"+ COLORLOG_SUFFIX + " InstallDetectStatus success = %r , error_code = %s",\
success,error_code)
WRITABLE_PROPERTIES = ()
# pylint: disable-msg=C0103,C0322

View File

@ -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")
#增加记录当产生错误的时候 详细信息

View File

@ -286,7 +286,7 @@ class InstallBackend():
self.window_main.check_conifg_aptdeamon()
self.update()
except UpdateBaseError as excep:
self._action_done(self.action,True,False,excep.header,excep.desc)
self._action_done(self.action,True,False,excep.header,excep.desc,excep.code)
except UpdateProgressExit as excep:
pass
except Exception as e:
@ -521,18 +521,23 @@ class InstallBackend():
logging.error("Package("+pkg+") "+ str(e))
return [],[]
#调用aptdeamon结束之后处理的地方 不管是出错还是正常都在此处理
def _action_done(self, action, is_cancelled,success, error_string,error_desc):
#后端的状态 到空闲状态
self.window_main.now_working = self.ACTION_DEFUALT_STATUS
def _send_error_code(self,error_code):
if error_code == ERROR_NOT_DISK_SPACE:
self.window_main.dbusController.InstallDetectStatus(False,error_code)
#调用aptdeamon结束之后处理的地方 不管是出错还是正常都在此处理
def _action_done(self, action, is_cancelled,success, error_string,error_desc,error_code=''):
#后端的状态 到空闲状态
self.window_main.now_working = self.ACTION_DEFUALT_STATUS
#升级完成后走的分支
if action == self.ACTION_INSTALL:
#记录这个过程中是否关机
self.window_main.configs.setValue("SystemStatus","abnormal_reboot",str(False),True)
#解锁 禁止关机
unLockedEnableShutdown()
self._send_error_code(error_code)
#单包安装模式 单独处理 目前 更新配置包和升级本身使用
if self.action_mode == self.MODE_INSTALL_SINGLE:
if success:
@ -673,27 +678,28 @@ class InstallBackend():
self.window_main.dbusController.UpdateDownloadFinished(success,self.now_upgrade.upgrade_content,error_string,error_desc)
elif action == self.ACTION_UPDATE:
if success == False and ERROR_UPDATE_KEY_SIGNATURES in self.aptd_base.error_details:
error_desc = _("Check your source public key signature")
#网络认证错误
elif success == False and 'does the network require authentication?' in self.aptd_base.error_details:
error_desc = _("Check if your network requires authentication?")
elif action == self.ACTION_UPDATE and self.action_mode == self.MODE_UPDATE_ALL:
if success == False:
threading_emulate = threading.Thread(target=self.emulate_update)
threading_emulate.start()
if ERROR_UPDATE_KEY_SIGNATURES in self.aptd_base.error_details:
error_desc = get_error_description_from_enum(ERROR_UPDATE_KEY_SIGNATURES)
elif ERROR_UPDATE_NET_AUTHENTICATION in self.aptd_base.error_details:
error_desc = get_error_description_from_enum(ERROR_UPDATE_NET_AUTHENTICATION)
elif ERROR_UPDATE_NOTREAD_SOURCES in self.aptd_base.error_details:
error_desc = get_error_description_from_enum(ERROR_UPDATE_NOTREAD_SOURCES)
if success and self.action_mode == self.MODE_UPDATE_ALL:
if success:
#开始生成列表
self.window_main.start_available()
else:
self.window_main.dbusController.DistUpdateDetectFinished(success,[],error_string+''+error_desc,error_desc)
if self.action_mode == self.MODE_UPDATE_ALL:
#记录本次更新时间插入数据库
self.window_main.sqlite3_server.insert_into_display("check_time",get_east_8_time())
if success == False and self.action_mode == self.MODE_UPDATE_ALL:
threading_emulate = threading.Thread(target=self.emulate_update)
threading_emulate.start()
self.window_main.sqlite3_server.insert_into_display("check_time",get_east_8_time())
elif action == self.ACTION_UPDATE and self.action_mode == self.MODE_UPDATE_CACHE:
self.window_main.dbusController.DistUpdateDetectFinished(success,[],error_string+''+error_desc,error_desc)
elif action == self.ACTION_FIX_BROKEN:
self.window_main.dbusController.FixBrokenStatusChanged(True,success,100,'',error_string,error_desc)
logging.warning("fix broken packages is complete...")

View File

@ -1,6 +1,3 @@
[AutoUpgrade]
upgradelist =
[SystemStatus]
abnormal_reboot = False
close_source_filter = False

View File

@ -520,6 +520,27 @@
#### InstallDetectStatus
- `介绍:`下载安装前的状态检查
- `出参`: `b:`检查出错时为`False`,没有错误`success``s:`产生错误的码
- 错误码示例:
```python
ERROR_NOT_DISK_SPACE = "error-not-disk-space"
```
- `示例:`
```sh
#表示出现磁盘已满的错误z
InstallDetectStatus success = False , error_code = "error-not-disk-space"
```

View File

@ -85,18 +85,15 @@ if __name__ == "__main__":
logging.info('kylin-system-updater(lang:%s) starting ...',os.environ["LANGUAGE"])
try:
app = UpdateManager(options)
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()
except Exception as e:
logging.error(e)
app.run()

View File

@ -2625,6 +2625,9 @@ msgstr "磁盘空间不足,请清理磁盘后进行升级更新"
msgid "Please check your network connection and retry."
msgstr "请检查您的网络连接后再试。"
msgid "Please check your source list and retry."
msgstr "请检查您的源列表后再试。"
msgid "Checking network connection"
msgstr "检查网络连接中"