Skip to content

Commit 8261c13

Browse files
committed
[ModelicaSystem] define check_model_executable() - test if the model existable exists and can be executed
1 parent 24729ee commit 8261c13

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,25 @@ def getWorkDirectory(self) -> OMCPath:
566566
"""
567567
return self._work_dir
568568

569+
def check_model_executable(self):
570+
"""
571+
Check if the model executable is working
572+
"""
573+
# check if the executable exists ...
574+
om_cmd = ModelExecutionCmd(
575+
runpath=self.getWorkDirectory(),
576+
cmd_local=self._session.model_execution_local,
577+
cmd_windows=self._session.model_execution_windows,
578+
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
579+
model_name=self._model_name,
580+
)
581+
# ... by running it - output help for command help
582+
om_cmd.arg_set(key="help", val="help")
583+
cmd_definition = om_cmd.definition()
584+
returncode = cmd_definition.run()
585+
if returncode != 0:
586+
raise ModelicaSystemError("Model executable not working!")
587+
569588
def buildModel(self, variableFilter: Optional[str] = None):
570589
filter_def: Optional[str] = None
571590
if variableFilter is not None:
@@ -582,19 +601,7 @@ def buildModel(self, variableFilter: Optional[str] = None):
582601
logger.debug("OM model build result: %s", build_model_result)
583602

584603
# check if the executable exists ...
585-
om_cmd = ModelExecutionCmd(
586-
runpath=self.getWorkDirectory(),
587-
cmd_local=self._session.model_execution_local,
588-
cmd_windows=self._session.model_execution_windows,
589-
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
590-
model_name=self._model_name,
591-
)
592-
# ... by running it - output help for command help
593-
om_cmd.arg_set(key="help", val="help")
594-
cmd_definition = om_cmd.definition()
595-
returncode = cmd_definition.run()
596-
if returncode != 0:
597-
raise ModelicaSystemError("Model executable not working!")
604+
self.check_model_executable()
598605

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

0 commit comments

Comments
 (0)