Files
brewpi/client/user_config.py
jens a44060a9bd gui: add a persisted user config; remember the last Sud file dialog dir
New client/user_config.py - a small JSON-backed key/value store at
~/.config/brewpi/gui.json for GUI preferences that should survive
restarts (distinct from the server's config.json and from sude/*.json
schedules). First use: Save/Load Sud's file dialogs now open in
whichever directory was last used, instead of always starting at cwd.
2026-06-21 11:46:01 +02:00

28 lines
780 B
Python

import json
from pathlib import Path
DEFAULT_PATH = Path.home() / ".config" / "brewpi" / "gui.json"
class UserConfig:
"""Small persisted key/value store for GUI preferences that should
survive across restarts (e.g. the last directory used for a file
dialog) - local user state, not version-controlled config."""
def __init__(self, path=DEFAULT_PATH):
self.path = path
self.data = {}
if self.path.exists():
try:
self.data = json.loads(self.path.read_text())
except (json.JSONDecodeError, OSError):
self.data = {}
def get(self, key, default=None):
return self.data.get(key, default)
def set(self, key, value):
self.data[key] = value
self.path.parent.mkdir(parents=True, exist_ok=True)
self.path.write_text(json.dumps(self.data, indent='\t'))