Files
sanguo_vnpy_v2/scripts/nas_sync/vps_update_dist.py
T

35 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
"""VPS: 替换 frontend/dist 为最新构建(先备份旧版)。
用法(VPS 上): C:\\Python310\\python.exe -X utf8 C:\\sanguo_vnpy_v2\\scripts\\nas_sync\\vps_update_dist.py
输入: C:\\sanguo_vnpy_v2\\dist_latest.tgz (Mac 构建后 scp 上来的 tar 包, 内容为 dist 根)
输出: 尾行 DIST_UPDATE_DONE(成功标记, CI 用)
"""
import os
import re
import shutil
import tarfile
ROOT = r"C:\sanguo_vnpy_v2"
TGZ = os.path.join(ROOT, "dist_latest.tgz")
DIST = os.path.join(ROOT, "frontend", "dist")
BAK = os.path.join(ROOT, "frontend", "dist_bak")
if not os.path.exists(TGZ):
raise SystemExit(f"tgz not found: {TGZ}")
if os.path.exists(BAK):
shutil.rmtree(BAK)
if os.path.exists(DIST):
shutil.move(DIST, BAK)
print("old dist ->", BAK, flush=True)
os.makedirs(DIST, exist_ok=True)
with tarfile.open(TGZ) as t:
t.extractall(DIST)
idx = os.path.join(DIST, "index.html")
with open(idx, encoding="utf-8") as f:
head = f.read(400)
m = re.search(r"assets/index-[^\"']*", head)
print("new index:", m.group(0) if m else "?", flush=True)
print("DIST_UPDATE_DONE", flush=True)