-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup.py
More file actions
54 lines (46 loc) · 1.49 KB
/
cleanup.py
File metadata and controls
54 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""
项目清理脚本
"""
import os
import shutil
from pathlib import Path
def cleanup_project():
"""清理项目文件"""
project_root = Path(__file__).parent
# 要删除的文件和目录
cleanup_items = [
"output", # 输出目录
".cache", # 缓存目录
".env", # 环境变量文件
"__pycache__", # Python 缓存
"*.pyc", # 编译的 Python 文件
"*.pyo", # 优化的 Python 文件
]
print("🧹 开始清理项目...")
for item in cleanup_items:
if "*" in item:
# 处理通配符
pattern = item
for file_path in project_root.rglob(pattern):
if file_path.is_file():
print(f" 删除文件: {file_path}")
file_path.unlink()
else:
# 处理具体路径
path = project_root / item
if path.exists():
if path.is_dir():
print(f" 删除目录: {path}")
shutil.rmtree(path)
else:
print(f" 删除文件: {path}")
path.unlink()
# 清理 __pycache__ 目录
for pycache_dir in project_root.rglob("__pycache__"):
if pycache_dir.is_dir():
print(f" 删除缓存目录: {pycache_dir}")
shutil.rmtree(pycache_dir)
print("✅ 项目清理完成!")
if __name__ == "__main__":
cleanup_project()