diff 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
line wrap: on
line diff
--- a/libervia/frontends/bridge/dbus_bridge.py	Tue Dec 12 12:17:15 2023 +0100
+++ b/libervia/frontends/bridge/dbus_bridge.py	Wed Dec 13 22:00:22 2023 +0100
@@ -82,11 +82,7 @@
                                       'org.freedesktop.DBus.Error.Spawn.ExecFailed'):
                 errback(BridgeExceptionNoService())
             elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
-                log.error(_(
-                    'D-Bus is not launched, please see documentation '
-                    '(doc/installation.rst, section "Launching D-Bus (on servers)") to '
-                    'see instructions on how to launch it.'
-                ))
+                log.error(_("D-Bus is not launched, please see README to see instructions on how to launch it"))
                 errback(BridgeInitError)
             else:
                 errback(e)
@@ -446,6 +442,15 @@
             error_handler = lambda err:errback(dbus_to_bridge_exception(err))
         return str(self.db_core_iface.image_resize(image_path, width, height, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
 
+    def init_pre_script(self, callback=None, errback=None):
+        if callback is None:
+            error_handler = None
+        else:
+            if errback is None:
+                errback = log.error
+            error_handler = lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.init_pre_script(timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
+
     def is_connected(self, profile_key="@DEFAULT@", callback=None, errback=None):
         if callback is None:
             error_handler = None
@@ -1251,6 +1256,14 @@
         self.db_core_iface.image_resize(image_path, width, height, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
         return fut
 
+    def init_pre_script(self):
+        loop = asyncio.get_running_loop()
+        fut = loop.create_future()
+        reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
+        error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
+        self.db_core_iface.init_pre_script(timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
+        return fut
+
     def is_connected(self, profile_key="@DEFAULT@"):
         loop = asyncio.get_running_loop()
         fut = loop.create_future()