Py2exe-GUI/dev_scripts/clear_cache.py
muzing 72990a0680 Update dev scripts
更新开发辅助脚本:
将所有用到的相对路径存储至统一位置;
将所有检查函数的名称与返回值行为统一;
添加 `check_license_statement()` 函数;
2023-12-04 21:54:06 +08:00

42 lines
1.1 KiB
Python

import os
from pathlib import Path
from shutil import rmtree
from dev_scripts.path_constants import SRC_PATH
def clear_pyinstaller_dist(src_path: Path) -> None:
"""
清理开发过程中测试运行时的打包中间文件及结果文件 \n
:param src_path: Py2exe-GUI.py 运行目录
"""
dist_path = src_path / Path("dist")
build_path = src_path / Path("build")
spec_path_list = list(src_path.glob("*.spec"))
if dist_path.exists():
rmtree(dist_path)
if build_path.exists():
rmtree(build_path)
if spec_path_list:
for spec_file in spec_path_list:
os.remove(spec_file)
print("Pyinstaller dist all cleaned.")
def clear_pycache(src_path: Path) -> None:
"""
清理给定路径下的所有 .pyc .pyo 文件与 __pycache__ 目录 \n
ref: https://stackoverflow.com/a/41386937
:param src_path: 源码 src 目录路径
"""
[p.unlink() for p in src_path.rglob("*.py[co]")]
[p.rmdir() for p in src_path.rglob("__pycache__")]
print("PyCache all cleaned.")
if __name__ == "__main__":
clear_pyinstaller_dist(SRC_PATH)
clear_pycache(SRC_PATH)