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 d3b91a8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions otfmi/mo2fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def mo2fmu(
except Exception:
raise TypeError("platforms must be a sequence of str")

# check omc can be run
subprocess.run(
["omc", "--version"],
capture_output=not verbose,
shell=sys.platform.startswith("win"),
check=True,
)

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 +96,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 d3b91a8

Please sign in to comment.