From d3b91a840f7b17ebe5a04be5197995406681ac6d 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/otfmi/mo2fmu.py b/otfmi/mo2fmu.py index 4c2e007..015741c 100644 --- a/otfmi/mo2fmu.py +++ b/otfmi/mo2fmu.py @@ -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 @@ -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)