Upload files to "backend/utils"

This commit is contained in:
Thierry 2026-04-01 21:29:53 +02:00
parent deec53617f
commit a39ba7596a

34
backend/utils/disk.py Normal file
View file

@ -0,0 +1,34 @@
import shutil
from pathlib import Path
from config import DATA_DIR, BASE_DIR
def get_disk_usage() -> float | str:
try:
stat = shutil.disk_usage(DATA_DIR)
return round(stat.free / (1024**3), 2)
except:
return "?"
def get_entwine_path() -> str | None:
import subprocess
try:
result = subprocess.run(["which", "entwine"],
capture_output=True, text=True, check=False)
if result.returncode == 0:
path = result.stdout.strip()
if path and Path(path).exists():
return path
except Exception:
pass
common_paths = [
"/usr/local/bin/entwine",
"/usr/bin/entwine",
str(BASE_DIR / "entwine"),
str(BASE_DIR / "bin" / "entwine"),
]
for path in common_paths:
if Path(path).exists():
return path
return None