Prefer location.assign for endscreen leave, and ship hub analytics/charts plus host deploy helpers. Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
import io
|
|
import posixpath
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
HOST, USER, PASS = "10.88.0.8", "eric", "4669805"
|
|
REMOTE = "/opt/live/d2ypp"
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def main() -> int:
|
|
files = [
|
|
"web-console/components/live-product/LiveYoutubeRelayLogView.tsx",
|
|
"web-console/components/live-product/LiveYoutubeRelayLogCharts.tsx",
|
|
"src/youtube_relay_log.py",
|
|
"src/hub_routes.py",
|
|
"web.py",
|
|
]
|
|
out = REPO / "web-console" / "out"
|
|
for p in out.rglob("*"):
|
|
if p.is_file():
|
|
files.append(str(p.relative_to(REPO)).replace("\\", "/"))
|
|
files = sorted(set(files))
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=20)
|
|
sftp = c.open_sftp()
|
|
|
|
def mkdir_p(d: str) -> None:
|
|
d = d.rstrip("/")
|
|
cur = ""
|
|
for part in [x for x in d.split("/") if x]:
|
|
cur = f"{cur}/{part}" if cur else f"/{part}"
|
|
try:
|
|
sftp.stat(cur)
|
|
except OSError:
|
|
try:
|
|
sftp.mkdir(cur)
|
|
except OSError:
|
|
pass
|
|
|
|
for rel in files:
|
|
local = REPO / rel
|
|
if not local.is_file():
|
|
continue
|
|
remote = f"{REMOTE}/{rel}"
|
|
mkdir_p(posixpath.dirname(remote))
|
|
data = local.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
sftp.putfo(io.BytesIO(data), remote)
|
|
sftp.close()
|
|
print(f"uploaded {len(files)}")
|
|
|
|
def run(cmd: str, timeout: int = 120) -> str:
|
|
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
print(run(f"echo {PASS!r} | sudo -S -p '' systemctl restart live-console.service"))
|
|
time.sleep(9)
|
|
print(run("curl -sf -m 5 http://127.0.0.1:8001/health; echo"))
|
|
print(run("curl -sS -m 8 -o /dev/null -w 'page=%{http_code}\\n' http://127.0.0.1:8001/youtube-relay-log"))
|
|
print(
|
|
run(
|
|
"curl -sS -m 10 'http://127.0.0.1:8001/hub/youtube/relay/sessions/stats?top_anchors=5' "
|
|
"| python3 -c \"import sys,json; d=json.load(sys.stdin); print(d['overview']); "
|
|
"print([(a['anchor_name'], a['sessions'], round(a['hours_total'],1)) for a in d['top_anchors']])\""
|
|
)
|
|
)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|