@@ -482,7 +482,6 @@ class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
482482
483483@dataclasses .dataclass
484484class OMCSessionRunData :
485- # TODO: rename OMCExcecutableModelData
486485 """
487486 Data class to store the command line data for running a model executable in the OMC environment.
488487
@@ -676,8 +675,11 @@ def execute(self, command: str):
676675 return self .sendExpression (command , parsed = False )
677676
678677 def sendExpression (self , command : str , parsed : bool = True ) -> Any :
678+ """
679+ Send an expression to the OMC server and return the result.
680+ """
679681 if self .omc_zmq is None :
680- raise OMCSessionException ("No OMC running. Create a new instance of OMCSessionZMQ !" )
682+ raise OMCSessionException ("No OMC running. Create a new instance of OMCProcess !" )
681683
682684 logger .debug ("sendExpression(%r, parsed=%r)" , command , parsed )
683685
@@ -1134,7 +1136,23 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
11341136 """
11351137 Update the OMCSessionRunData object based on the selected OMCProcess implementation.
11361138 """
1137- raise OMCSessionException ("OMCProcessDocker* does not support omc_run_data_update()!" )
1139+ omc_run_data_copy = dataclasses .replace (omc_run_data )
1140+
1141+ omc_run_data_copy .cmd_prefix = (
1142+ [
1143+ "docker" , "exec" ,
1144+ "--user" , str (self ._getuid ()),
1145+ "--workdir" , omc_run_data_copy .cmd_path ,
1146+ ]
1147+ + self ._dockerExtraArgs
1148+ + [self ._dockerCid ]
1149+ )
1150+
1151+ cmd_path = pathlib .PurePosixPath (omc_run_data_copy .cmd_path )
1152+ cmd_model_executable = cmd_path / omc_run_data_copy .cmd_model_name
1153+ omc_run_data_copy .cmd_model_executable = cmd_model_executable .as_posix ()
1154+
1155+ return omc_run_data_copy
11381156
11391157
11401158class OMCProcessDocker (OMCProcessDockerHelper ):
@@ -1388,25 +1406,33 @@ def __init__(
13881406
13891407 super ().__init__ (timeout = timeout )
13901408
1391- # get wsl base command
1392- self ._wsl_cmd = ['wsl' ]
1393- if isinstance (wsl_distribution , str ):
1394- self ._wsl_cmd += ['--distribution' , wsl_distribution ]
1395- if isinstance (wsl_user , str ):
1396- self ._wsl_cmd += ['--user' , wsl_user ]
1397- self ._wsl_cmd += ['--' ]
1398-
13991409 # where to find OpenModelica
14001410 self ._wsl_omc = wsl_omc
1411+ # store WSL distribution and user
1412+ self ._wsl_distribution = wsl_distribution
1413+ self ._wsl_user = wsl_user
14011414 # start up omc executable, which is waiting for the ZMQ connection
14021415 self ._omc_process = self ._omc_process_get ()
14031416 # connect to the running omc instance using ZMQ
14041417 self ._omc_port = self ._omc_port_get ()
14051418
1419+ def _wsl_cmd (self , wsl_cwd : Optional [str ] = None ) -> list [str ]:
1420+ # get wsl base command
1421+ wsl_cmd = ['wsl' ]
1422+ if isinstance (self ._wsl_distribution , str ):
1423+ wsl_cmd += ['--distribution' , self ._wsl_distribution ]
1424+ if isinstance (self ._wsl_user , str ):
1425+ wsl_cmd += ['--user' , self ._wsl_user ]
1426+ if isinstance (wsl_cwd , str ):
1427+ wsl_cmd += ['--cd' , wsl_cwd ]
1428+ wsl_cmd += ['--' ]
1429+
1430+ return wsl_cmd
1431+
14061432 def _omc_process_get (self ) -> subprocess .Popen :
14071433 my_env = os .environ .copy ()
14081434
1409- omc_command = self ._wsl_cmd + [
1435+ omc_command = self ._wsl_cmd () + [
14101436 self ._wsl_omc ,
14111437 "--locale=C" ,
14121438 "--interactive=zmq" ,
@@ -1429,7 +1455,7 @@ def _omc_port_get(self) -> str:
14291455 omc_portfile_path = self ._get_portfile_path ()
14301456 if omc_portfile_path is not None :
14311457 output = subprocess .check_output (
1432- args = self ._wsl_cmd + ["cat" , omc_portfile_path .as_posix ()],
1458+ args = self ._wsl_cmd () + ["cat" , omc_portfile_path .as_posix ()],
14331459 stderr = subprocess .DEVNULL ,
14341460 )
14351461 port = output .decode ().strip ()
@@ -1455,4 +1481,12 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
14551481 """
14561482 Update the OMCSessionRunData object based on the selected OMCProcess implementation.
14571483 """
1458- raise OMCSessionException ("OMCProcessWSL does not support omc_run_data_update()!" )
1484+ omc_run_data_copy = dataclasses .replace (omc_run_data )
1485+
1486+ omc_run_data_copy .cmd_prefix = self ._wsl_cmd (wsl_cwd = omc_run_data .cmd_path )
1487+
1488+ cmd_path = pathlib .PurePosixPath (omc_run_data_copy .cmd_path )
1489+ cmd_model_executable = cmd_path / omc_run_data_copy .cmd_model_name
1490+ omc_run_data_copy .cmd_model_executable = cmd_model_executable .as_posix ()
1491+
1492+ return omc_run_data_copy
0 commit comments