diff options
Diffstat (limited to 'app/backends')
| -rwxr-xr-x | app/backends/audiocpp.py | 33 |
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: |
