diff --git a/main.py b/main.py index 275c0b3..9e6c3ea 100644 --- a/main.py +++ b/main.py @@ -365,10 +365,15 @@ def run_medslik_sim(self, simdir, simname, separate_slicks=False): shutil.copy(src, os.path.join(model_dir, "RUN", dest if "config" in dest else "MODEL_SRC")) # Compile and start running (replacing `cd` with `cwd`) - compile_script = "MODEL_SRC/compile.sh" - run_script = "RUN.sh" - subprocess.run(["sh", compile_script], check=True, cwd=os.path.join(model_dir, "RUN")) - subprocess.run(["./" + run_script], check=True, cwd=os.path.join(model_dir, "RUN")) + compile_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "MODEL_SRC", "compile.sh")) + run_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "RUN.sh")) + if not os.access(compile_script_path, os.X_OK): + os.chmod(compile_script_path, 0o755) + + if not os.access(run_script_path, os.X_OK): + os.chmod(run_script_path, 0o755) + subprocess.run([compile_script_path], check=True, cwd=os.path.join(model_dir, "RUN")) + subprocess.run([run_script_path], check=True, cwd=os.path.join(model_dir, "RUN")) else: # Handle separate slicks @@ -389,10 +394,15 @@ def run_medslik_sim(self, simdir, simname, separate_slicks=False): shutil.copy(config1_path, os.path.join(model_dir, "RUN", "config1.txt")) # Compile and start running - compile_script = "MODEL_SRC/compile.sh" - run_script = "RUN.sh" - subprocess.run(["sh", compile_script], check=True, cwd=os.path.join(model_dir, "RUN")) - subprocess.run(["./" + run_script], check=True, cwd=os.path.join(model_dir, "RUN")) + compile_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "MODEL_SRC", "compile.sh")) + run_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "RUN.sh")) + if not os.access(compile_script_path, os.X_OK): + os.chmod(compile_script_path, 0o755) + + if not os.access(run_script_path, os.X_OK): + os.chmod(run_script_path, 0o755) + subprocess.run([compile_script_path], check=True, cwd=os.path.join(model_dir, "RUN")) + subprocess.run([run_script_path], check=True, cwd=os.path.join(model_dir, "RUN")) # Copy output files (replacing `cp -r`) output_dest = os.path.join(simdir, simname, "out_files") diff --git a/src/model/RUN/MODEL_SRC/compile.sh b/src/model/RUN/MODEL_SRC/compile.sh index 24d6166..ba4d675 100644 --- a/src/model/RUN/MODEL_SRC/compile.sh +++ b/src/model/RUN/MODEL_SRC/compile.sh @@ -1,3 +1,4 @@ +#!/bin/bash # set folders DIR_EXE=. DIR_SRC=$DIR_EXE/MODEL_SRC