summaryrefslogtreecommitdiffstats
path: root/workers/hugo_worker.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-03 10:10:30 +0200
committerDanilo M. <danix@danix.xyz>2026-05-03 10:10:30 +0200
commit1f9d3cb3ee98b28ddd72ebd4a94ca6657a0bb11e (patch)
treef9687fcd619e57b1e8f79e7511dd8603f21314a5 /workers/hugo_worker.py
parente8a8a4c37713be0c0bc49a78f36570c80807b43a (diff)
downloadpublisher-1f9d3cb3ee98b28ddd72ebd4a94ca6657a0bb11e.tar.gz
publisher-1f9d3cb3ee98b28ddd72ebd4a94ca6657a0bb11e.zip
feat: HugoWorker QProcess with log streaming
Diffstat (limited to 'workers/hugo_worker.py')
-rw-r--r--workers/hugo_worker.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/workers/hugo_worker.py b/workers/hugo_worker.py
new file mode 100644
index 0000000..23748a7
--- /dev/null
+++ b/workers/hugo_worker.py
@@ -0,0 +1,49 @@
+from __future__ import annotations
+from PyQt6.QtCore import QObject, QProcess, pyqtSignal
+from pathlib import Path
+
+class HugoWorker(QObject):
+ log_line = pyqtSignal(str)
+ started = pyqtSignal()
+ stopped = pyqtSignal()
+ error = pyqtSignal(str)
+
+ def __init__(self, repo_path: Path, parent=None):
+ super().__init__(parent)
+ self._repo_path = repo_path
+ self._process = QProcess(self)
+ self._process.readyReadStandardOutput.connect(self._on_stdout)
+ self._process.readyReadStandardError.connect(self._on_stderr)
+ self._process.finished.connect(self._on_finished)
+
+ @property
+ def is_running(self) -> bool:
+ return self._process.state() == QProcess.ProcessState.Running
+
+ def start(self):
+ if self.is_running:
+ return
+ self._process.setWorkingDirectory(str(self._repo_path))
+ self._process.start("hugo", ["server", "-D"])
+ self.started.emit()
+
+ def stop(self):
+ if self.is_running:
+ self._process.terminate()
+ self._process.waitForFinished(3000)
+ self.stopped.emit()
+
+ def _on_stdout(self):
+ data = self._process.readAllStandardOutput().data().decode("utf-8", errors="replace")
+ for line in data.splitlines():
+ self.log_line.emit(line)
+
+ def _on_stderr(self):
+ data = self._process.readAllStandardError().data().decode("utf-8", errors="replace")
+ for line in data.splitlines():
+ self.log_line.emit(line)
+
+ def _on_finished(self, exit_code: int, _):
+ if exit_code != 0:
+ self.error.emit(f"hugo server exited with code {exit_code}")
+ self.stopped.emit()