import os import shutil import time from pathlib import Path def safe_mkdir(p: str) -> str: Path(p).mkdir(parents=True, exist_ok=True) return p def now_ts() -> str: return time.strftime("%Y%m%d-%H%M%S") def rmtree(path: str): try: shutil.rmtree(path) except Exception: pass def find_any_apk(root: str) -> str | None: root_path = Path(root) apks = list(root_path.rglob("*.apk")) if not apks: return None # Elige el más reciente apks.sort(key=lambda p: p.stat().st_mtime, reverse=True) return str(apks[0]) def human_bytes(n: int) -> str: unit = ["B", "KB", "MB", "GB", "TB"] i = 0 x = float(n) while x >= 1024 and i < len(unit) - 1: x /= 1024 i += 1 return f"{x:.2f} {unit[i]}"