aboutsummaryrefslogtreecommitdiffstats
path: root/bin/udt-accent
diff options
context:
space:
mode:
Diffstat (limited to 'bin/udt-accent')
-rwxr-xr-xbin/udt-accent37
1 files changed, 7 insertions, 30 deletions
diff --git a/bin/udt-accent b/bin/udt-accent
index 4294347..7949597 100755
--- a/bin/udt-accent
+++ b/bin/udt-accent
@@ -153,18 +153,9 @@ def write_accent(name):
f"* {{ accent: {hexval}ff; }}\n"
)
- OUTPUT.parent.mkdir(parents=True, exist_ok=True)
# Write-then-rename: a rofi launch during a wallpaper change must never
# read a half-written file.
- fd, tmp = tempfile.mkstemp(dir=str(OUTPUT.parent), suffix=".tmp")
- try:
- with os.fdopen(fd, "w") as handle:
- handle.write(content)
- os.replace(tmp, OUTPUT)
- except BaseException:
- if os.path.exists(tmp):
- os.unlink(tmp)
- raise
+ write_atomic(OUTPUT, content)
def hue_neighbours(name):
@@ -270,7 +261,10 @@ def write_colors_json(name, image):
colors[4] = colors[12] = hexval
doc = {
- "wallpaper": str(image),
+ # Resolved, not as passed: wallp gives the real file but a caller may
+ # give ~/.cache/wal/wpaper, the symlink to it. Same wallpaper either
+ # way, so record one spelling.
+ "wallpaper": os.path.realpath(image),
"alpha": "100",
"special": {
"background": MACCHIATO["background"],
@@ -280,16 +274,7 @@ def write_colors_json(name, image):
"colors": {f"color{i}": c for i, c in enumerate(colors)},
}
- fd, tmp = tempfile.mkstemp(dir=str(COLORS_JSON.parent), suffix=".tmp")
- try:
- with os.fdopen(fd, "w") as handle:
- json.dump(doc, handle, indent=4)
- handle.write("\n")
- os.replace(tmp, COLORS_JSON)
- except BaseException:
- if os.path.exists(tmp):
- os.unlink(tmp)
- raise
+ write_atomic(COLORS_JSON, json.dumps(doc, indent=4) + "\n")
# Firefox only picks the new colours up when pywalfox pushes them. Never
# fatal: pywalfox may not be installed, and the desktop theme is unaffected.
@@ -310,15 +295,7 @@ def write_dunst(name):
if "@ACCENT@" not in text:
return
- fd, tmp = tempfile.mkstemp(dir=str(DUNSTRC.parent), suffix=".tmp")
- try:
- with os.fdopen(fd, "w") as handle:
- handle.write(text.replace("@ACCENT@", ACCENTS[name]))
- os.replace(tmp, DUNSTRC)
- except BaseException:
- if os.path.exists(tmp):
- os.unlink(tmp)
- raise
+ write_atomic(DUNSTRC, text.replace("@ACCENT@", ACCENTS[name]))
# Restart dunst so it rereads the file. It must be started again, not just
# killed: nothing else respawns it, and a dead dunst means no notifications