Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 4,423 Bytes
61d29fc | 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 105 106 107 108 109 110 111 112 113 | #!/bin/bash
# Free up disk space by removing packages/compiled files ONLY
# Does NOT delete any source data
set -e
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$PROJECT_ROOT"
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BLUE}π§Ή Disk Space Cleanup (Safe - No Source Data Loss)${NC}"
echo -e "${BLUE}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
echo -e "${YELLOW}This script only removes:${NC}"
echo -e " β Old Python packages (venv/)"
echo -e " β Compiled Python bytecode (__pycache__, *.pyc)"
echo -e " β Node.js packages (node_modules/) - optional"
echo ""
echo -e "${GREEN}All source data will be preserved!${NC}"
echo ""
# Calculate sizes before
BEFORE=$(du -sh . 2>/dev/null | cut -f1)
echo -e "${YELLOW}Current project size: $BEFORE${NC}"
echo ""
FREED=0
# 1. Remove old venv (using .venv now)
if [ -d "venv" ]; then
SIZE=$(du -sh venv 2>/dev/null | cut -f1)
echo -e "${GREEN}Removing old venv/ directory ($SIZE)...${NC}"
rm -rf venv
echo " β Removed venv/"
FREED=$((FREED + 6300))
else
echo " β venv/ not found (already removed)"
fi
# 2. Do NOT remove LocalView cache - it's source data
echo -e "${BLUE}Preserving data/cache/localview/ (source data)${NC}"
# 2. Do NOT remove LocalView cache - it's source data
echo -e "${BLUE}Preserving data/cache/localview/ (source data)${NC}"
# 3. Remove Python cache files
echo -e "${GREEN}Removing Python cache files...${NC}"
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -exec rm -f {} + 2>/dev/null || true
echo " β Removed __pycache__ directories and .pyc files"
# 4. Remove node_modules (can reinstall with npm install)
read -p "Remove node_modules? (can reinstall in 2 min with npm install) [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -d "frontend/node_modules" ]; then
SIZE=$(du -sh frontend/node_modules 2>/dev/null | cut -f1)
echo -e "${GREEN}Removing frontend/node_modules ($SIZE)...${NC}"
rm -rf frontend/node_modules
echo " β Removed frontend/node_modules"
FREED=$((FREED + 641))
fi
if [ -d "website/node_modules" ]; then
SIZE=$(du -sh website/node_modules 2>/dev/null | cut -f1)
echo -e "${GREEN}Removing website/node_modules ($SIZE)...${NC}"
rm -rf website/node_modules
echo " β Removed website/node_modules"
FREED=$((FREED + 907))
fi
else
echo " β Skipped node_modules removal"
fi
echo ""
echo -e "${BLUE}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BLUE}β
Cleanup Complete! All Source Data Preserved${NC}"
echo -e "${BLUE}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
# Calculate sizes after
AFTER=$(du -sh . 2>/dev/null | cut -f1)
echo -e "${GREEN}Project size before: $BEFORE${NC}"
echo -e "${GREEN}Project size after: $AFTER${NC}"
echo -e "${GREEN}Freed approximately: ${FREED} MB (~$((FREED/1024)) GB)${NC}"
echo ""
# Show current disk space
df -h . | grep -v Filesystem
echo ""
echo -e "${YELLOW}Protected source data:${NC}"
echo -e " ${BLUE}β data/cache/form990_gt_index.parquet (925 MB)${NC}"
echo -e " ${BLUE}β data/cache/irs_bmf/ (295 MB)${NC}"
echo -e " ${BLUE}β data/cache/localview/ (5.9 GB) - meeting minutes${NC}"
echo -e " ${BLUE}β data/cache/census/ (15 MB)${NC}"
echo -e " ${BLUE}β data/gold/ (1.7 GB) - enriched data${NC}"
echo ""
if [[ $FREED -gt 1000 ]]; then
echo -e "${YELLOW}To reinstall dependencies:${NC}"
echo -e " ${BLUE}cd frontend && npm install && cd ..${NC}"
echo -e " ${BLUE}cd website && npm install && cd ..${NC}"
echo ""
fi
|