Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
3632:7acf19bdca2f | 3634:3c7a64d6f49f |
---|---|
138 raise failure_ | 138 raise failure_ |
139 | 139 |
140 def bridgeConnect(self, callback, errback): | 140 def bridgeConnect(self, callback, errback): |
141 factory = pb.PBClientFactory() | 141 factory = pb.PBClientFactory() |
142 conf = config.parseMainConf() | 142 conf = config.parseMainConf() |
143 conn_type = config.getConfig( | 143 getConf = partial(config.getConf, conf, "bridge_pb", "") |
144 conf, | 144 conn_type = getConf("connection_type", "unix_socket") |
145 "", | |
146 "bridge_pb_connection_type", | |
147 "unix_socket" | |
148 ) | |
149 if conn_type == "unix_socket": | 145 if conn_type == "unix_socket": |
150 local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve() | 146 local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve() |
151 socket_path = local_dir / "bridge_pb" | 147 socket_path = local_dir / "bridge_pb" |
152 reactor.connectUNIX(str(socket_path), factory) | 148 reactor.connectUNIX(str(socket_path), factory) |
153 elif conn_type == "socket": | 149 elif conn_type == "socket": |
154 host = int(config.getConfig( | 150 host = getConf("host", "localhost") |
155 conf, | 151 port = int(getConf("port", 8789)) |
156 "", | |
157 "bridge_pb_host", | |
158 "localhost" | |
159 )) | |
160 port = int(config.getConfig( | |
161 conf, | |
162 "", | |
163 "bridge_pb_port", | |
164 8789 | |
165 )) | |
166 reactor.connectTCP(host, port, factory) | 152 reactor.connectTCP(host, port, factory) |
167 else: | 153 else: |
168 raise ValueError(f"Unknown pb connection type: {conn_type!r}") | 154 raise ValueError(f"Unknown pb connection type: {conn_type!r}") |
169 d = factory.getRootObject() | 155 d = factory.getRootObject() |
170 d.addCallback(self._set_root) | 156 d.addCallback(self._set_root) |