Files
CapacityReport/scripts/clean.py
T
nixevol 22fbf47577 feat: 支持托管到Metrix应用包并移除授权与平台模式
- 新增 scripts/package_metrix.py 打包应用包(user_auth=metrix、admin_auth=none、数据目录 /data)
- 托管模式只认平台代理身份,停用应用登录与改密码,新增 /api/session
- 后端按 X-Forwarded-Prefix 注入 <base href>,前端改为相对路径构建并按 basePath 请求
- 托管时隐藏登录页、退出按钮和修改密码页,顶栏显示 Metrix 用户名
- 移除授权到期校验、激活码和连点品牌图标打开的授权延期窗口
- 移除 Metrix 平台数据源/仓库模式及相关配置、接口、设置页和 requests 依赖
- 新增托管鉴权与 base href 注入测试,更新使用与开发文档
2026-11-06 16:22:32 +08:00

92 lines
2.5 KiB
Python
Raw 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.
"""清理脚本:清除缓存、__pycache__、编译产物和运行时临时数据,保持项目整洁。
用法:
python scripts/clean.py # 清理缓存 / 编译产物 / 运行时临时数据(保留 .venv 与前端依赖)
python scripts/clean.py --deep # 额外清理 .venv 与 frontend/node_modules(下次运行会重装)
默认不会删除源码、配置(Configure.json/*.sql)、账号文件或 .git。
"""
from __future__ import annotations
import argparse
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import _env # noqa: E402
# 遍历时跳过这些目录(既慢又无意义)
PRUNE_DIRS = {".git", ".venv", "node_modules"}
# 编译产物 / 缓存目录(相对项目根)
ARTIFACT_DIRS = [
"dist",
"frontend/dist",
"frontend/.vite",
"src-tauri/target",
"src-tauri/binaries",
".ruff_cache",
".pytest_cache",
".mypy_cache",
]
# 运行时临时数据目录
RUNTIME_DIRS = ["cache", "logs", "uploads"]
DEEP_DIRS = [".venv", "frontend/node_modules"]
def clean_pycache() -> int:
removed = 0
for current, dirs, files in os.walk(_env.ROOT):
dirs[:] = [d for d in dirs if d not in PRUNE_DIRS]
for d in list(dirs):
if d == "__pycache__":
if _env.remove_path(Path(current) / d):
removed += 1
dirs.remove(d)
for f in files:
if f.endswith((".pyc", ".pyo")):
if _env.remove_path(Path(current) / f):
removed += 1
return removed
def clean_dirs(rel_dirs: list[str]) -> int:
removed = 0
for rel in rel_dirs:
if _env.remove_path(_env.ROOT / rel):
_env.info(f"已删除 {rel}")
removed += 1
return removed
def main() -> int:
_env.setup_console()
parser = argparse.ArgumentParser(description="清理缓存与编译产物")
parser.add_argument("--deep", action="store_true", help="额外清理 .venv 与 frontend/node_modules")
args = parser.parse_args()
_env.step("清理 __pycache__ / *.pyc")
n = clean_pycache()
_env.info(f"清理 {n} 项")
_env.step("清理编译产物")
clean_dirs(ARTIFACT_DIRS)
_env.step("清理运行时临时数据(cache / logs / uploads)")
clean_dirs(RUNTIME_DIRS)
if args.deep:
_env.step("深度清理依赖(.venv / node_modules)")
clean_dirs(DEEP_DIRS)
_env.step("清理完成")
return 0
if __name__ == "__main__":
raise SystemExit(main())