aboutsummaryrefslogtreecommitdiff
path: root/app/ui
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-25 19:15:43 -0400
committerhistoria <historiavg@proton.me>2026-08-25 19:15:43 -0400
commit757588321d4c27889be6e8e3c12b75873ad1218d (patch)
treef5550ef214a1939ba5844b7d91abdabb4171a48f /app/ui
parent8c9a782dfe94525dc5f0893c98fd19543648264b (diff)
downloadtts-audiobook-generator-757588321d4c27889be6e8e3c12b75873ad1218d.tar.gz
fix: book generation logging
Diffstat (limited to 'app/ui')
-rw-r--r--app/ui/hub.py16
-rw-r--r--app/ui/runview.py19
2 files changed, 30 insertions, 5 deletions
diff --git a/app/ui/hub.py b/app/ui/hub.py
index c1f5dce..9282fa7 100644
--- a/app/ui/hub.py
+++ b/app/ui/hub.py
@@ -1405,15 +1405,24 @@ def _prepare_run_config(backend: str, kwargs: dict
if info is not None:
label = info.label
log_path = str(LOGS_FOLDER / f"audiobook_{datetime.now():%Y%m%d}.log")
+ # The run view points failures at this file, so make sure it exists
+ # from the moment a run starts — even when the run dies before the
+ # converter's setup_logging creates it.
+ LOGS_FOLDER.mkdir(parents=True, exist_ok=True)
+ Path(log_path).touch()
autostart = kwargs.pop("autostart", None)
+ # book_files/planned travel on the dedicated RunConfig fields; keeping
+ # them in kwargs too would collide with convert()'s named parameters.
+ book_files = kwargs.pop("book_files", None) or []
+ planned = kwargs.pop("planned", None) or []
api_url = kwargs.get("api_url")
if api_url:
identity = _remote_identity(backend, kwargs)
return runview.RunConfig(
backend=backend, backend_label=f"{label} [remote]",
- kwargs=kwargs, book_files=kwargs.get("book_files") or [],
- planned=kwargs.get("planned") or [],
+ kwargs=kwargs, book_files=book_files,
+ planned=planned,
server_url=api_url, server_identity=identity,
log_path=log_path)
@@ -1434,8 +1443,7 @@ def _prepare_run_config(backend: str, kwargs: dict
notice = (f"no server named '{autostart}' — starting it was skipped")
return runview.RunConfig(
backend=backend, backend_label=label, kwargs=kwargs,
- book_files=kwargs.get("book_files") or [],
- planned=kwargs.get("planned") or [],
+ book_files=book_files, planned=planned,
server_name=spec.name if spec is not None else None,
server_url=spec.url if spec is not None else None,
server_identity=spec.identity if spec is not None else None,
diff --git a/app/ui/runview.py b/app/ui/runview.py
index d49d949..7ff7ab1 100644
--- a/app/ui/runview.py
+++ b/app/ui/runview.py
@@ -29,6 +29,7 @@ import io
import threading
import time
from dataclasses import dataclass, field
+from datetime import datetime
from queue import Empty, Queue
from typing import Callable, List, Optional
@@ -245,14 +246,30 @@ class RunView:
if self._cancel.is_set():
self._queue.put({"kind": "cancelled"})
return
+ # book_files/planned travel on the config fields; dropping
+ # any stray duplicates from kwargs keeps convert()'s call
+ # binding unambiguous.
+ kwargs = {key: value for key, value in config.kwargs.items()
+ if key not in ("book_files", "planned")}
audiobook.convert(backend=config.backend,
progress=self._queue.put,
cancel=self._cancel,
book_files=config.book_files,
planned=config.planned,
- **config.kwargs)
+ **kwargs)
except Exception as exc: # noqa: BLE001 - reported to the view
self._queue.put({"kind": "error", "message": f"{exc}"})
+ # The view points failures at the dated log; a crash that
+ # happens before the converter configures logging (e.g. bad
+ # arguments) must still leave its trace there.
+ if self.config.log_path:
+ try:
+ with open(self.config.log_path, "a",
+ encoding="utf-8") as logf:
+ logf.write(f"{datetime.now():%Y-%m-%d %H:%M:%S} - "
+ f"ERROR - {exc}\n")
+ except (OSError, ValueError):
+ pass
finally:
self._queue.put({"kind": "worker_exit"})