summaryrefslogtreecommitdiffstats
path: root/hyprsunset_qt/config.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-17 10:04:37 +0200
committerDanilo M. <danix@danix.xyz>2026-07-17 10:04:37 +0200
commit7548ce1bfd4496d7cb035706307d709801a54a30 (patch)
tree689652b8245397c41a3307523f5e25e8b70803c3 /hyprsunset_qt/config.py
parent85bdcf48d91fedf32d09c64707c1e206e4347e54 (diff)
downloadhyprsunset-qt-7548ce1bfd4496d7cb035706307d709801a54a30.tar.gz
hyprsunset-qt-7548ce1bfd4496d7cb035706307d709801a54a30.zip
feat: read/write hyprsunset.conf
Add read_config() and write_config() functions for managing hyprsunset configuration files. Implements file I/O operations with automatic parent directory creation and CONFIG_PATH default to ~/.config/hypr/hyprsunset.conf. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'hyprsunset_qt/config.py')
-rw-r--r--hyprsunset_qt/config.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/hyprsunset_qt/config.py b/hyprsunset_qt/config.py
index f8ad5cf..a718861 100644
--- a/hyprsunset_qt/config.py
+++ b/hyprsunset_qt/config.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import re
from dataclasses import dataclass
+from pathlib import Path
_BLOCK_RE = re.compile(r"profile\s*\{(.*?)\}", re.DOTALL)
@@ -82,3 +83,19 @@ def night_index(profiles: list[Profile]) -> int | None:
if p.temperature is not None:
return i
return None
+
+
+CONFIG_PATH = Path.home() / ".config" / "hypr" / "hyprsunset.conf"
+
+
+def read_config(path: Path = CONFIG_PATH) -> list[Profile]:
+ path = Path(path)
+ if not path.exists():
+ return []
+ return parse_config(path.read_text())
+
+
+def write_config(profiles: list[Profile], path: Path = CONFIG_PATH) -> None:
+ path = Path(path)
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(serialize(profiles))