File size: 791 Bytes
ca9426f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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]}"