douyinWEB/scripts/_clean_pve_nomad_android2.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

96 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
"""Finish Android/Gradle cleanup on PVE; report sizes."""
import sys, paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=30, allow_agent=False, look_for_keys=False)
script = r'''
set +e
HOME_DIR=/home/eric
PROJ=/home/eric/projects/nomadLifeApp2
echo '===== CURRENT ====='
df -h /
du -sh "$HOME_DIR" 2>/dev/null
du -sh "$HOME_DIR/.gradle" "$PROJ" 2>/dev/null
du -sh "$PROJ/android" "$PROJ/android/app/build" "$PROJ/node_modules" 2>/dev/null
ls -la "$HOME_DIR/.gradle" 2>/dev/null | head -20
ls -la "$PROJ/android" 2>/dev/null | head -20
echo
echo '===== TOP under home ====='
du -h --max-depth=2 "$HOME_DIR" 2>/dev/null | sort -hr | head -25
echo
echo '===== TOP under android ====='
du -h --max-depth=2 "$PROJ/android" 2>/dev/null | sort -hr | head -20
echo
echo '===== TOP under node_modules (android-ish) ====='
du -sh "$PROJ"/node_modules/*/android 2>/dev/null | sort -hr | head -20
du -sh "$PROJ"/node_modules/@*/*/android 2>/dev/null | sort -hr | head -20
echo
echo '===== REMOVE remaining gradle + android builds ====='
# ensure gradle caches gone
rm -rf "$HOME_DIR/.gradle/caches" "$HOME_DIR/.gradle/daemon" \
"$HOME_DIR/.gradle/native" "$HOME_DIR/.gradle/workers" \
"$HOME_DIR/.gradle/.tmp" "$HOME_DIR/.gradle/notifications"
# android project
rm -rf "$PROJ/android/app/build" "$PROJ/android/build" \
"$PROJ/android/.gradle" "$PROJ/android/app/.cxx" "$PROJ/android/.cxx"
# only android/build and android/.cxx under node_modules — not JS package "build/"
python3 - <<'PY'
import os, shutil
root = "/home/eric/projects/nomadLifeApp2/node_modules"
removed = 0
bytes_ = 0
if os.path.isdir(root):
for dirpath, dirnames, filenames in os.walk(root):
base = os.path.basename(dirpath)
parent = os.path.basename(os.path.dirname(dirpath))
# .../something/android/build or .../android/.cxx
if parent == "android" and base in ("build", ".cxx", ".gradle"):
# rough size
for r, ds, fs in os.walk(dirpath):
for f in fs:
try:
bytes_ += os.path.getsize(os.path.join(r, f))
except OSError:
pass
shutil.rmtree(dirpath, ignore_errors=True)
removed += 1
# don't descend
dirnames[:] = []
print(f"removed {removed} android native dirs, ~{bytes_/1024/1024:.0f} MB")
PY
# expo caches
rm -rf "$PROJ/.expo" "$HOME_DIR/.expo" "$HOME_DIR/.android/build-cache" 2>/dev/null
sync
echo
echo '===== AFTER ====='
df -h /
du -sh "$HOME_DIR" "$HOME_DIR/.gradle" "$PROJ" "$PROJ/android" "$PROJ/node_modules" 2>/dev/null
echo DONE
'''
sftp = c.open_sftp()
with sftp.file("/tmp/_clean_nomad_android2.sh", "w") as f:
f.write(script)
sftp.chmod("/tmp/_clean_nomad_android2.sh", 0o755)
sftp.close()
_, o, e = c.exec_command("bash /tmp/_clean_nomad_android2.sh", timeout=600)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("STDERR", err[-3000:])
c.close()