增加aptdaemon可升级时 进行自动升级
This commit is contained in:
parent
42efb70512
commit
9fa1193e74
|
@ -43,7 +43,7 @@ class UpgradeConfig(SafeConfigParser):
|
|||
|
||||
def setValue(self, section, option, value=None,is_write = True):
|
||||
if option != 'upgradelist':
|
||||
logging.info("setValue section:%s option:%s value:%s",section, option, value)
|
||||
logging.info("SetValue Section:%s Option:%s Value:%s",section, option, value)
|
||||
|
||||
try:
|
||||
self.set(section, option,value)
|
||||
|
|
|
@ -30,6 +30,7 @@ from SystemUpdater.Core.DpkgInstallProgress import LogInstallProgress
|
|||
class UpdateManager():
|
||||
SELF_PKG_NAME = 'kylin-system-updater'
|
||||
GROUPS_PKG_NAME = 'kylin-update-desktop-config'
|
||||
APTD_PKG_NAME = "aptdaemon"
|
||||
INSTALL_ALONE_PROGRESS = "alone"
|
||||
RUN_UNATTENDED_UPGRADE = '/var/run/unattended-upgrades.pid'
|
||||
RETRY_LIMIT_NUM = 1
|
||||
|
@ -68,8 +69,9 @@ class UpdateManager():
|
|||
self.is_disc_source = False
|
||||
|
||||
#是否开启关机后安装或者重启安装模式
|
||||
self.later_install = False
|
||||
self.upgrade_partial = []
|
||||
if self.shutdown_install_model() == True:
|
||||
self.upgrade_partial = []
|
||||
logging.info("Now install model use to shutdown install model...")
|
||||
|
||||
def check_auto_install(self):
|
||||
return self.configs.getWithDefault("InstallModel", "auto_install", False)
|
||||
|
@ -77,6 +79,12 @@ class UpdateManager():
|
|||
def check_manual_install(self):
|
||||
return self.configs.getWithDefault("InstallModel", "manual_install", False)
|
||||
|
||||
def shutdown_install_model(self):
|
||||
return self.configs.getWithDefault("InstallModel", "shutdown_install", False)
|
||||
|
||||
def reset_manaul_install(self):
|
||||
self.configs.setValue("InstallModel","manual_install",str(False),True)
|
||||
|
||||
#检查是否需要重新启动aptdeamon 目前需要重启的有限速功能
|
||||
def check_restart_aptdeamon(self):
|
||||
if self.set_restart_aptdeamon == True:
|
||||
|
@ -123,12 +131,12 @@ class UpdateManager():
|
|||
install_backend = get_backend(self, InstallBackend.ACTION_INSTALLONLY)
|
||||
install_backend.start()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
logging.error(e)
|
||||
|
||||
#进行升级的操作
|
||||
def start_install(self,upgrade_mode,not_resolver = False,partial_upgrade_list = []):
|
||||
try:
|
||||
if self.later_install == True and upgrade_mode != InstallBackend.MODE_UPGRADE_SINGLE:
|
||||
if self.shutdown_install_model() == True and upgrade_mode != InstallBackend.MODE_UPGRADE_SINGLE:
|
||||
#部分升级的方式 计算的时候 补上上次更新的内容一起计算
|
||||
if upgrade_mode == InstallBackend.MODE_UPGRADE_PARTIAL:
|
||||
partial_upgrade_list += self.upgrade_partial
|
||||
|
@ -174,10 +182,10 @@ class UpdateManager():
|
|||
self.configs.reReadConfigFiles()
|
||||
self.retry_limit = self.RETRY_LIMIT_NUM
|
||||
|
||||
self.later_install = self.configs.getWithDefault("InstallModel", "shutdown_install", False)
|
||||
if self.later_install == True:
|
||||
self.upgrade_partial = []
|
||||
if self.shutdown_install_model() == True:
|
||||
logging.info("Check: Now install model use to shutdown_install model...")
|
||||
self.upgrade_partial = []
|
||||
self.reset_manaul_install()
|
||||
|
||||
#检查 光盘源
|
||||
if self._check_disc_source() == True:
|
||||
|
@ -402,6 +410,12 @@ class UpdateManager():
|
|||
if _success == False:
|
||||
return _success,header,desc
|
||||
|
||||
#检查自己是否需要升级更新
|
||||
if self.options.no_check_selfupgrade is False:
|
||||
_success,header,desc = self._check_aptd_upgrade(self.cache)
|
||||
if _success == False:
|
||||
return _success,header,desc
|
||||
|
||||
#检查更新分组配置表
|
||||
_success,header,desc = self._check_group_config(self.cache)
|
||||
if _success == False and self.configs.getWithDefault("ConfigPkgStatus", "mustexistconfigpkg", True) == True:
|
||||
|
@ -420,12 +434,12 @@ class UpdateManager():
|
|||
#2、 安装JSON分组配置文件包 安装完毕会重新调start_available --> here 安装失败就直接退出不会进行下面的操作
|
||||
try:
|
||||
if self.SELF_PKG_NAME in cache:
|
||||
pkg_json = cache[self.SELF_PKG_NAME]
|
||||
self_pkg = cache[self.SELF_PKG_NAME]
|
||||
#是否安装
|
||||
if pkg_json.is_installed and pkg_json.is_upgradable:
|
||||
if self_pkg.is_installed and self_pkg.is_upgradable:
|
||||
logging.info("Check: Self-Updater(%s) start upgrading From %s to %s...",self.SELF_PKG_NAME,\
|
||||
pkg_json.installed.source_version,pkg_json.candidate.source_version)
|
||||
pkg_json.mark_upgrade()
|
||||
self_pkg.installed.source_version,self_pkg.candidate.source_version)
|
||||
self_pkg.mark_upgrade()
|
||||
|
||||
self.start_install(InstallBackend.MODE_UPGRADE_SINGLE,True)
|
||||
#直接退出 进行安装程序
|
||||
|
@ -433,7 +447,7 @@ class UpdateManager():
|
|||
header = self.INSTALL_ALONE_PROGRESS
|
||||
return _success,header,desc
|
||||
else:
|
||||
logging.info("Check: Self-Updater(%s:%s) No need to upgrade...",self.SELF_PKG_NAME,pkg_json.installed.source_version)
|
||||
logging.info("Check: Self-Updater(%s:%s) No need to upgrade...",self.SELF_PKG_NAME,self_pkg.installed.source_version)
|
||||
#直接退出 进行之后的动作
|
||||
_success = True
|
||||
return _success,header,desc
|
||||
|
@ -493,20 +507,46 @@ class UpdateManager():
|
|||
logging.error(e)
|
||||
_success = False
|
||||
return _success,header,desc
|
||||
|
||||
#FIXME:
|
||||
#3、 判断目录是JSON配置文件夹是否缺失 缺失后进行修复 卸载重新安装步骤
|
||||
# if not os.path.exists(INPUT_CONFIG_PATH):
|
||||
# logging.info("groups JSON Config Path(%s) Missing and Trying to fix...",INPUT_CONFIG_PATH)
|
||||
# #将软件包卸载 之后进行重新安装here --> purge --> start_available 进行判断是否安装未安装重新安装
|
||||
# # self.start_install_alone(pkgs_purge = [self.GROUPS_PKG_NAME])
|
||||
# #直接退出
|
||||
# _success = False
|
||||
# header = self.INSTALL_ALONE_PROGRESS
|
||||
# return _success,header,desc
|
||||
|
||||
return _success,header,desc
|
||||
|
||||
def _check_aptd_upgrade(self,cache):
|
||||
_success = True
|
||||
header = ''
|
||||
desc = ''
|
||||
#2、 安装JSON分组配置文件包 安装完毕会重新调start_available --> here 安装失败就直接退出不会进行下面的操作
|
||||
try:
|
||||
if self.APTD_PKG_NAME in cache:
|
||||
self_pkg = cache[self.APTD_PKG_NAME]
|
||||
#是否安装
|
||||
if self_pkg.is_installed and self_pkg.is_upgradable:
|
||||
logging.info("Check: Aptdaemon(%s) start upgrading From %s to %s...",self.APTD_PKG_NAME,\
|
||||
self_pkg.installed.source_version,self_pkg.candidate.source_version)
|
||||
self_pkg.mark_upgrade()
|
||||
|
||||
self.start_install(InstallBackend.MODE_UPGRADE_SINGLE,True)
|
||||
#直接退出 进行安装程序
|
||||
_success = False
|
||||
header = self.INSTALL_ALONE_PROGRESS
|
||||
return _success,header,desc
|
||||
else:
|
||||
logging.info("Check: Aptdaemon(%s:%s) No need to upgrade...",self.APTD_PKG_NAME,self_pkg.installed.source_version)
|
||||
#直接退出 进行之后的动作
|
||||
_success = True
|
||||
return _success,header,desc
|
||||
else:
|
||||
#没有在cache中就认为不需要升级
|
||||
logging.error("Check: Aptdaemon(%s) The upgrade package is not in Cache...",self.APTD_PKG_NAME)
|
||||
#直接退出 进行之后的动作
|
||||
_success = True
|
||||
return _success,header,desc
|
||||
|
||||
#FIXME: 错误处理未做 报告到控制面板
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
_success = True
|
||||
return _success,header,desc
|
||||
|
||||
def _check_system_broken(self,cache):
|
||||
_success = True
|
||||
header = ''
|
||||
|
|
|
@ -215,22 +215,35 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
mainloop.quit()
|
||||
logging.debug("Exit")
|
||||
|
||||
#检查是否需要安装或者重启安装的请求
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,out_signature='i')
|
||||
def Test(self):
|
||||
try:
|
||||
self.parent.start_install_later()
|
||||
return 0
|
||||
except Exception:
|
||||
return -1
|
||||
|
||||
#检查是否需要安装或者重启安装的请求
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,out_signature='i')
|
||||
def CheckInstallRequired(self):
|
||||
try:
|
||||
logging.info(COLORMETHOR_PREFIX+'Method'+COLORLOG_SUFFIX+' CheckInstallRequired ...')
|
||||
|
||||
if self.parent.check_manual_install() == True:
|
||||
logging.info("Now need to shutdown install in manual install model...")
|
||||
return 1
|
||||
elif self.parent.check_auto_install() == True:
|
||||
logging.info("Now need to shutdown install in auto install model...")
|
||||
return 2
|
||||
if self.shutdown_install_model() == True:
|
||||
if self.parent.check_manual_install() == True:
|
||||
logging.info("Now need to shutdown install in manual install model...")
|
||||
return 1
|
||||
elif self.parent.check_auto_install() == True:
|
||||
logging.info("Now need to shutdown install in auto install model...")
|
||||
return 2
|
||||
else:
|
||||
return 0
|
||||
else:
|
||||
logging.info("No need to shutdown install in the normal model...")
|
||||
return 0
|
||||
except Exception:
|
||||
return -1
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return 0
|
||||
|
||||
#set config value
|
||||
@dbus.service.method(UPDATER_DBUS_INTERFACE,in_signature='sss',out_signature='b')
|
||||
|
|
|
@ -131,9 +131,7 @@ class InstallBackend():
|
|||
self.commit(self.action,pkgs_install, pkgs_upgrade, pkgs_remove)
|
||||
elif self.action == self.ACTION_DOWNLOADONLY:
|
||||
#将需要升级的软件包写入配置文件中进行保存
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_install",pkgs_install)
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_upgrade",pkgs_upgrade)
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_remove",pkgs_remove)
|
||||
self._update_to_config(pkgs_install,pkgs_upgrade,pkgs_remove)
|
||||
self.commit(self.action,pkgs_install, pkgs_upgrade, pkgs_remove)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
@ -442,7 +440,7 @@ class InstallBackend():
|
|||
desc ='\n' + msg
|
||||
logging.error('\n' + msg)
|
||||
return _success,[],[],header,desc
|
||||
|
||||
|
||||
#调用aptdeamon结束之后处理的地方 不管是出错还是正常都在此处理
|
||||
def _action_done(self, action, is_cancelled,success, error_string,error_desc):
|
||||
#后端的状态 到空闲状态
|
||||
|
@ -464,6 +462,9 @@ class InstallBackend():
|
|||
self.window_main.dbusController.DistUpdateDetectFinished(False,[self.window_main.SELF_PKG_NAME],error_string,error_desc)
|
||||
#升级本身完成后 退出 有systemd 来进行重启服务
|
||||
self.window_main.dbusController.Quit(None)
|
||||
elif self.window_main.APTD_PKG_NAME in self.cache and self.cache[self.window_main.APTD_PKG_NAME] in self.cache.get_changes():
|
||||
#升级本身完成后 直接重启aptd
|
||||
self.window_main.dbusController.make_aptdeamon_restart()
|
||||
else:
|
||||
#只有安装配置文件包 才会走到此处
|
||||
self.window_main.start_available()
|
||||
|
@ -523,14 +524,14 @@ class InstallBackend():
|
|||
self.window_main.only_update_cache()
|
||||
|
||||
elif action == self.ACTION_INSTALLONLY:
|
||||
self.window_main.configs.setValue("SystemStatus","isabnormalreboot",str(False),True)
|
||||
self.window_main.configs.setValue("SystemStatus","isabnormalreboot",str(False))
|
||||
if success == True:
|
||||
#记录这个过程中是否关机
|
||||
self.window_main.configs.setValue("InstallModel","manual_install",str(False),True)
|
||||
#当升级完成时 将手动和自动安装的标志位全部清空
|
||||
self.window_main.configs.setValue("InstallModel","manual_install",str(False))
|
||||
self.window_main.configs.setValue("InstallModel","auto_install",str(False))
|
||||
|
||||
#安装完成之后清空下载列表
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_install",[])
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_upgrade",[])
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_remove",[])
|
||||
self._update_to_config([],[],[])
|
||||
|
||||
upgrade_content = self.now_upgrade.upgrade_groups + self.now_upgrade.single_pkgs
|
||||
self.window_main.dbusController.UpdateInstallFinished(success,upgrade_content,error_string,error_desc)
|
||||
|
@ -538,6 +539,14 @@ class InstallBackend():
|
|||
elif action == self.ACTION_DOWNLOADONLY:
|
||||
upgrade_content = self.now_upgrade.upgrade_groups + self.now_upgrade.single_pkgs
|
||||
|
||||
if self.is_version_upgrade == True and self.is_need_retry == True and success == False:
|
||||
#增加重试次数的限制
|
||||
if self.window_main.retry_limit != 0:
|
||||
logging.warning("Retry the upgrade and installaton(%s) and retry number: %d",upgrade_content,self.window_main.retry_limit)
|
||||
self.window_main.start_install(self.now_upgrade.upgrade_mode,True,upgrade_content)
|
||||
self.window_main.retry_limit = self.window_main.retry_limit - 1
|
||||
return
|
||||
|
||||
if success == True and self.now_upgrade.upgrade_mode == self.MODE_UPGRADE_PARTIAL:
|
||||
self.window_main.upgrade_partial += upgrade_content
|
||||
|
||||
|
@ -547,14 +556,6 @@ class InstallBackend():
|
|||
else:
|
||||
self.window_main.configs.setValue("InstallModel","manual_install",str(False),True)
|
||||
|
||||
if self.is_version_upgrade == True and self.is_need_retry == True and success == False:
|
||||
#增加重试次数的限制
|
||||
if self.window_main.retry_limit != 0:
|
||||
logging.warning("Retry the upgrade and installaton(%s) and retry number: %d",upgrade_content,self.window_main.retry_limit)
|
||||
self.window_main.start_install(self.now_upgrade.upgrade_mode,True,upgrade_content)
|
||||
self.window_main.retry_limit = self.window_main.retry_limit - 1
|
||||
return
|
||||
|
||||
self.window_main.dbusController.UpdateDownloadFinished(success,upgrade_content,error_string,error_desc)
|
||||
|
||||
elif action == self.ACTION_UPDATE:
|
||||
|
@ -594,7 +595,13 @@ class InstallBackend():
|
|||
error_string = _("Package validation failed and installation was rejected.")
|
||||
error_desc = ''
|
||||
self.window_main.dbusController.InstalldebFinished(success,error_string,error_desc)
|
||||
|
||||
|
||||
|
||||
def _update_to_config(self,pkgs_install,pkgs_upgrade,pkgs_remove):
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_install",pkgs_install)
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_upgrade",pkgs_upgrade)
|
||||
self.window_main.configs.setListValue("InstallModel","pkgs_remove",pkgs_remove)
|
||||
|
||||
#将安装完成的插入数据库 安装失败的计算那些包安装失败了 分类插入数据库中
|
||||
#将安装失败的数据进行返回
|
||||
def _make_insert_info(self,success,is_cancelled,_now_upgrade,error_string,error_desc):
|
||||
|
|
Loading…
Reference in New Issue