blu-assistant / src /blu /adapter_manager.py
Aravindhan11's picture
Upload 33 files
9776024 verified
raw
history blame contribute delete
940 Bytes
import os, subprocess
from typing import Optional
ADAPTER_DIR = ".config/adapters"
def list_adapters():
if not os.path.exists(ADAPTER_DIR):
return []
return [d for d in os.listdir(ADAPTER_DIR) if os.path.isdir(os.path.join(ADAPTER_DIR, d))]
def adapter_path(name: str):
p = os.path.join(ADAPTER_DIR, name)
return p if os.path.exists(p) else None
def install_adapter_from_remote(url: str, name: str):
os.makedirs(ADAPTER_DIR, exist_ok=True)
tarball = os.path.join(ADAPTER_DIR, f"{name}.zip")
try:
subprocess.check_call(["wget", "-O", tarball, url])
except Exception:
try:
subprocess.check_call(["curl", "-L", url, "-o", tarball])
except Exception as e:
raise RuntimeError("download failed: " + str(e))
subprocess.check_call(["unzip", "-o", tarball, "-d", os.path.join(ADAPTER_DIR, name)])
return adapter_path(name)