Skip to content
Snippets Groups Projects
Commit 0cf9b9f3 authored by Ashwin Kumar Karnad's avatar Ashwin Kumar Karnad
Browse files

refactor prepate env into sub functions

parent 859fb5c5
Branches
Tags
2 merge requests!19Move linux-debian11 into main,!1Resolve "First draft for user interface for top level install command"
...@@ -62,8 +62,10 @@ def setup_log_cmd(msg=None,*args, **kwargs): ...@@ -62,8 +62,10 @@ def setup_log_cmd(msg=None,*args, **kwargs):
# MSGs # MSGs
with open(config_vars["cmd_log_file"], "a") as f: with open(config_vars["cmd_log_file"], "a") as f:
if msg: if msg:
# Write the message to the log file
f.write(msg + "\n") f.write(msg + "\n")
else: else:
# Write the header
f.write("-" * 50 + "\n") f.write("-" * 50 + "\n")
# Gather data to log # Gather data to log
...@@ -79,14 +81,14 @@ def setup_log_cmd(msg=None,*args, **kwargs): ...@@ -79,14 +81,14 @@ def setup_log_cmd(msg=None,*args, **kwargs):
# Write to log file # Write to log file
f.write(f"{datetime.datetime.now().isoformat()}, {cmd_line}\n") f.write(f"{datetime.datetime.now().isoformat()}, {cmd_line}\n")
f.write( f.write(
f"Software environment installer branch: {shared_var['script_branch']} (commit hash: {shared_var['script_commit_hash']})\n" f"Software environment installer branch: {script_branch} (commit hash: {script_commit_hash})\n"
) )
f.write( f.write(
f"Spack environments branch: {shared_var['spe_branch']} (commit hash: {shared_var['spe_commit_hash']})\n" f"Spack environments branch: {spe_branch} (commit hash: {spe_commit_hash})\n"
) )
def create_dir_structure(mpsd_release, script_dir):
def prepare_environment(mpsd_release, script_dir): # Create the directory structure for the release
release_base_dir = os.path.join(script_dir, mpsd_release) release_base_dir = os.path.join(script_dir, mpsd_release)
if not os.path.exists(release_base_dir): if not os.path.exists(release_base_dir):
os.makedirs(release_base_dir) os.makedirs(release_base_dir)
...@@ -109,6 +111,13 @@ def prepare_environment(mpsd_release, script_dir): ...@@ -109,6 +111,13 @@ def prepare_environment(mpsd_release, script_dir):
subprocess.run(["git", "checkout", mpsd_release]) subprocess.run(["git", "checkout", mpsd_release])
subprocess.run(["git", "pull"]) subprocess.run(["git", "pull"])
def get_release_info(mpsd_release, script_dir):
# Get the info for release
release_base_dir = os.path.join(script_dir, mpsd_release)
if not os.path.exists(release_base_dir):
raise Exception("Release directory does not exist. Run create_dir_structure() first.")
with os_chdir(release_base_dir):
with os_chdir("spack-environments"):
# Get the branch and commit hash of the spack-environments repo and store them in shared_var # Get the branch and commit hash of the spack-environments repo and store them in shared_var
spe_commit_hash = ( spe_commit_hash = (
subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE) subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE)
...@@ -123,6 +132,15 @@ def prepare_environment(mpsd_release, script_dir): ...@@ -123,6 +132,15 @@ def prepare_environment(mpsd_release, script_dir):
.strip() .strip()
) )
available_toolchains = os.listdir("toolchains") available_toolchains = os.listdir("toolchains")
return spe_branch,spe_commit_hash,available_toolchains
def prepare_environment(mpsd_release, script_dir):
# create the release folder and clone the spack-environments repo
# get the branch and commit hash of the spack-environments repo and available toolchains
# log the command usage.
create_dir_structure(mpsd_release, script_dir)
spe_branch, spe_commit_hash, available_toolchains = get_release_info(mpsd_release, script_dir)
setup_log_cmd(spe_branch=spe_branch, spe_commit_hash=spe_commit_hash) setup_log_cmd(spe_branch=spe_branch, spe_commit_hash=spe_commit_hash)
return available_toolchains return available_toolchains
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment