diff options
Diffstat (limited to 'sb_builder')
| -rw-r--r-- | sb_builder/fmt.py | 10 | ||||
| -rw-r--r-- | sb_builder/mainwindow.py | 17 |
2 files changed, 20 insertions, 7 deletions
diff --git a/sb_builder/fmt.py b/sb_builder/fmt.py index 55a2d0d..5c50628 100644 --- a/sb_builder/fmt.py +++ b/sb_builder/fmt.py @@ -54,6 +54,16 @@ def job_title(j): return " ".join([j["kind"], *j["args"]]) +def outcome(j): + """How an ended job went, as a sentence for its notification.""" + took = fmt_duration(j["end"] - j["start"]) if "end" in j and "start" in j else None + after = f" after {took}" if took else "" + return {"ok": f"Succeeded in {took}" if took else "Succeeded", + "failed": f"Failed with exit code {j.get('exit', '?')}{after}", + "killed": f"Killed{after}", + "lost": "Lost: its runner died (killed, crashed or the VM rebooted)"}[j["status"]] + + def describe(j): """One-line job summary: icon, kind and args, start time, duration.""" dur = None if "start" not in j else j.get("end", time.time()) - j["start"] diff --git a/sb_builder/mainwindow.py b/sb_builder/mainwindow.py index f63a4ba..ec2b87a 100644 --- a/sb_builder/mainwindow.py +++ b/sb_builder/mainwindow.py @@ -27,7 +27,7 @@ from PyQt6.QtWidgets import (QHeaderView, QLabel, QMainWindow, QMessageBox, QPus from . import VERSION, config from .dashboard import Dashboard -from .fmt import job_title +from .fmt import job_title, outcome from .hints_tab import HINT_JOBS, HintResultDialog, HintsTab from .jobs import JobsTab, NextStep, is_preview from .packages import PackagesTab @@ -51,6 +51,9 @@ QTabBar::tab:selected { background: palette(highlight); color: palette(highlight QTabBar::tab:hover:!selected { background: palette(midlight); } """ END_EVENT = {"ok": "finished", "failed": "failed", "killed": "killed", "lost": "lost"} +# freedesktop icon names per notification event +NOTIFY_ICON = {"finished": "emblem-default", "failed": "dialog-error", "killed": "process-stop", + "lost": "dialog-warning", "vm-up": "computer"} MAX_RETRY_MS = 30000 @@ -66,9 +69,9 @@ class Notifier(QObject): bus.connect(NOTIFY, NOTIFY_PATH, NOTIFY, "ActionInvoked", self._action) self.ids = {} # notification id -> job id - def send(self, title, body, jid=""): + def send(self, title, body, icon="", jid=""): reply = self.iface.call( - "Notify", "sb-builder", QDBusArgument(0, QMetaType.Type.UInt.value), "", title, body, + "Notify", "sb-builder", QDBusArgument(0, QMetaType.Type.UInt.value), icon, title, body, QDBusArgument(["default", "Open"], QMetaType.Type.QStringList.value), {}, -1) if reply.type() == QDBusMessage.MessageType.ReplyMessage: self.ids[reply.arguments()[0]] = jid @@ -231,7 +234,7 @@ class MainWindow(QMainWindow): self.poll_slow() if self.vm_woken: self.vm_woken = False - self.notify("vm-up", f"{self.cfg['vm']['domain']} is up") + self.notify("vm-up", "VM up", f"{self.cfg['vm']['domain']} answers over ssh") def _failed(self, err): if err == MISSING: @@ -290,10 +293,10 @@ class MainWindow(QMainWindow): # ── notifications ─────────────────────────────────────────────────────── - def notify(self, event, body, jid=""): + def notify(self, event, title, body, jid=""): n = self.cfg["notify"] if n["enabled"] and event in n["events"]: - self.notifier.send(f"sb-builder: {event}", body, jid) + self.notifier.send(title, body, NOTIFY_ICON[event], jid) def _notify_ends(self, jobs): prev, self.seen = self.seen, {j["id"]: j["status"] for j in jobs} @@ -302,7 +305,7 @@ class MainWindow(QMainWindow): for j in jobs: event = END_EVENT.get(j["status"]) if event and prev.get(j["id"], "running") != j["status"]: - self.notify(event, job_title(j), j["id"]) + self.notify(event, job_title(j), outcome(j), j["id"]) if self.tabs.currentWidget() is not self.jobs_tab: self._badge("ok" if j["status"] == "ok" else "bad") if j["kind"] in ("slackrepo", "publish"): # build state changed |
