# -*- coding: utf-8 -*- from __future__ import annotations import time from pathlib import Path import paramiko REPO = Path(__file__).resolve().parents[3] HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( HOST, username=USER, password=PASS, timeout=60, allow_agent=False, look_for_keys=False, ) sftp = c.open_sftp() for rel in ("live.py", "routers/api.py"): local = REPO / "apps/api/services/social_svc" / rel remote = f"/tmp/social_{rel.replace('/', '_')}" with sftp.file(remote, "wb") as rf: rf.write(local.read_bytes()) print("up", remote, flush=True) sftp.close() cmd = r""" set -e B=/var/www/nomadro.cn/apps/api/services/social_svc sudo cp /tmp/social_live.py "$B/live.py" sudo cp /tmp/social_routers_api.py "$B/routers/api.py" sudo systemctl restart nomadro-social sleep 2 curl -sk --max-time 8 -X POST 'https://api.nomadro.cn/api/social/v1/live/rooms/office/join?guest=camtest1' \ -H 'Content-Type: application/json' --data-binary '{"nick":"cam"}' | head -c 360; echo """ _, stdout, _ = c.exec_command(cmd, timeout=60, get_pty=True) while not stdout.channel.exit_status_ready(): if stdout.channel.recv_ready(): print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True) time.sleep(0.05) while stdout.channel.recv_ready(): print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True) print("[exit", stdout.channel.recv_exit_status(), "]", flush=True) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())