comparison libervia/frontends/bridge/dbus_bridge.py @ 4193:730f542e4ad0

core: add new `init_script_path` option: `init_script_path` option can be used in `[DEFAULTS]` to run a script at the end of backend initialisation. A new `init_pre_script` method is used to wait for backend to reach this stage (designed to be used mostly by CLI frontend), then the usual `ready_get` method is finished once the script is finished.
author Goffi <goffi@goffi.org>
date Wed, 13 Dec 2023 22:00:22 +0100
parents 11f95dfe5b17
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4192:1d24ff583794 4193:730f542e4ad0
80 except dbus.exceptions.DBusException as e: 80 except dbus.exceptions.DBusException as e:
81 if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown', 81 if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown',
82 'org.freedesktop.DBus.Error.Spawn.ExecFailed'): 82 'org.freedesktop.DBus.Error.Spawn.ExecFailed'):
83 errback(BridgeExceptionNoService()) 83 errback(BridgeExceptionNoService())
84 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported': 84 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
85 log.error(_( 85 log.error(_("D-Bus is not launched, please see README to see instructions on how to launch it"))
86 'D-Bus is not launched, please see documentation '
87 '(doc/installation.rst, section "Launching D-Bus (on servers)") to '
88 'see instructions on how to launch it.'
89 ))
90 errback(BridgeInitError) 86 errback(BridgeInitError)
91 else: 87 else:
92 errback(e) 88 errback(e)
93 else: 89 else:
94 callback() 90 callback()
443 else: 439 else:
444 if errback is None: 440 if errback is None:
445 errback = log.error 441 errback = log.error
446 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) 442 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
447 return str(self.db_core_iface.image_resize(image_path, width, height, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) 443 return str(self.db_core_iface.image_resize(image_path, width, height, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
444
445 def init_pre_script(self, callback=None, errback=None):
446 if callback is None:
447 error_handler = None
448 else:
449 if errback is None:
450 errback = log.error
451 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
452 return self.db_core_iface.init_pre_script(timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
448 453
449 def is_connected(self, profile_key="@DEFAULT@", callback=None, errback=None): 454 def is_connected(self, profile_key="@DEFAULT@", callback=None, errback=None):
450 if callback is None: 455 if callback is None:
451 error_handler = None 456 error_handler = None
452 else: 457 else:
1249 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret) 1254 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1250 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err)) 1255 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1251 self.db_core_iface.image_resize(image_path, width, height, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler) 1256 self.db_core_iface.image_resize(image_path, width, height, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1252 return fut 1257 return fut
1253 1258
1259 def init_pre_script(self):
1260 loop = asyncio.get_running_loop()
1261 fut = loop.create_future()
1262 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1263 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1264 self.db_core_iface.init_pre_script(timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1265 return fut
1266
1254 def is_connected(self, profile_key="@DEFAULT@"): 1267 def is_connected(self, profile_key="@DEFAULT@"):
1255 loop = asyncio.get_running_loop() 1268 loop = asyncio.get_running_loop()
1256 fut = loop.create_future() 1269 fut = loop.create_future()
1257 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret) 1270 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1258 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err)) 1271 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))