From a39ba7596a13c72ba8af1a968a45fd7ca9d31dfa Mon Sep 17 00:00:00 2001 From: Thierry Date: Wed, 1 Apr 2026 21:29:53 +0200 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