Skip to content

Commit

Permalink
mo2fmu: Check omc can be run
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Apr 25, 2024
1 parent 524adc6 commit addb629
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions otfmi/mo2fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def mo2fmu(
except Exception:
raise TypeError("platforms must be a sequence of str")

# check omc can be run
try:
subprocess.run(["omc", "--version"], check=True)
except subprocess.CalledProcessError:
raise RuntimeError("could not run the omc OpenModelica compiler command line executable")

workdir = tempfile.mkdtemp()
path_mos = os.path.join(workdir, "mo2fmu.mos")
# assume the model name is the file name
Expand Down Expand Up @@ -88,6 +94,8 @@ def mo2fmu(
check=True,
)
temp_fmu = os.path.join(workdir, model_name) + ".fmu"
if not os.path.exists(temp_fmu):
raise RuntimeError(f"omc failed to generate the FMU file {temp_fmu}")
if path_fmu == "":
path_fmu = os.path.join(os.getcwd(), model_name) + ".fmu"
shutil.move(temp_fmu, path_fmu)
Expand Down

0 comments on commit addb629

Please sign in to comment.