From 041cf7b04474b9f3316f6f2a66c7b6b82f64ab25 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Thu, 4 May 2023 10:24:47 +0200 Subject: [PATCH] remove the class --- install-mpsd-software-environment.py | 124 +-------------------------- 1 file changed, 3 insertions(+), 121 deletions(-) diff --git a/install-mpsd-software-environment.py b/install-mpsd-software-environment.py index bcfb1de..2cefe6a 100755 --- a/install-mpsd-software-environment.py +++ b/install-mpsd-software-environment.py @@ -16,6 +16,7 @@ The toolchains are built using the bash script spack_setup.sh, and the results a """ config_vars = { "cmd_log_file": "logs/install-software-environment.log", + "build_log_file": f"build_toolchains_mpsd_spack_ver_{time.strftime('%Y%m%d-%H%M%S')}.log", # TODO: modify toolchains,mpsd_spack_ver when the variable is available "spack_environments_repo": "https://gitlab.gwdg.de/mpsd-cs/spack-environments.git", } @@ -26,6 +27,7 @@ shared_var ={ "spe_commit_hash": None, "available_toolchains": None, "toolchain_base_dir": None, + } # Helper class to change directory via context manager @@ -40,7 +42,7 @@ class os_chdir: def __exit__(self, exc_type, exc_val, exc_tb): os.chdir(self.saved_dir) -def setup_log_cmd(shared_var): +def setup_log_cmd(shared_var, msg=None): # Create log directory if it doesn't exist if not os.path.exists("logs"): os.makedirs("logs") @@ -65,126 +67,6 @@ def setup_log_cmd(shared_var): ) -class builder: - def __init__( - self, release, cmd, toolchain_list=None, target_dir=None, skip_build_cache=False - ) -> None: - # Variables taken from cli arguments - self.mpsd_os = os.getenv("MPSD_OS", "UNKNOWN_OS") - self.mpsd_microarch = os.getenv("MPSD_MICROARCH", "UNKNOWN_MICROARCH") - self.mpsd_spack_ver = release - self.toolchain_list = toolchain_list - if target_dir == "DEFAULT" or target_dir is None: - target_dir = ( - f"/opt_mpsd/{self.mpsd_os}/{self.mpsd_spack_ver}/{self.mpsd_microarch}" - ) - self.toolchain_base_dir = Path(target_dir) - self.skip_build_cache = skip_build_cache - self.skip_dir_check = False - self.current_dir = os.getcwd() - self.run_mode = cmd - # Spack environments related variables - self.spe_branch = None # To be set after cloning the spack-environments repo - self.spe_commit_hash = ( - None # To be set after cloning the spack-environments repo - ) - # script related variables - self.script_branch = ( - subprocess.run( - ["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE - ) - .stdout.decode() - .strip() - ) - self.script_commit_hash = ( - subprocess.run( - ["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE - ) - .stdout.decode() - .strip() - ) - # Two log files, one for logging commands and the other for logging the build process - self.cmd_log_file = "logs/install-software-environment.log" - self.build_log_file = f"build_toolchains_{self.mpsd_spack_ver}_{time.strftime('%Y%m%d-%H%M%S')}.log" - - # run the script - # self.run() # better to call this seperately after creating the object - - - def run(self): - if self.run_mode == "remove": - pass - # self.remove_toolchains() - elif self.run_mode == "start_new": - pass - # self.start_new_env() - elif self.run_mode == "install": - pass - # self.build_toolchains() - else: - self.prepare_env() - - def prepare_env(self): - # ensure required arguments are not None - if self.toolchain_base_dir is None: - raise ValueError("Error: Please specify the target directory") - if self.mpsd_spack_ver is None: - raise ValueError("Error: Please specify the release version to install") - if self.toolchain_base_dir is None: - raise ValueError( - "Error: Please specify the target directory for installation" - ) - if not os.path.exists(self.toolchain_base_dir): - os.makedirs(self.toolchain_base_dir) - else: - if not self.skip_dir_check: - raise ValueError( - f"Error: Target directory {self.toolchain_base_dir} already exists. \n\ - Please remove it and try again." - ) - with os_chdir(self.toolchain_base_dir): - subprocess.run( - [ - "git", - "clone", - "https://gitlab.gwdg.de/mpsd-cs/spack-environments.git", - ] - ) - with os_chdir("spack-environments"): - subprocess.run(["git", "checkout", self.mpsd_spack_ver]) - self.spe_branch = subprocess.run( - ["git", "rev-parse", "--abbrev-ref", "HEAD"], - stdout=subprocess.PIPE, - ).stdout.decode() - self.spe_commit_hash = subprocess.run( - ["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE - ).stdout.decode() - # keep the available toolchains in current spack-environments branch - self.available_toolchains = os.listdir("toolchains") - - # Setup the log file for commands - self.setup_log_cmd() - - def build_toolchains( - self, - release, - install, - target_dir, - force_reinstall, - skip_build_cache, - skip_dir_check, - ): - # ensure required arguments are not None - - if self.toolchain_list is None: - raise ValueError("Error: Please specify the toolchains to install") - self.prepare_env() - - def start_new_env(set_up, from_release): - pass - - def remove_toolchain(release, remove): - pass def main(): -- GitLab