chore: remove dead supervisor analytics and archived tooling
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _data_dir() -> Path:
|
||||
root = Path(os.getenv("CC_DATA_DIR", ".data")).resolve()
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
return root
|
||||
|
||||
|
||||
def _file_path(name: str) -> Path:
|
||||
safe = name.replace("\\", "_").replace("/", "_")
|
||||
return _data_dir() / safe
|
||||
|
||||
|
||||
def load_json(name: str, default: Any) -> Any:
|
||||
path = _file_path(name)
|
||||
if not path.exists():
|
||||
return copy.deepcopy(default)
|
||||
try:
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
return copy.deepcopy(default)
|
||||
|
||||
|
||||
def save_json(name: str, data: Any) -> None:
|
||||
path = _file_path(name)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with NamedTemporaryFile("w", encoding="utf-8", delete=False, dir=str(path.parent)) as tmp:
|
||||
json.dump(data, tmp, ensure_ascii=False, indent=2)
|
||||
tmp_path = Path(tmp.name)
|
||||
|
||||
tmp_path.replace(path)
|
||||
Reference in New Issue
Block a user