优化代码逻辑,调整dbus接口

This commit is contained in:
wangsong 2021-11-22 09:40:55 +08:00
parent 387c0a796c
commit cacc58e8a7
2 changed files with 11 additions and 27 deletions

View File

@ -101,7 +101,7 @@ class UpdateManager():
def start_download(self, pkgs):
try:
if self.options.no_update_source is False:
self.dbusController._on_update_important_list()
self.dbusController.on_update_important_list()
update_backend = get_backend(self, InstallBackend.ACTION_DOWNLOADONLY)
update_backend.start(partial_upgrade_list = pkgs)
@ -125,7 +125,7 @@ class UpdateManager():
#从服务器端更新摸板
self.dbusController.UpdateDetectStatusChanged(10,_("Updating Source Template"))
if self.options.no_update_source is False:
_success,header,desc = self.dbusController._on_update_important_list()
_success,header,desc = self.dbusController.on_update_important_list()
if _success == False:
self.dbusController.UpdateDetectFinished(_success,[],header,desc)
return

View File

@ -47,24 +47,19 @@ class UpdateManagerDbusController(dbus.service.Object):
object_path=UPDATER_DBUS_PATH):
dbus.service.Object.__init__(self, bus_name, object_path)
self.parent = parent
self.bus = dbus.SystemBus()
#网络检测 电池检测等等的启动检查
# self.alert_watcher = AlertWatcher()
# self.alert_watcher.check_alert_state()
# self.alert_watcher.connect("network-alert", self._on_network_alert)
# self.connected = False
self.transaction = None
#更新important.list的本次升级的列表
def _on_update_important_list(self):
def on_update_important_list(self):
header = None
desc = None
lock = threading.Lock()
bus = dbus.SystemBus()
try:
logging.info("Start to update Source Template...")
obj = bus.get_object('com.kylin.software.properties', '/com/kylin/software/properties')
# logging.info("Start to update Source Template...")
obj = self.bus.get_object('com.kylin.software.properties', '/com/kylin/software/properties')
interface = dbus.Interface(obj, dbus_interface='com.kylin.software.properties.interface')
lock.acquire()
retval = interface.updateSourceTemplate(timeout=5)
@ -81,7 +76,7 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.warning(header + desc)
return retval,header,desc
else:
logging.info("Update sourceTemplate successed...")
# logging.info("Update sourceTemplate successed...")
return retval,header,desc
#重启aptdeamon后台服务
@ -89,9 +84,8 @@ class UpdateManagerDbusController(dbus.service.Object):
header = None
desc = None
bus = dbus.SystemBus()
try:
obj = bus.get_object('org.debian.apt', '/org/debian/apt')
obj = self.bus.get_object('org.debian.apt', '/org/debian/apt')
interface = dbus.Interface(obj, dbus_interface='org.debian.apt')
retval = interface.Quit()
except Exception as e:
@ -104,13 +98,12 @@ class UpdateManagerDbusController(dbus.service.Object):
header = ''
desc = ''
bus = dbus.SystemBus()
try:
logging.info("Start to check network connectivity...")
obj = bus.get_object("org.freedesktop.NetworkManager","/org/freedesktop/NetworkManager")
# logging.info("Start to check network connectivity...")
obj = self.bus.get_object("org.freedesktop.NetworkManager","/org/freedesktop/NetworkManager")
interface = dbus.Interface(obj, "org.freedesktop.NetworkManager")
retval = interface.CheckConnectivity(timeout=5)
logging.info("Check network connectivity to Complete...")
# logging.info("Check network connectivity to Complete...")
if retval == 4:
return True,header,desc
else:
@ -123,15 +116,6 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.error(header + desc)
return False,header,desc
#检测网络的状态
# def _on_network_alert(self, watcher, state):
# if state in NetworkManagerHelper.NM_STATE_CONNECTED_LIST:
# self.connected = True
# logging.info('Network Connected ...')
# else:
# self.connected = False
# logging.info('Network Disconnected ...')
@dbus.service.method(UPDATER_DBUS_INTERFACE,
in_signature="", out_signature="",
sender_keyword="caller_name")