| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/usr/bin/env python3
- """全站完整性扫描:逐文件对比本地与线上字节数,找出未真正上传的文件"""
- import os, subprocess, concurrent.futures, sys
- SITE = "/opt/data/projects/hardware-lab/site"
- BASE = "https://app.fmode.cn/dev/GvsWkfZb36"
- IDX_SIZE = os.path.getsize(os.path.join(SITE, "index.html"))
- files = []
- for root, dirs, names in os.walk(SITE):
- dirs[:] = [d for d in dirs if d != "node_modules"]
- for n in names:
- if n.endswith(".map"):
- continue
- p = os.path.join(root, n)
- rel = os.path.relpath(p, SITE)
- files.append((rel, os.path.getsize(p)))
- print(f"共 {len(files)} 个文件,index.html = {IDX_SIZE} 字节")
- def check(item):
- rel, local = item
- try:
- out = subprocess.run(
- ["curl", "-s", "-o", "/dev/null", "-w", "%{size_download}", "--max-time", "30",
- f"{BASE}/{rel}?t=1"],
- capture_output=True, text=True, timeout=40).stdout.strip()
- remote = int(out) if out.isdigit() else -1
- except Exception:
- remote = -1
- ok = (remote == local)
- fallback = (remote == IDX_SIZE and local != IDX_SIZE)
- return (rel, local, remote, ok, fallback)
- bad = []
- with concurrent.futures.ThreadPoolExecutor(max_workers=12) as ex:
- for rel, local, remote, ok, fallback in ex.map(check, files):
- if not ok:
- bad.append((rel, local, remote, "FALLBACK" if fallback else "MISSING"))
- print(f"\n{'='*70}")
- print(f"正常: {len(files) - len(bad)} / {len(files)}")
- print(f"异常: {len(bad)}")
- for rel, local, remote, kind in bad[:40]:
- print(f" {kind:9} {rel} 本地={local} 线上={remote}")
- if bad:
- with open("/opt/data/projects/hardware-lab/logs/missing.txt", "w") as f:
- for rel, _, _, _ in bad:
- f.write(rel + "\n")
- print(f"\n清单已写入 logs/missing.txt")
|