Skip to content

Commit 5729017

Browse files
Merge pull request #12 from CMCC-Foundation/plot_update
Dealing with Bandit errors related to sh and /
2 parents 684f4d4 + 86dd755 commit 5729017

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

main.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,15 @@ def run_medslik_sim(self, simdir, simname, separate_slicks=False):
365365
shutil.copy(src, os.path.join(model_dir, "RUN", dest if "config" in dest else "MODEL_SRC"))
366366

367367
# Compile and start running (replacing `cd` with `cwd`)
368-
compile_script = "MODEL_SRC/compile.sh"
369-
run_script = "RUN.sh"
370-
subprocess.run(["sh", compile_script], check=True, cwd=os.path.join(model_dir, "RUN"))
371-
subprocess.run(["./" + run_script], check=True, cwd=os.path.join(model_dir, "RUN"))
368+
compile_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "MODEL_SRC", "compile.sh"))
369+
run_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "RUN.sh"))
370+
if not os.access(compile_script_path, os.X_OK):
371+
os.chmod(compile_script_path, 0o755)
372+
373+
if not os.access(run_script_path, os.X_OK):
374+
os.chmod(run_script_path, 0o755)
375+
subprocess.run([compile_script_path], check=True, cwd=os.path.join(model_dir, "RUN"))
376+
subprocess.run([run_script_path], check=True, cwd=os.path.join(model_dir, "RUN"))
372377

373378
else:
374379
# Handle separate slicks
@@ -389,10 +394,15 @@ def run_medslik_sim(self, simdir, simname, separate_slicks=False):
389394
shutil.copy(config1_path, os.path.join(model_dir, "RUN", "config1.txt"))
390395

391396
# Compile and start running
392-
compile_script = "MODEL_SRC/compile.sh"
393-
run_script = "RUN.sh"
394-
subprocess.run(["sh", compile_script], check=True, cwd=os.path.join(model_dir, "RUN"))
395-
subprocess.run(["./" + run_script], check=True, cwd=os.path.join(model_dir, "RUN"))
397+
compile_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "MODEL_SRC", "compile.sh"))
398+
run_script_path = os.path.abspath(os.path.join(model_dir, "RUN", "RUN.sh"))
399+
if not os.access(compile_script_path, os.X_OK):
400+
os.chmod(compile_script_path, 0o755)
401+
402+
if not os.access(run_script_path, os.X_OK):
403+
os.chmod(run_script_path, 0o755)
404+
subprocess.run([compile_script_path], check=True, cwd=os.path.join(model_dir, "RUN"))
405+
subprocess.run([run_script_path], check=True, cwd=os.path.join(model_dir, "RUN"))
396406

397407
# Copy output files (replacing `cp -r`)
398408
output_dest = os.path.join(simdir, simname, "out_files")

src/model/RUN/MODEL_SRC/compile.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
# set folders
23
DIR_EXE=.
34
DIR_SRC=$DIR_EXE/MODEL_SRC

0 commit comments

Comments
 (0)