Skip to content

Commit 73c5062

Browse files
committed
[ModelicaSystemCmd] define as compatibility layer
1 parent abed1db commit 73c5062

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,3 +2819,50 @@ def _prepare_structure_parameters(
28192819
"pre-compiled binary of model.")
28202820

28212821
return {}
2822+
2823+
2824+
class ModelicaSystemCmd(ModelExecutionCmd):
2825+
# TODO: docstring
2826+
2827+
def __init__(
2828+
self,
2829+
runpath: pathlib.Path,
2830+
modelname: str,
2831+
timeout: float = 10.0,
2832+
) -> None:
2833+
super().__init__(
2834+
runpath=runpath,
2835+
timeout=timeout,
2836+
cmd_prefix=[],
2837+
model_name=modelname,
2838+
)
2839+
2840+
def get_exe(self) -> pathlib.Path:
2841+
"""Get the path to the compiled model executable."""
2842+
# TODO: move to the top
2843+
import platform
2844+
2845+
path_run = pathlib.Path(self._runpath)
2846+
if platform.system() == "Windows":
2847+
path_exe = path_run / f"{self._model_name}.exe"
2848+
else:
2849+
path_exe = path_run / self._model_name
2850+
2851+
if not path_exe.exists():
2852+
raise ModelicaSystemError(f"Application file path not found: {path_exe}")
2853+
2854+
return path_exe
2855+
2856+
def get_cmd(self) -> list:
2857+
"""Get a list with the path to the executable and all command line args.
2858+
2859+
This can later be used as an argument for subprocess.run().
2860+
"""
2861+
2862+
cmdl = [self.get_exe().as_posix()] + self.get_cmd_args()
2863+
2864+
return cmdl
2865+
2866+
def run(self):
2867+
cmd_definition = self.definition()
2868+
return cmd_definition.run()

OMPython/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
ModelicaDoERunner,
2424

2525
doe_get_solutions,
26+
27+
ModelicaSystemCmd,
2628
)
2729
from OMPython.OMCSession import (
2830
OMPathABC,
@@ -62,6 +64,7 @@
6264

6365
'ModelicaSystem',
6466
'ModelicaSystemOMC',
67+
'ModelicaSystemCmd',
6568
'ModelExecutionCmd',
6669
'ModelicaSystemDoE',
6770
'ModelicaDoEOMC',

0 commit comments

Comments
 (0)