147 lines
6.7 KiB
Python
Executable File
147 lines
6.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Verify all Geminux .xth themes, dunst synchronization, and GTK2/GTK3 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")
|
|
GTK_SYNC_SCRIPT = os.path.join(BASE_DIR, "overlay", "rootfs", "usr", "bin", "geminux-sync-gtk-theme")
|
|
|
|
LIGHT_THEMES = frozenset({"CatppuccinLatte", "GruvboxLight", "SolarizedLight"})
|
|
|
|
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 idx, th in enumerate(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 int(vals["Xft.dpi"]) >= 168, f"Expected Xft.dpi >= 168 in {os.path.basename(th)}"
|
|
assert int(vals["theme.baseFontSize"]) >= 28, f"Expected baseFontSize >= 28 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 = 720" in txt
|
|
|
|
th_home = os.path.join(tmp, f"home-{idx}")
|
|
os.makedirs(th_home, exist_ok=True)
|
|
gtk_env = {
|
|
k: v for k, v in os.environ.items()
|
|
if k not in (
|
|
"GEMINUX_GTK_THEMES_DIR", "GEMINUX_XDG_THEMES_DIR",
|
|
"GEMINUX_GTK2_RC", "GEMINUX_GTK3_DIR", "GEMINUX_XSETTINGSD_CONF",
|
|
)
|
|
}
|
|
gtk_env["HOME"] = th_home
|
|
gtk_env["GEMINUX_XRESOURCES"] = th
|
|
subprocess.run([GTK_SYNC_SCRIPT, "--no-reload"], env=gtk_env, check=True)
|
|
|
|
tname = vals["theme.name"]
|
|
gtk_name = f"Geminux-{tname}"
|
|
theme_root = os.path.join(th_home, ".themes", gtk_name)
|
|
is_light = tname in LIGHT_THEMES
|
|
|
|
for cfg_rel in (".gtkrc-2.0", ".config/gtk-3.0/settings.ini", ".config/xsettingsd/xsettingsd.conf"):
|
|
cfg_path = os.path.join(th_home, cfg_rel)
|
|
with open(cfg_path, encoding="utf-8") as cf:
|
|
cfg_txt = cf.read()
|
|
assert gtk_name in cfg_txt, f"Missing {gtk_name} in {cfg_rel} for {tname}"
|
|
assert "/tmp" not in cfg_txt and "/home" not in cfg_txt, (
|
|
f"Hardcoded path leaked into {cfg_rel} for {tname}: {cfg_txt}"
|
|
)
|
|
|
|
with open(os.path.join(th_home, ".config/gtk-3.0/settings.ini"), encoding="utf-8") as sf:
|
|
ini_txt = sf.read()
|
|
exp_dark_bool = "false" if is_light else "true"
|
|
assert f"gtk-application-prefer-dark-theme={exp_dark_bool}" in ini_txt, (
|
|
f"Expected gtk-application-prefer-dark-theme={exp_dark_bool} for {tname}"
|
|
)
|
|
|
|
with open(os.path.join(th_home, ".config/xsettingsd/xsettingsd.conf"), encoding="utf-8") as xf:
|
|
xsd_txt = xf.read()
|
|
assert f'Net/ThemeName "{gtk_name}"' in xsd_txt
|
|
assert "Xft/DPI" not in xsd_txt, f"Unexpected Xft/DPI in xsettingsd.conf for {tname}"
|
|
|
|
with open(os.path.join(theme_root, "index.theme"), encoding="utf-8") as itf:
|
|
idx_txt = itf.read()
|
|
assert f"GtkTheme={gtk_name}" in idx_txt
|
|
|
|
with open(os.path.join(theme_root, "gtk-2.0/gtkrc"), encoding="utf-8") as rc2f:
|
|
rc2_txt = rc2f.read()
|
|
assert 'engine "' not in rc2_txt, f"External GTK2 engine referenced in {tname}"
|
|
for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent"):
|
|
assert vals[ck] in rc2_txt, f"Missing {ck} in gtkrc for {tname}"
|
|
|
|
with open(os.path.join(theme_root, "gtk-3.0/gtk.css"), encoding="utf-8") as css3f:
|
|
css3_txt = css3f.read()
|
|
exp_base = "gtk-contained.css" if is_light else "gtk-contained-dark.css"
|
|
assert f'@import url("resource:///org/gtk/libgtk/theme/Adwaita/{exp_base}");' in css3_txt, (
|
|
f"Wrong Adwaita base CSS in {tname}: expected {exp_base}"
|
|
)
|
|
assert css3_txt.count("{") == css3_txt.count("}"), f"Unbalanced braces in gtk.css for {tname}"
|
|
for ck in ("theme.bgMain", "theme.fgMain", "theme.selBg", "theme.accent", "theme.dangerBg"):
|
|
assert vals[ck] in css3_txt, f"Missing {ck} in gtk.css for {tname}"
|
|
|
|
with open(os.path.join(theme_root, "gtk-3.0/gtk-dark.css"), encoding="utf-8") as css3df:
|
|
assert '@import url("gtk.css");' in css3df.read()
|
|
|
|
xdg_link = os.path.join(th_home, ".local/share/themes", gtk_name)
|
|
assert os.path.islink(xdg_link), f"Missing XDG symlink {xdg_link}"
|
|
assert os.readlink(xdg_link) == f"../../../.themes/{gtk_name}", (
|
|
f"Unexpected XDG symlink target for {tname}: {os.readlink(xdg_link)}"
|
|
)
|
|
assert os.path.isfile(os.path.join(xdg_link, "gtk-3.0/gtk.css"))
|
|
|
|
print(f"[PASS] Verified {len(themes)} .xth themes, dunst synchronization, and GTK2/GTK3 theme generation")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|