def get_bash_script(script_dir, is_simulation = True, is_automated=False, is_testing=False):
"""
Reads a README.md file in the indicated directoy and builds an
executable bash script from the commands contained within.
"""
if not script_dir.endswith('/'):
script_dir = script_dir + "/"
script = ""
env = Environment(script_dir, False).get()
for key, value in env.items():
script += key + "='" + value + "'\n"
filename = env.get_script_file_name(script_dir)
in_code_block = False
in_results_section = False
lines = list(open(script_dir + filename))
for line in lines:
if line.startswith("Results:"):
# Entering results section
in_results_section = True
elif line.startswith("```") and not in_code_block:
# Entering a code block, if in_results_section = True then it's a results block
in_code_block = True
elif line.startswith("```") and in_code_block:
# Finishing code block
in_results_section = False
in_code_block = False
elif in_code_block and not in_results_section:
# Executable line
script += line
elif line.startswith("#") and not in_code_block and not in_results_section and not is_automated:
# Heading in descriptive text
script += "\n"
return script
评论列表
文章目录