Files

87 lines
3.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""按本次口径重打 1.zip:最新代码,不含安装包(160MB 抓包工具)与任何数据/凭据。
范围与 pack_zip.ps1 一致(源码+模板+静态+测试+脚本),额外排除:
- downloads/*.exe 安装包(用户本次明确要求不带)
- *.db / *.db-* 数据库(含 WAL/SHM 旁文件)
- *.pem *.key *.crt 密钥与证书
- token/smtp/admin/secret 配置及其 .old-bak 备份
- __pycache__/.pytest_cache/.reasonix/backups/日志/临时产物
打包后逐条目审计 + 解压冒烟(init_db + pytest 采集)确保可运行。
"""
import zipfile
from pathlib import Path
ROOT = Path(__file__).parent.parent
ZIP = ROOT / "1.zip"
EXCLUDE_DIR_PARTS = {"__pycache__", ".pytest_cache", ".reasonix", "backups",
"artifacts", ".git", "downloads"}
EXCLUDE_SUFFIX = (".pyc", ".pyo", ".log", ".tmp", ".bak", ".zip", ".db", ".db-wal",
".db-shm", ".pem", ".key", ".crt", ".exe", ".sqlite")
EXCLUDE_NAMES = {"token_config.txt", "token_config.txt.old-bak", "smtp_config.txt",
"admin_config.txt", "secret_key.txt", "users.db", "bikes.db",
"server_config.json.keep", ".pack_baseline.json.keep"}
# scripts/.pack_baseline.json 是打包增量快照(运行时产物),一并排除
EXCLUDE_NAMES.add(".pack_baseline.json")
def excluded(rel: Path) -> bool:
parts = set(rel.parts)
if parts & EXCLUDE_DIR_PARTS:
return True
if rel.name in EXCLUDE_NAMES:
return True
if rel.suffix.lower() in EXCLUDE_SUFFIX:
return True
# token/smtp/admin/secret 任何变体
stem = rel.name.lower()
if any(stem.startswith(p) for p in
("token_config", "smtp_config", "admin_config", "secret_key")):
return True
return False
files = []
for p in sorted(ROOT.rglob("*")):
if not p.is_file():
continue
rel = p.relative_to(ROOT)
if excluded(rel):
continue
files.append((p, rel.as_posix()))
if ZIP.exists():
ZIP.unlink()
with zipfile.ZipFile(ZIP, "w", zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
for p, arc in files:
zf.write(p, arc)
# ---------- 审计 ----------
zf = zipfile.ZipFile(ZIP)
names = zf.namelist()
size_mb = ZIP.stat().st_size / 1048576
print(f"✓ 1.zip 重打包完成: {len(names)} 个文件, {size_mb:.1f} MB")
bad = [n for n in names
if n.lower().endswith((".exe", ".db", ".pem", ".key", ".crt", ".zip", ".log"))
or any(k in n.lower() for k in
("token_config", "smtp_config", "admin_config", "secret_key",
"users.db", "pack_baseline"))]
print(f"敏感/大文件审计: {'发现!! ' + str(bad) if bad else '干净(无 exe/db/密钥/token)'}")
required = ["app.py", "db.py", "campus.py", "alerts.py", "subscribe.py",
"wechat.py", "timer.py", "email_utils.py", "email_verify.py",
"routes/rental.py", "routes/admin.py", "routes/share.py",
"routes/auth.py", "routes/map_api.py", "routes/export.py",
"routes/subscribe.py", "routes/download.py",
"templates/map.html", "templates/admin.html", "templates/analysis.html",
"static/js/map.js", "static/css/map.css",
"scripts/pack_zip.ps1", "tests/test_history_30d.py",
"tests/test_rounds_and_preview.py", "tests/test_code_mail.py"]
missing = [r for r in required if r not in names]
print(f"关键文件校验: {'缺失!! ' + str(missing) if missing else '全部在位'}")
zf.close()