From 3543e5dc0b12fa1b5b92fb483294c2ab2a93b61b Mon Sep 17 00:00:00 2001 From: Thierry Date: Thu, 26 Mar 2026 11:40:44 +0100 Subject: [PATCH] Upload files to "backend/utils" --- backend/utils/disk.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 backend/utils/disk.py diff --git a/backend/utils/disk.py b/backend/utils/disk.py new file mode 100644 index 0000000..9f7e603 --- /dev/null +++ b/backend/utils/disk.py @@ -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 \ No newline at end of file