From aa35052a5827ba77473917f816517a4edfb3c0a8 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Thu, 25 Apr 2024 10:15:17 +0200 Subject: [PATCH] mo2fmu: Check omc can be run --- otfmi/mo2fmu.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/otfmi/mo2fmu.py b/otfmi/mo2fmu.py index 4c2e007..2d3bd7c 100644 --- a/otfmi/mo2fmu.py +++ b/otfmi/mo2fmu.py @@ -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 @@ -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)