Skip to content

Commit 9a93725

Browse files
feat: default logs folder on Geometry Service started by Python at PUBLIC (Windows) (#1386)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 1def483 commit 9a93725

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

doc/changelog.d/1386.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default logs folder on Geometry Service started by Python at PUBLIC (Windows)

src/ansys/geometry/core/connection/launcher.py

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import logging
2525
import os
26+
from pathlib import Path
2627
from typing import TYPE_CHECKING
2728

2829
from ansys.geometry.core.connection.backend import ApiVersions, BackendType
@@ -576,6 +577,13 @@ def launch_modeler_with_geometry_service(
576577
"Please remove it from the arguments."
577578
)
578579

580+
# If we are in a Windows environment, we are going to write down the server
581+
# logs in the %PUBLIC%/Documents/Ansys/GeometryService folder.
582+
if os.name == "nt" and server_logs_folder is None:
583+
# Writing to the "Public" folder by default - no write permissions specifically required.
584+
server_logs_folder = Path(os.getenv("PUBLIC"), "Documents", "Ansys", "GeometryService")
585+
LOG.info(f"Writing server logs to the default folder at {server_logs_folder}.")
586+
579587
return prepare_and_start_backend(
580588
BackendType.WINDOWS_SERVICE,
581589
product_version=product_version,

src/ansys/geometry/core/connection/product_instance.py

+13
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ def prepare_and_start_backend(
270270
product_version = get_latest_ansys_installation()[0]
271271
_check_minimal_versions(product_version)
272272

273+
if server_logs_folder is not None:
274+
# Verify that the user has write permissions to the folder and that it exists.
275+
try:
276+
# Make sure the folder exists...
277+
Path(server_logs_folder).mkdir(parents=True, exist_ok=True)
278+
# Create a file to test write permissions...
279+
Path(server_logs_folder, ".verify").touch(exist_ok=True)
280+
except PermissionError:
281+
raise RuntimeError(
282+
"User does not have write permissions to the logs folder "
283+
f"{Path(server_logs_folder).resolve()}"
284+
)
285+
273286
args = []
274287
env_copy = _get_common_env(
275288
host=host,

0 commit comments

Comments
 (0)