Upload files to "backend/utils"
This commit is contained in:
parent
deec53617f
commit
a39ba7596a
1 changed files with 34 additions and 0 deletions
34
backend/utils/disk.py
Normal file
34
backend/utils/disk.py
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue