29 lines
804 B
Python
29 lines
804 B
Python
"""Simple on-disk registry interface for GoC entries."""
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any, Dict, Union
|
|
|
|
from .dsl import RegistryEntry
|
|
|
|
|
|
def registry_path() -> Path:
|
|
return Path(os.environ.get("GOC_REGISTRY_PATH", "registry/registry.json"))
|
|
|
|
|
|
def load_registry() -> Dict[str, Any]:
|
|
path = registry_path()
|
|
if not path.exists():
|
|
return {}
|
|
with path.open("r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def save_registry(entry: Union[Dict[str, Any], RegistryEntry]) -> None:
|
|
path = registry_path()
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
payload = entry.to_dict() if isinstance(entry, RegistryEntry) else entry
|
|
with path.open("w", encoding="utf-8") as f:
|
|
json.dump(payload, f, indent=2, sort_keys=True)
|