File size: 3,081 Bytes
065e391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# =============================================================================
#  WARNING β€” RodSizer β€” Clear All Local History Data (Mac)
#  Double-click this file in Finder only if you want to delete local history.
# =============================================================================

cd "$(dirname "$0")"
PROJECT_DIR="$(pwd)"
BACKEND_DIR="$PROJECT_DIR/backend"
RESULTS_DIR="$PROJECT_DIR/results"
UPLOADS_DIR="$PROJECT_DIR/uploads"

RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
info()  { echo -e "${GREEN}[βœ“]${NC} $*"; }
warn()  { echo -e "${YELLOW}[!]${NC} $*"; }
error() { echo -e "${RED}[βœ—]${NC} $*"; }
step()  { echo -e "\n${CYAN}──────────────────────────────────────────${NC}"; echo -e "${CYAN}  $*${NC}"; echo -e "${CYAN}──────────────────────────────────────────${NC}"; }

pause_and_exit() {
    echo ""
    echo "Press Enter to close..."
    read -r
    exit "$1"
}

ensure_dir() {
    local dir="$1"
    [ -d "$dir" ] || mkdir -p "$dir"
}

clear_dir_contents() {
    local dir="$1"
    ensure_dir "$dir"
    find "$dir" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
}

step "WARNING β€” Clear All Local History Data"

echo "This is a destructive cleanup action."
echo "It will permanently remove local runtime history, including:"
echo "  - uploaded files in uploads/"
echo "  - generated results in results/"
echo "  - folder analysis cache (.analysis_cache)"
echo "  - backend/server.log"
echo "  - Python __pycache__ files"
echo ""
echo "It will NOT delete your installed Python packages in backend/.venv."
echo ""
read -r -p "Type YES to permanently delete the local history data: " CONFIRM

if [ "$CONFIRM" != "YES" ]; then
    warn "Cleanup cancelled."
    pause_and_exit 0
fi

step "Stopping local server if needed"

if lsof -ti:8000 &>/dev/null; then
    warn "Port 8000 is in use. Stopping the running app first..."
    lsof -ti:8000 | xargs kill -9 2>/dev/null
    sleep 1
fi

step "Removing local history files"

clear_dir_contents "$RESULTS_DIR"
clear_dir_contents "$UPLOADS_DIR"

find "$PROJECT_DIR" -type d -name ".analysis_cache" -prune -exec rm -rf {} +
find "$PROJECT_DIR" -type d -name "__pycache__" -prune -exec rm -rf {} +
find "$PROJECT_DIR" -type f -name "*.pyc" -delete

if [ -f "$BACKEND_DIR/server.log" ]; then
    rm -f "$BACKEND_DIR/server.log"
fi

ensure_dir "$RESULTS_DIR"
ensure_dir "$UPLOADS_DIR"

info "Local history data has been cleared."
info "Your virtual environment and installed packages were kept intact."

echo ""
echo -e "${GREEN}════════════════════════════════════════════${NC}"
echo -e "${GREEN}  Cleanup complete.${NC}"
echo -e "${GREEN}════════════════════════════════════════════${NC}"

pause_and_exit 0