#!/usr/bin/env python3 """Sync changed web-console files and build on remote (fast path).""" from __future__ import annotations import sys import time from pathlib import Path if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", errors="replace") try: import paramiko except ImportError: print("pip install paramiko", file=sys.stderr) raise SystemExit(1) HOST = "192.168.31.56" USER = "eric" PASS = "4669805" REMOTE = "/home/eric/d2ypp2" LOCAL = Path(__file__).resolve().parent.parent FILES = [ "web-console/next.config.mjs", "web-console/app/globals.css", "web-console/components/LiveStudioScene3D.tsx", "web-console/components/live-product/DashboardOverview.tsx", ] def main() -> int: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(HOST, username=USER, password=PASS, timeout=20) sftp = client.open_sftp() for rel in FILES: lp = LOCAL / rel rp = f"{REMOTE}/{rel.replace(chr(92), '/')}" sftp.put(str(lp), rp) print(f"uploaded {rel}") sftp.close() print("--- remote build ---") _, stdout, _ = client.exec_command(f"cd {REMOTE}/web-console && npm run build 2>&1", timeout=600) start = time.time() while not stdout.channel.exit_status_ready(): if stdout.channel.recv_ready(): print(stdout.channel.recv(4096).decode("utf-8", "replace"), end="", flush=True) time.sleep(0.3) tail = stdout.read().decode("utf-8", "replace") if tail.strip(): print(tail) code = stdout.channel.recv_exit_status() print(f"build exit {code} in {time.time() - start:.1f}s") _, o, _ = client.exec_command( "curl -sS -m 8 -o /dev/null -w 'dashboard=%{http_code}' http://127.0.0.1:8001/hub/dashboard", timeout=15, ) print("health:", o.read().decode().strip()) client.close() return code if __name__ == "__main__": raise SystemExit(main())