Skip to content
Snippets Groups Projects

Remove cmd

Merged Ashwin Kumar Karnad requested to merge continue-with-remove-cmd into main
Files
3
@@ -1117,9 +1117,9 @@ def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove
if package_sets == "NONE":
logging.warning(
"Please specify package_sets to remove, or 'ALL' to remove all toolchains"
"Please specify package_sets to remove, or 'ALL' to remove all package_sets"
)
sys.exit(50) # TODO document this code.
sys.exit(50)
# 2nd case: remove the entire release for microarchitecture
dir_to_remove = root_dir / mpsd_release / get_native_microarchitecture()
if "ALL" in package_sets:
@@ -1131,22 +1131,36 @@ def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove
if not force_remove:
logging.warning("do you want to continue? [y/n]")
if input().lower() != "y":
sys.exit(60) # TODO document this code.
sys.exit(60)
# Set the remove log file name from create_log_file_names
build_log_path = get_log_file_path(mpsd_release, "remove", root_dir, "ALL")
logging.info(f"> Logging removal of {mpsd_release} at {build_log_path}")
folders_to_remove = os.listdir(dir_to_remove)
# skip logs folder
# if "logs" in folders_to_remove:
# folders_to_remove.remove("logs")
for folder in folders_to_remove:
# shutil.rmtree(dir_to_remove / folder) #dosent delete file
run(f"rm -rf {dir_to_remove / folder}", shell=True, check=True)
run(
f"rm -rf {dir_to_remove / folder} 2>&1 | tee -a {build_log_path}",
shell=True,
check=True,
)
logging.warning(f"Removed release {mpsd_release} from {root_dir}")
return
# 3rd case: remove specific package_sets from release
for package_set in package_sets:
# we load the spack environment and remove the package_set
build_log_path = get_log_file_path(
mpsd_release, "remove", root_dir, package_set
)
logging.info(f"> Logging removal of {package_set} at {build_log_path}")
if package_set not in ["global_generic", "global"]:
remove_spack_environment(dir_to_remove / "spack", package_set)
remove_spack_environment(
dir_to_remove / "spack", package_set, build_log_path
)
else:
# list all specs from the global_packages.list
spe_folder = root_dir / mpsd_release / "spack-environments"
@@ -1166,10 +1180,10 @@ def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove
# remove all packages in package_list
for package in package_list:
logging.info(f"Removing package {package} from installation")
remove_spack_package(dir_to_remove / "spack", package)
remove_spack_package(dir_to_remove / "spack", package, build_log_path)
def remove_spack_environment(spack_dir, environment_name):
def remove_spack_environment(spack_dir, environment_name, build_log_path=None):
"""Remove spack environment including packages exclusive to it.
First activate the environment,
@@ -1182,6 +1196,8 @@ def remove_spack_environment(spack_dir, environment_name):
A Path object representing the path to the spack directory.
environment_name : str
A string representing the name of the spack environment to remove.
build_log_path : pathlib.Path, optional
A Path object representing the path to where the logs will be teed
"""
logging.warning(f"Removing spack environment {environment_name}")
spack_env = spack_dir / "share" / "spack" / "setup-env.sh"
@@ -1195,10 +1211,15 @@ def remove_spack_environment(spack_dir, environment_name):
"spack env deactivate",
f"spack env remove -y {environment_name}",
]
run(" && ".join(commands_to_execute), shell=True, check=True)
build_log_path = build_log_path or "/dev/null"
run(
"(" + " && ".join(commands_to_execute) + f") 2>&1 |tee -a {build_log_path}",
shell=True,
check=True,
)
def remove_spack_package(spack_dir, package):
def remove_spack_package(spack_dir, package, build_log_path=None):
"""Remove spack package.
Used to remove global packages.
@@ -1209,6 +1230,8 @@ def remove_spack_package(spack_dir, package):
A Path object representing the path to the spack directory.
package : str
A string representing the name of the spack package to remove.
build_log_path : pathlib.Path, optional
A Path object representing the path to where the logs will be teed
"""
logging.info(f"Removing spack package {package}")
@@ -1218,7 +1241,11 @@ def remove_spack_package(spack_dir, package):
f". {spack_env}",
f"spack uninstall -y {package}",
]
run(" && ".join(commands_to_execute), shell=True, check=True)
run(
"(" + " && ".join(commands_to_execute) + f") 2>&1 |tee -a {build_log_path}",
shell=True,
check=True,
)
def start_new_environment(release, from_release, target_dir):
Loading