修改安装JSON配置包的流程 以及错误反馈的机制完善

This commit is contained in:
wangsong 2021-09-14 16:17:49 +08:00
parent c419449bbc
commit ef47740996
5 changed files with 63 additions and 29 deletions

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"sudo":true
}
]
}

View File

@ -24,11 +24,13 @@ from .Core.MyCache import MyCache
from .UpdateManagerDbus import UpdateManagerDbusController
from .Core.UpdateList import UpdateList
from .backend import (InstallBackend,
get_backend)
get_backend)
#安装完成之后是否有请求需要重启
REBOOT_REQUIRED_FILE = "/var/run/reboot-required"
INSTALL_ALONE_PROGRESS = "alone"
class UpdateManager():
def __init__(self,options):
@ -135,7 +137,14 @@ class UpdateManager():
#更新结束之后会调到此获取要升级的列表 and 安装完成后也会再重新调此方法更新cache
def start_available(self, cancelled_update=False):
self.refresh_cache()
_success,header,desc = self.refresh_cache()
#特殊情况的处理 单独安装包需要直接退出
if _success == True and header == INSTALL_ALONE_PROGRESS:
return
else:
#发送更新升级列表完成的标志
self.dbusController.UpdateDetectFinished(_success,self.update_list.local_upgrade_list.get('upgrade_groups_list',[]),header,desc)
#检查安装完成之后需要重启吗
if os.path.exists(REBOOT_REQUIRED_FILE):
@ -143,8 +152,8 @@ class UpdateManager():
def refresh_cache(self):
_success = True
header = ''
desc = ''
header = None
desc = None
try:
#第一次进入 之后update不进入
if self.cache is None:
@ -155,19 +164,21 @@ class UpdateManager():
except AssertionError:
header = _("Software index is broken")
desc = _("It is impossible to install or remove any software. "
"Please use the package manager \"Synaptic\" or run "
"\"sudo apt-get install -f\" in a terminal to fix "
"this issue at first.")
"Please use the package manager \"Synaptic\" or run "
"\"sudo apt-get install -f\" in a terminal to fix "
"this issue at first.")
_success = False
return _success,header,desc
except SystemError as e:
header = _("Could not initialize the package information")
desc = _("An unresolvable problem occurred while "
"initializing the package information.\n\n"
"Please report this bug against the 'update-manager' "
"package and include the following error "
"message:\n") + str(e)
"initializing the package information.\n\n"
"Please report this bug against the 'update-manager' "
"package and include the following error "
"message:\n") + str(e)
_success = False
return _success,header,desc
self.update_list = UpdateList(self)
@ -187,14 +198,19 @@ class UpdateManager():
logging.info("groups JSON ConfigPkgs(%s) start upgrading...",self.GROUPS_JSON_PKG)
self.start_install_alone(pkgs_upgrade = [self.update_list.GROUPS_JSON_PKG])
#直接退出
return
_success = True
header = INSTALL_ALONE_PROGRESS
return _success,header,desc
else:
logging.info("ConfigPkgs(%s) No need to upgrade...",self.update_list.GROUPS_JSON_PKG)
else:
logging.info("groups JSON ConfigPkgs(%s) start new installing...",self.update_list.GROUPS_JSON_PKG)
self.start_install_alone(pkgs_install = [self.update_list.GROUPS_JSON_PKG])
#直接退出
return
_success = True
header = INSTALL_ALONE_PROGRESS
return _success,header,desc
#FIXME: 错误处理未做 报告到控制面板
except Exception as e:
logging.warning("groups JSON ConfigPkgs(%s) install failed...",self.update_list.GROUPS_JSON_PKG)
@ -207,7 +223,9 @@ class UpdateManager():
#将软件包卸载 之后进行重新安装here --> purge --> start_available 进行判断是否安装未安装重新安装
self.start_install_alone(pkgs_purge = [self.update_list.GROUPS_JSON_PKG])
#直接退出
return
_success = True
header = INSTALL_ALONE_PROGRESS
return _success,header,desc
#4、 清空上次输出的分组JSON文件
try:
@ -237,21 +255,19 @@ class UpdateManager():
"message:\n") + str(e)
_success = False
#发送更新升级列表完成的标志
self.dbusController.UpdateDetectFinished(_success,self.update_list.local_upgrade_list.get('upgrade_groups_list',[]),header,desc)
return _success,header,desc
def _setup_dbus(self):
# check if there is another g-a-i already and if not setup one
# listening on dbus
try:
# bus = dbus.SessionBus()
bus = dbus.SystemBus()
except Exception:
logging.error("warning: could not initiate dbus")
return
try:
proxy_obj = bus.get_object('com.kylin.systemupgrade',
'/com/kylin/systemupgrade')
'/com/kylin/systemupgrade')
logging.warning("kylin-update-manager have started...")
sys.exit(0)
@ -259,5 +275,4 @@ class UpdateManager():
bus_name = dbus.service.BusName('com.kylin.systemupgrade',
bus)
logging.info('initiate dbus success ...')
return UpdateManagerDbusController(self, bus_name)
return UpdateManagerDbusController(self, bus_name)

View File

@ -14,7 +14,7 @@ class UpdateManagerDbusController(dbus.service.Object):
INTERFACE = 'com.kylin.systemupgrade.interface'
def __init__(self, parent, bus_name,
object_path='/com/kylin/systemupgrade'):
object_path='/com/kylin/systemupgrade'):
dbus.service.Object.__init__(self, bus_name, object_path)
self.parent = parent
@ -127,13 +127,13 @@ class UpdateManagerDbusController(dbus.service.Object):
#更新完成的信号
@dbus.service.signal(INTERFACE,signature='basss')
def UpdateDetectFinished(self, success, upgrade_group,error_string='',error_desc='',):
logging.info("emit success = %r , upgrade_group = %a, error_string = %s , error_desc = %s ",\
logging.info("emit udapte success = %r , upgrade_group = %a, error_string = %s , error_desc = %s ",\
success,upgrade_group, error_string,error_desc)
#升级的进度信息 0~100 进度信息 101为非预期的信号
@dbus.service.signal(INTERFACE,signature='asis')
def UpdateDloadAndInstStaChanged(self,groups_list,progress,status):
logging.info("emit groups_list = %s progress = %d , status = %s",groups_list,progress,status)
logging.info("emit upgrade groups_list = %s progress = %d , status = %s",groups_list,progress,status)
#升级完成的信号
@dbus.service.signal(INTERFACE,signature='basss')

View File

@ -87,7 +87,12 @@ class InstallBackend():
if action == self.ACTION_INSTALL:
self.window_main.is_upgrading = False
if success:
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,'','')
#当组列表为空时 表示现在的单独进行安装某些包或卸载,不发信号到控制面板
if self.upgrade_groups_list:
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,'','')
else:
self.window_main.start_available()
elif error_string or error_desc:
logging.warning(error_string + error_desc)
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,error_string,error_desc)

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3
# update-manager.in - easy updating application
from __future__ import print_function
@ -21,10 +20,10 @@ if __name__ == "__main__":
# Begin parsing of options
parser = OptionParser()
parser.add_option ("--no-update", action="store_true",
dest="no_update", default=False,
help=_("Do not check for updates when starting"))
dest="no_update", default=False,
help=_("Do not check for updates when starting"))
parser.add_option ("", "--debug", action="store_true", default=False,
help=_("Show debug messages"))
help=_("Show debug messages"))
(options, args) = parser.parse_args()
@ -34,7 +33,6 @@ if __name__ == "__main__":
logging.basicConfig(format=FORMAT,level=logging.INFO)
logging.info('kylin-update-manager starting ...')
bus_loop = DBusGMainLoop(set_as_default=True)
app = UpdateManager(options)