# Helper utilities for robustness
def _enumerate_drives() -> list[str]:
"""Return list of available drive letters, e.g., ['C', 'D']"""
import ctypes
import string
bitmask = ctypes.windll.kernel32.GetLogicalDrives()
return [letter for i, letter in enumerate(string.ascii_uppercase) if bitmask & (1 << i)]
def _disk_usage_gb(root: str) -> tuple[float, float]:
"""Return used and free space in GB for a given root like 'C:\\'."""
import shutil
total, used, free = shutil.disk_usage(root)
gb = 1024 ** 3
return used / gb, free / gb
def _run_powershell(command: str, timeout: int = 10) -> str:
"""Run a PowerShell command using pwsh if available, else Windows PowerShell."""
import shutil as _shutil
import subprocess
shell = _shutil.which("pwsh") or "powershell"
result = subprocess.run(
[shell, "-NoProfile", "-Command", command],
capture_output=True,
text=True,
timeout=timeout,
check=True,
)
return result.stdout