Skip to content

Commit

Permalink
Merge pull request #12 from CMCC-Foundation/plot_update
Browse files Browse the repository at this point in the history
Dealing with Bandit errors related to sh and /
  • Loading branch information
santibravocmcc authored Feb 18, 2025
2 parents 684f4d4 + 86dd755 commit 5729017
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions src/model/RUN/MODEL_SRC/compile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# set folders
DIR_EXE=.
DIR_SRC=$DIR_EXE/MODEL_SRC
Expand Down

0 comments on commit 5729017

Please sign in to comment.