-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.py
More file actions
104 lines (89 loc) · 3.02 KB
/
cleanup.py
File metadata and controls
104 lines (89 loc) · 3.02 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
"""
Cleanup script to remove temporary files and cache directories.
This script removes:
- API capture files (api_interactions_*.jsonl, api_capture_*.log)
- Batch review results (batch_review_results*.json)
- Fine-tuning datasets (fine_tuning_dataset.jsonl)
- Python cache directories (__pycache__, .pytest_cache)
- Compiled Python files (*.pyc, *.pyo)
- IDE cache (.claude)
"""
import os
import shutil
import glob
from pathlib import Path
# Get project root
PROJECT_ROOT = Path(__file__).parent
def cleanup():
"""Remove temporary files and cache directories."""
print("\n" + "="*70)
print("CLEANUP: Removing Temporary Files and Cache")
print("="*70 + "\n")
# Files to remove (glob patterns)
file_patterns = [
"api_interactions_*.jsonl",
"api_capture_*.log",
"batch_review_results*.json",
"fine_tuning_dataset.jsonl",
"*.pyc",
"*.pyo",
"*.pyd",
]
# Directories to remove
dirs_to_remove = [
"__pycache__",
".pytest_cache",
".mypy_cache",
".claude",
".venv/__pycache__",
]
# Track what was removed
removed_files = 0
removed_dirs = 0
total_size = 0
# Remove files
print("Removing temporary files...")
for pattern in file_patterns:
for filepath in glob.glob(str(PROJECT_ROOT / pattern)):
try:
file_size = os.path.getsize(filepath)
os.remove(filepath)
removed_files += 1
total_size += file_size
print(f" [REMOVED] {Path(filepath).name}")
except Exception as e:
print(f" [ERROR] {Path(filepath).name}: {e}")
# Remove directories
print("\nRemoving cache directories...")
for dir_pattern in dirs_to_remove:
for dirpath in glob.glob(str(PROJECT_ROOT / "**" / dir_pattern), recursive=True):
if os.path.isdir(dirpath):
try:
# Calculate directory size
dir_size = sum(
f.stat().st_size
for f in Path(dirpath).rglob('*')
if f.is_file()
)
shutil.rmtree(dirpath)
removed_dirs += 1
total_size += dir_size
rel_path = os.path.relpath(dirpath, PROJECT_ROOT)
print(f" [REMOVED] {rel_path}/")
except Exception as e:
print(f" [ERROR] {dirpath}: {e}")
# Print summary
print("\n" + "="*70)
print("CLEANUP SUMMARY")
print("="*70)
print(f"Files removed: {removed_files}")
print(f"Directories removed: {removed_dirs}")
print(f"Space freed: {total_size / (1024*1024):.2f} MB")
print("="*70 + "\n")
if removed_files == 0 and removed_dirs == 0:
print("No temporary files or cache directories found.\n")
else:
print("Cleanup complete!\n")
if __name__ == "__main__":
cleanup()