mirror of
https://github.com/HuangYuChuh/ComfyUI_Skills_OpenClaw.git
synced 2026-07-30 19:49:07 +00:00
feat: add shared utility modules
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Shared helpers for CLI scripts."""
|
||||
@@ -0,0 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
CONFIG_PATH = BASE_DIR / "config.json"
|
||||
OUTPUTS_DIR = BASE_DIR / "outputs"
|
||||
DEFAULT_COMFYUI_SERVER_URL = "http://127.0.0.1:8188"
|
||||
|
||||
|
||||
def default_config() -> dict[str, str]:
|
||||
return {
|
||||
"comfyui_server_url": DEFAULT_COMFYUI_SERVER_URL,
|
||||
"output_dir": str(OUTPUTS_DIR),
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
def load_json(path: str | Path) -> Any:
|
||||
with Path(path).open("r", encoding="utf-8") as file:
|
||||
return json.load(file)
|
||||
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from shared.config import CONFIG_PATH, default_config
|
||||
from shared.json_utils import load_json
|
||||
|
||||
|
||||
def get_runtime_config() -> dict[str, str]:
|
||||
if not CONFIG_PATH.exists():
|
||||
return default_config()
|
||||
|
||||
loaded = load_json(CONFIG_PATH)
|
||||
if not isinstance(loaded, dict):
|
||||
return default_config()
|
||||
|
||||
defaults = default_config()
|
||||
return {
|
||||
"comfyui_server_url": str(loaded.get("comfyui_server_url") or defaults["comfyui_server_url"]),
|
||||
"output_dir": str(loaded.get("output_dir") or defaults["output_dir"]),
|
||||
}
|
||||
Reference in New Issue
Block a user