# -*- coding: utf-8 -*- from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) def run(cmd: str, timeout: int = 420) -> str: _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace").strip() # Stash dirty code-only files (not data). Preserve stash for recovery. print( "[stash]", run( "cd /opt/douyinWEB && " "git stash push -m 'auto-before-caption-pool-04dc572' -- " "backend/app/main.py backend/app/notify.py backend/app/ops_panel.py " "frontend/src/app/layout.tsx frontend/src/app/ops/page.tsx frontend/src/components/Shell.tsx" ), ) print( "[pull]", run("cd /opt/douyinWEB && git pull --ff-only origin test1 && git log --oneline -2"), ) print("[restart api]") run("systemctl restart douyinweb-api") for i in range(30): st = run("systemctl is-active douyinweb-api", timeout=20) print("api", i, st) if st == "active": break time.sleep(2) print( "[seed]", run( r"""cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY' from app import db, caption_pool db.init_db() print(caption_pool.pool_stats()) for i in range(3): print('pick', caption_pool.pick_caption('x', custom='street food')) PY""" ), ) print("[npm build]") build = run("cd /opt/douyinWEB/frontend && npm run build", timeout=360) for line in build.splitlines()[-20:]: print(line.encode("ascii", "replace").decode("ascii")) run("systemctl restart douyinweb-web") time.sleep(4) print("[ok]", run("systemctl is-active douyinweb-api douyinweb-web; cd /opt/douyinWEB && git log --oneline -1")) c.close() print("DONE")