aboutsummaryrefslogtreecommitdiff
path: root/app/backends
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-24 03:41:57 -0400
committerhistoria <historiavg@proton.me>2026-08-24 03:41:57 -0400
commit73b466fbc054e80b50e318b49643aee8a03c784b (patch)
treedf3d78efa84956bcf47586af736479f319a80abe /app/backends
parent471798cf5e967b2d1bceb02d12a47fe9ad1cbed1 (diff)
downloadtts-audiobook-generator-73b466fbc054e80b50e318b49643aee8a03c784b.tar.gz
feat: settings for ports in TUI
Diffstat (limited to 'app/backends')
-rwxr-xr-xapp/backends/audiocpp.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/backends/audiocpp.py b/app/backends/audiocpp.py
index cc67efc..2368ce7 100755
--- a/app/backends/audiocpp.py
+++ b/app/backends/audiocpp.py
@@ -253,6 +253,39 @@ def update_config_api_url_port(port: int, config_path: Optional[Path] = None) ->
return True
+def update_server_config_port(port: int) -> bool:
+ """Rewrite the 'port' in the audio.cpp checkout's server.json.
+
+ Loads ``<checkout>/server.json``, sets its ``port`` to PORT, and
+ rewrites it with the same ``json.dump`` formatting the wizard uses.
+ Returns True when the file now carries PORT (a no-op when it already
+ does), and False when there is no checkout/server.json or the file
+ cannot be read or written.
+ """
+ checkout = find_local_checkout()
+ if checkout is None:
+ return False
+ server_json = checkout / "server.json"
+ if not server_json.exists():
+ return False
+ try:
+ data = json.loads(server_json.read_text(encoding="utf-8"))
+ except (OSError, ValueError):
+ return False
+ if not isinstance(data, dict):
+ return False
+ if data.get("port") == port:
+ return True
+ data["port"] = port
+ try:
+ with server_json.open("w", encoding="utf-8") as handle:
+ json.dump(data, handle, indent=2, ensure_ascii=False)
+ handle.write("\n")
+ except OSError:
+ return False
+ return True
+
+
def update_config_model_ids(model_id: str,
clone_model_id: Optional[str] = None,
config_path: Optional[Path] = None) -> bool: