diff sat_frontends/bridge/pb.py @ 3634:3c7a64d6f49f

bridge: bridge can now be set using environment variable: The `LIBERVIA_BRIDGE_NAME` environment variable can now be used to specify the bridge to use. If set and different from empty string, the environment has precedence over config file value. For `pb` bridge, the following environment variable can also be used: - LIBERVIA_BRIDGE_PB_CONNECTION_TYPE - LIBERVIA_BRIDGE_PB_HOST - LIBERVIA_BRIDGE_PB_PORT
author Goffi <goffi@goffi.org>
date Sat, 28 Aug 2021 15:26:02 +0200
parents d71a163c0861
children 524856bd7b19
line wrap: on
line diff
--- a/sat_frontends/bridge/pb.py	Fri Aug 27 14:59:47 2021 +0200
+++ b/sat_frontends/bridge/pb.py	Sat Aug 28 15:26:02 2021 +0200
@@ -140,29 +140,15 @@
     def bridgeConnect(self, callback, errback):
         factory = pb.PBClientFactory()
         conf = config.parseMainConf()
-        conn_type = config.getConfig(
-            conf,
-            "",
-            "bridge_pb_connection_type",
-            "unix_socket"
-        )
+        getConf = partial(config.getConf, conf, "bridge_pb", "")
+        conn_type = getConf("connection_type", "unix_socket")
         if conn_type == "unix_socket":
             local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve()
             socket_path = local_dir / "bridge_pb"
             reactor.connectUNIX(str(socket_path), factory)
         elif conn_type == "socket":
-            host = int(config.getConfig(
-                conf,
-                "",
-                "bridge_pb_host",
-                "localhost"
-            ))
-            port = int(config.getConfig(
-                conf,
-                "",
-                "bridge_pb_port",
-                8789
-            ))
+            host = getConf("host", "localhost")
+            port = int(getConf("port", 8789))
             reactor.connectTCP(host, port, factory)
         else:
             raise ValueError(f"Unknown pb connection type: {conn_type!r}")