Files
geminux/scripts/test-theme-dunst-sync.py
T

73 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python3
"""Verify all Geminux .xth themes and dunst theme synchronization."""
import glob
import os
import re
import subprocess
import sys
import tempfile
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
THEMES_DIR = os.path.join(BASE_DIR, "overlay", "rootfs", "etc", "skel", ".xthemes")
SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-dunst-theme")
REQUIRED_KEYS = (
"theme.name", "theme.fontFace", "theme.iconFontFace", "theme.baseFontSize",
"theme.bgMain", "theme.bgBar", "theme.bgHeader", "theme.bgOverlay",
"theme.fgMain", "theme.fgBright", "theme.fgMuted", "theme.selBg", "theme.selFg",
"theme.accent", "theme.border", "theme.danger", "theme.dangerBg",
"dmenu.font", "dmenu.background", "dmenu.foreground", "dmenu.selbackground", "dmenu.selforeground",
"dwm.font", "dwm.normbgcolor", "dwm.normfgcolor", "dwm.selbgcolor", "dwm.selfgcolor",
"st.font", "st.background", "st.foreground", "st.cursorColor", "Xft.dpi",
)
HEX_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
def parse_xres(path):
vals = {}
with open(path) as f:
for line in f:
line = line.strip()
if not line or line.startswith("!") or line.startswith("#") or ":" not in line:
continue
k, v = line.split(":", 1)
vals[k.strip()] = v.strip()
return vals
def main():
themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth")))
assert len(themes) >= 20, f"Expected >= 20 themes, found {len(themes)}"
with tempfile.TemporaryDirectory(prefix="geminux-dunst-test-") as tmp:
for th in themes:
vals = parse_xres(th)
for req in REQUIRED_KEYS:
assert req in vals and vals[req], f"Missing {req} in {os.path.basename(th)}"
assert "Fira Code" in vals["theme.fontFace"], f"Expected Fira Code in {os.path.basename(th)}"
assert "Fira Code" in vals["st.font"], f"Expected Fira Code in st.font of {os.path.basename(th)}"
assert "Fira Code" in vals["dmenu.font"], f"Expected Fira Code in dmenu.font of {os.path.basename(th)}"
assert "Fira Code" in vals["dwm.font"], f"Expected Fira Code in dwm.font of {os.path.basename(th)}"
for color_key in ("theme.bgMain", "theme.fgMain", "theme.accent", "theme.danger"):
assert HEX_RE.match(vals[color_key]), f"Invalid hex color {color_key}={vals[color_key]} in {th}"
dunstrc = os.path.join(tmp, f"{os.path.basename(th)}.dunstrc")
env = dict(os.environ, GEMINUX_XRESOURCES=th, GEMINUX_DUNSTRC=dunstrc)
subprocess.run([SYNC_SCRIPT, "--no-restart"], env=env, check=True)
with open(dunstrc) as df:
txt = df.read()
assert vals["theme.accent"] in txt
assert vals["theme.bgMain"] in txt
assert vals["theme.dangerBg"] in txt
assert "font = Fira Code " in txt
assert "width = 560" in txt
print(f"[PASS] Verified {len(themes)} .xth themes and dunst synchronization")
return 0
if __name__ == "__main__":
sys.exit(main())