Skip to content

Commit e5c8a41

Browse files
committed
[ModelicaSystem] define check_model_executable() - test if the model existable exists and can be executed
1 parent 4ae625b commit e5c8a41

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

OMPython/ModelicaSystem.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,25 @@ def getWorkDirectory(self) -> OMCPath:
575575
"""
576576
return self._work_dir
577577

578+
def check_model_executable(self):
579+
"""
580+
Check if the model executable is working
581+
"""
582+
# check if the executable exists ...
583+
om_cmd = ModelExecutionCmd(
584+
runpath=self.getWorkDirectory(),
585+
cmd_local=self._session.model_execution_local,
586+
cmd_windows=self._session.model_execution_windows,
587+
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
588+
model_name=self._model_name,
589+
)
590+
# ... by running it - output help for command help
591+
om_cmd.arg_set(key="help", val="help")
592+
cmd_definition = om_cmd.definition()
593+
returncode = cmd_definition.run()
594+
if returncode != 0:
595+
raise ModelicaSystemError("Model executable not working!")
596+
578597
def buildModel(self, variableFilter: Optional[str] = None):
579598
filter_def: Optional[str] = None
580599
if variableFilter is not None:
@@ -591,19 +610,7 @@ def buildModel(self, variableFilter: Optional[str] = None):
591610
logger.debug("OM model build result: %s", build_model_result)
592611

593612
# check if the executable exists ...
594-
om_cmd = ModelExecutionCmd(
595-
runpath=self.getWorkDirectory(),
596-
cmd_local=self._session.model_execution_local,
597-
cmd_windows=self._session.model_execution_windows,
598-
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
599-
model_name=self._model_name,
600-
)
601-
# ... by running it - output help for command help
602-
om_cmd.arg_set(key="help", val="help")
603-
cmd_definition = om_cmd.definition()
604-
returncode = cmd_definition.run()
605-
if returncode != 0:
606-
raise ModelicaSystemError("Model executable not working!")
613+
self.check_model_executable()
607614

608615
xml_file = self._session.omcpath(build_model_result[0]).parent / build_model_result[1]
609616
self._xmlparse(xml_file=xml_file)

0 commit comments

Comments
 (0)