import json import os import threading from pathlib import Path KONFIG = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "raveos-center" FAJL = KONFIG / "beallitasok.json" _zar = threading.Lock() def _olvas(): try: return json.loads(FAJL.read_text()) except (OSError, ValueError): return {} def ertek(kulcs, alap=None): with _zar: return _olvas().get(kulcs, alap) def beallit(kulcs, ertek_): with _zar: adat = _olvas() adat[kulcs] = ertek_ KONFIG.mkdir(parents=True, exist_ok=True) ideiglenes = FAJL.with_suffix(".uj") ideiglenes.write_text(json.dumps(adat, ensure_ascii=False, indent=2)) os.replace(ideiglenes, FAJL)