#!/usr/bin/env python3
"""Recon the BC-250 for PyTorch/ComfyUI installation."""
import paramiko, sys

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.178.150', username='fabian', key_filename=r'C:\Users\fabia\.ssh\id_ed25519')

cmds = [
    ("Python version", "python3 --version 2>&1"),
    ("pip version", "pip --version 2>&1 || pip3 --version 2>&1"),
    ("Disk space", "df -h / /home 2>&1"),
    ("RAM", "free -h 2>&1"),
    ("CPU cores", "nproc 2>&1"),
    ("ROCm version", "cat /opt/rocm/.info/version 2>/dev/null || echo 'no version file'; ls /opt/rocm/lib/libamdhip64.so* 2>&1"),
    ("hipcc", "which hipcc 2>&1 && hipcc --version 2>&1 | head -5"),
    ("rocminfo GPU", "HSA_OVERRIDE_GFX_VERSION=10.1.0 rocminfo 2>&1 | grep -E 'Marketing|gfx|Name:' | head -10"),
    ("Existing PyTorch", "python3 -c 'import torch; print(torch.__version__); print(torch.cuda.is_available()); print(torch.version.hip)' 2>&1"),
    ("Existing venvs", "ls -la ~/venv* ~/env* ~/.local/lib/python*/site-packages/torch* 2>&1 | head -20"),
    ("git version", "git --version 2>&1"),
    ("cmake version", "cmake --version 2>&1 | head -1"),
    ("ninja version", "ninja --version 2>&1"),
    ("Available Python packages", "python3 -m venv --help >/dev/null 2>&1 && echo 'venv OK' || echo 'venv missing'"),
    ("Swap", "swapon --show 2>&1"),
    ("GPU device check", "ls -la /dev/kfd /dev/dri/render* 2>&1"),
    ("Existing ComfyUI", "ls -la ~/ComfyUI 2>&1 || echo 'not found'"),
    ("pacman cmake/ninja", "pacman -Q cmake ninja 2>&1"),
]

for label, cmd in cmds:
    print(f"\n{'='*60}")
    print(f"  {label}")
    print(f"{'='*60}")
    _, stdout, stderr = ssh.exec_command(cmd, timeout=30)
    out = stdout.read().decode()
    err = stderr.read().decode()
    if out.strip():
        print(out.strip())
    if err.strip():
        print(f"STDERR: {err.strip()}")

ssh.close()
print("\n\nDone.")
