-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup_reports.py
More file actions
94 lines (73 loc) · 2.85 KB
/
cleanup_reports.py
File metadata and controls
94 lines (73 loc) · 2.85 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
#!/usr/bin/env python3
"""
Script to clean up existing reports and visualizations.
"""
import sys
from pathlib import Path
from loguru import logger
# Add src to path for imports
sys.path.append(str(Path(__file__).parent / "src"))
from config.settings import settings
def cleanup_reports():
"""Clean up existing reports and visualizations."""
logger.info("Starting cleanup of existing reports and visualizations")
reports_dir = Path(settings.output_dir)
dashboard_static_dir = Path(settings.dashboard_static_dir)
# Files to delete patterns
patterns_to_delete = [
"*_analysis_*.json",
"*_insights_*.txt",
"*.png",
"*.jpg",
"*.jpeg",
"*.csv"
]
deleted_count = 0
# Clean up reports directory
if reports_dir.exists():
logger.info(f"Cleaning up reports directory: {reports_dir}")
for pattern in patterns_to_delete:
for file_path in reports_dir.glob(pattern):
try:
file_path.unlink()
logger.info(f"Deleted: {file_path.name}")
deleted_count += 1
except Exception as e:
logger.warning(f"Could not delete {file_path.name}: {e}")
else:
logger.warning(f"Reports directory does not exist: {reports_dir}")
# Clean up dashboard static directory
if dashboard_static_dir.exists():
logger.info(f"Cleaning up dashboard static directory: {dashboard_static_dir}")
for pattern in patterns_to_delete:
for file_path in dashboard_static_dir.glob(pattern):
try:
file_path.unlink()
logger.info(f"Deleted from dashboard: {file_path.name}")
deleted_count += 1
except Exception as e:
logger.warning(f"Could not delete {file_path.name} from dashboard: {e}")
else:
logger.warning(f"Dashboard static directory does not exist: {dashboard_static_dir}")
logger.info(f"Cleanup completed. Deleted {deleted_count} files")
return deleted_count
def main():
"""Main function."""
try:
# Setup logging
logger.add("logs/cleanup.log", rotation="1 day", retention="30 days")
# Ensure directories exist
settings.ensure_directories()
print("🧹 Starting Report Cleanup")
print("=" * 40)
deleted_count = cleanup_reports()
print(f"\n✅ Cleanup completed successfully!")
print(f"📊 Files deleted: {deleted_count}")
if deleted_count == 0:
print("ℹ️ No files were found to delete")
except Exception as e:
logger.error(f"Error during cleanup: {e}")
print(f"❌ Error during cleanup: {e}")
sys.exit(1)
if __name__ == "__main__":
main()