Trying to get python bridge to work.

This commit is contained in:
Raphaël Numbus
2026-05-17 14:24:57 +02:00
parent df5132e97a
commit 27a5eca7f8
2 changed files with 18 additions and 11 deletions
+8 -5
View File
@@ -336,11 +336,14 @@ launch_gui() {
python3 "${BRIDGE_SCRIPT}" > /dev/null 2>&1 & python3 "${BRIDGE_SCRIPT}" > /dev/null 2>&1 &
export BRIDGE_PID=$! export BRIDGE_PID=$!
xdg-open "http://localhost:${WEBSERVER_PORT}" 2>/dev/null || open "http://localhost:${WEBSERVER_PORT}" 2>/dev/null || true
local START_URL="http://localhost:${WEBSERVER_PORT}/pages/index.html"
xdg-open "${START_URL}" 2>/dev/null || open "${START_URL}" 2>/dev/null || true
sleep 5 sleep 5
echo -e "\n ➡️ If it doesn't automatically, open your browser at: $(gum style --foreground 212 "http://localhost:${WEBSERVER_PORT}")" echo -e "\n ➡️ If it doesn't automatically, open your browser at: $(gum style --foreground 212 "${START_URL}")"
} }
# --- MAIN WEB FUNCTIONS ---< # --- MAIN WEB FUNCTIONS ---<
@@ -711,9 +714,9 @@ securely on a hidden sheet of paper or add it to your password manager (locally
# --- DEFAULT VARIABLES ---> # --- DEFAULT VARIABLES --->
WEBSERVER_PORT=${WEBSERVER_PORT:-8088} WEBSERVER_PORT=${WEBSERVER_PORT:-8088}
LIVE_DATA_FILE="config/live.yaml" LIVE_DATA_FILE="web/config/live.yaml"
HW_DATA_FILE="config/hardware.yaml" HW_DATA_FILE="web/config/hardware.yaml"
CONFIG_FILE="config/numbus.yaml" CONFIG_FILE="web/config/numbus.yaml"
BRIDGE_SCRIPT="web/logic/interactive.py" BRIDGE_SCRIPT="web/logic/interactive.py"
+10 -6
View File
@@ -9,10 +9,10 @@ os.makedirs(SECRET_PATH, exist_ok=True)
LOGS_DIR = "logs/" LOGS_DIR = "logs/"
PAGES_DIR = "pages/" PAGES_DIR = "pages/"
CONFIG_DIR = "config/" CONFIG_DIR = "config/"
SIGNALS_DIR = "signal/" SIGNALS_DIR = "signals/"
### <-- Variables ### <-- Variables
os.chdir(web/) os.chdir('web')
class BridgeHandler(http.server.SimpleHTTPRequestHandler): class BridgeHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self): def do_GET(self):
@@ -39,18 +39,22 @@ class BridgeHandler(http.server.SimpleHTTPRequestHandler):
if self.path == '/discovery': if self.path == '/discovery':
# Store secrets in memory-backed filesystem # Store secrets in memory-backed filesystem
with open(os.path.join(SECRET_PATH, "live.yaml"), "wb") as f: # We write to CONFIG_DIR so deploy.sh can find it easily
os.makedirs(CONFIG_DIR, exist_ok=True)
with open(os.path.join(CONFIG_DIR, "live.yaml"), "wb") as f:
f.write(post_data) f.write(post_data)
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
# Signal Bash that discovery data is ready # Signal Bash that discovery data is ready and we can proceed to hardware detection
with open(os.path.join(SIGNALS_DIR, ".discovery_ready"), "w") as f: f.write("1") os.makedirs(SIGNALS_DIR, exist_ok=True)
with open(os.path.join(SIGNALS_DIR, "hw_detection_ready"), "w") as f: f.write("1")
with open(os.path.join(SIGNALS_DIR, "configuration_ready"), "w") as f: f.write("1")
elif self.path == '/deploy': elif self.path == '/deploy':
with open(os.path.join(CONFIG_DIR, "numbus.yaml"), "wb") as f: with open(os.path.join(CONFIG_DIR, "numbus.yaml"), "wb") as f:
f.write(post_data) f.write(post_data)
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
with open(os.path.join(SIGNALS_DIR, ".deploy_signal"), "w") as f: f.write("1") with open(os.path.join(SIGNALS_DIR, "deployment_ready"), "w") as f: f.write("1")
http.server.HTTPServer(('localhost', 8088), BridgeHandler).serve_forever() http.server.HTTPServer(('localhost', 8088), BridgeHandler).serve_forever()