@@ -461,7 +461,6 @@ class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
461461
462462@dataclasses .dataclass
463463class OMCSessionRunData :
464- # TODO: rename OMCExcecutableModelData
465464 """
466465 Data class to store the command line data for running a model executable in the OMC environment.
467466
@@ -655,8 +654,11 @@ def execute(self, command: str):
655654 return self .sendExpression (command , parsed = False )
656655
657656 def sendExpression (self , command : str , parsed : bool = True ) -> Any :
657+ """
658+ Send an expression to the OMC server and return the result.
659+ """
658660 if self .omc_zmq is None :
659- raise OMCSessionException ("No OMC running. Create a new instance of OMCSessionZMQ !" )
661+ raise OMCSessionException ("No OMC running. Create a new instance of OMCProcess !" )
660662
661663 logger .debug ("sendExpression(%r, parsed=%r)" , command , parsed )
662664
@@ -1113,7 +1115,23 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
11131115 """
11141116 Update the OMCSessionRunData object based on the selected OMCProcess implementation.
11151117 """
1116- raise OMCSessionException ("OMCProcessDocker* does not support omc_run_data_update()!" )
1118+ omc_run_data_copy = dataclasses .replace (omc_run_data )
1119+
1120+ omc_run_data_copy .cmd_prefix = (
1121+ [
1122+ "docker" , "exec" ,
1123+ "--user" , str (self ._getuid ()),
1124+ "--workdir" , omc_run_data_copy .cmd_path ,
1125+ ]
1126+ + self ._dockerExtraArgs
1127+ + [self ._dockerCid ]
1128+ )
1129+
1130+ cmd_path = pathlib .PurePosixPath (omc_run_data_copy .cmd_path )
1131+ cmd_model_executable = cmd_path / omc_run_data_copy .cmd_model_name
1132+ omc_run_data_copy .cmd_model_executable = cmd_model_executable .as_posix ()
1133+
1134+ return omc_run_data_copy
11171135
11181136
11191137class OMCProcessDocker (OMCProcessDockerHelper ):
@@ -1367,25 +1385,33 @@ def __init__(
13671385
13681386 super ().__init__ (timeout = timeout )
13691387
1370- # get wsl base command
1371- self ._wsl_cmd = ['wsl' ]
1372- if isinstance (wsl_distribution , str ):
1373- self ._wsl_cmd += ['--distribution' , wsl_distribution ]
1374- if isinstance (wsl_user , str ):
1375- self ._wsl_cmd += ['--user' , wsl_user ]
1376- self ._wsl_cmd += ['--' ]
1377-
13781388 # where to find OpenModelica
13791389 self ._wsl_omc = wsl_omc
1390+ # store WSL distribution and user
1391+ self ._wsl_distribution = wsl_distribution
1392+ self ._wsl_user = wsl_user
13801393 # start up omc executable, which is waiting for the ZMQ connection
13811394 self ._omc_process = self ._omc_process_get ()
13821395 # connect to the running omc instance using ZMQ
13831396 self ._omc_port = self ._omc_port_get ()
13841397
1398+ def _wsl_cmd (self , wsl_cwd : Optional [str ] = None ) -> list [str ]:
1399+ # get wsl base command
1400+ wsl_cmd = ['wsl' ]
1401+ if isinstance (self ._wsl_distribution , str ):
1402+ wsl_cmd += ['--distribution' , self ._wsl_distribution ]
1403+ if isinstance (self ._wsl_user , str ):
1404+ wsl_cmd += ['--user' , self ._wsl_user ]
1405+ if isinstance (wsl_cwd , str ):
1406+ wsl_cmd += ['--cd' , wsl_cwd ]
1407+ wsl_cmd += ['--' ]
1408+
1409+ return wsl_cmd
1410+
13851411 def _omc_process_get (self ) -> subprocess .Popen :
13861412 my_env = os .environ .copy ()
13871413
1388- omc_command = self ._wsl_cmd + [
1414+ omc_command = self ._wsl_cmd () + [
13891415 self ._wsl_omc ,
13901416 "--locale=C" ,
13911417 "--interactive=zmq" ,
@@ -1408,7 +1434,7 @@ def _omc_port_get(self) -> str:
14081434 omc_portfile_path = self ._get_portfile_path ()
14091435 if omc_portfile_path is not None :
14101436 output = subprocess .check_output (
1411- args = self ._wsl_cmd + ["cat" , omc_portfile_path .as_posix ()],
1437+ args = self ._wsl_cmd () + ["cat" , omc_portfile_path .as_posix ()],
14121438 stderr = subprocess .DEVNULL ,
14131439 )
14141440 port = output .decode ().strip ()
@@ -1434,4 +1460,12 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
14341460 """
14351461 Update the OMCSessionRunData object based on the selected OMCProcess implementation.
14361462 """
1437- raise OMCSessionException ("OMCProcessWSL does not support omc_run_data_update()!" )
1463+ omc_run_data_copy = dataclasses .replace (omc_run_data )
1464+
1465+ omc_run_data_copy .cmd_prefix = self ._wsl_cmd (wsl_cwd = omc_run_data .cmd_path )
1466+
1467+ cmd_path = pathlib .PurePosixPath (omc_run_data_copy .cmd_path )
1468+ cmd_model_executable = cmd_path / omc_run_data_copy .cmd_model_name
1469+ omc_run_data_copy .cmd_model_executable = cmd_model_executable .as_posix ()
1470+
1471+ return omc_run_data_copy
0 commit comments