Skip to content

Commit 6e962dc

Browse files
committed
[OMCProcessWSL] implement omc_run_data_update()
1 parent eb3ec31 commit 6e962dc

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

OMPython/OMCSession.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,25 +1353,30 @@ def __init__(
13531353

13541354
super().__init__(timeout=timeout)
13551355

1356-
# get wsl base command
1357-
self._wsl_cmd = ['wsl']
1358-
if isinstance(wsl_distribution, str):
1359-
self._wsl_cmd += ['--distribution', wsl_distribution]
1360-
if isinstance(wsl_user, str):
1361-
self._wsl_cmd += ['--user', wsl_user]
1362-
self._wsl_cmd += ['--']
1363-
13641356
# where to find OpenModelica
13651357
self._wsl_omc = wsl_omc
1358+
# store WSL distribution and user
1359+
self._wsl_distribution = wsl_distribution
1360+
self._wsl_user = wsl_user
13661361
# start up omc executable, which is waiting for the ZMQ connection
13671362
self._omc_process = self._omc_process_get()
13681363
# connect to the running omc instance using ZMQ
13691364
self._omc_port = self._omc_port_get()
13701365

1366+
def _wsl_cmd(self) -> list[str]: # get wsl base command
1367+
wsl_cmd = ['wsl']
1368+
if isinstance(self._wsl_distribution, str):
1369+
wsl_cmd += ['--distribution', self._wsl_distribution]
1370+
if isinstance(self._wsl_user, str):
1371+
wsl_cmd += ['--user', self._wsl_user]
1372+
wsl_cmd += ['--']
1373+
1374+
return wsl_cmd
1375+
13711376
def _omc_process_get(self) -> subprocess.Popen:
13721377
my_env = os.environ.copy()
13731378

1374-
omc_command = self._wsl_cmd + [
1379+
omc_command = self._wsl_cmd() + [
13751380
self._wsl_omc,
13761381
"--locale=C",
13771382
"--interactive=zmq",
@@ -1394,7 +1399,7 @@ def _omc_port_get(self) -> str:
13941399
omc_portfile_path = self._get_portfile_path()
13951400
if omc_portfile_path is not None:
13961401
output = subprocess.check_output(
1397-
args=self._wsl_cmd + ["cat", omc_portfile_path.as_posix()],
1402+
args=self._wsl_cmd() + ["cat", omc_portfile_path.as_posix()],
13981403
stderr=subprocess.DEVNULL,
13991404
)
14001405
port = output.decode().strip()
@@ -1420,4 +1425,14 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData, session: OMCSessi
14201425
"""
14211426
Update the OMCSessionRunData object based on the selected OMCProcess implementation.
14221427
"""
1423-
raise OMCSessionException("OMCProcessWSL does not support omc_run_data_update()!")
1428+
omc_run_data_copy = dataclasses.replace(omc_run_data)
1429+
1430+
omc_run_data_copy.cmd_prefix = self._wsl_cmd()
1431+
1432+
cmd_path = session.omcpath(omc_run_data_copy.cmd_path)
1433+
cmd_model_executable = cmd_path / omc_run_data_copy.cmd_model_name
1434+
if not cmd_model_executable.is_file():
1435+
raise OMCSessionException(f"Application file path not found: {cmd_model_executable}")
1436+
omc_run_data_copy.cmd_model_executable = cmd_model_executable.as_posix()
1437+
1438+
return omc_run_data_copy

0 commit comments

Comments
 (0)