Skip to content
Snippets Groups Projects

Try remove cmd

Merged Ashwin Kumar Karnad requested to merge try-remove-cmd into main
Files
2
+ 24
9
@@ -980,25 +980,40 @@ def install_environment(
@@ -980,25 +980,40 @@ def install_environment(
)
)
def remove_environment(release, package_sets, target_dir):
def remove_environment(mpsd_release, root_dir, package_sets="NONE", force_remove=False):
"""Remove release from installation."""
"""Remove release from installation."""
msg = (
msg = (
f"Removing release {release} with package_sets {package_sets} from {target_dir}"
f"Removing release {mpsd_release}"
 
f" with package_sets {package_sets} from {root_dir}"
)
)
logging.warning(msg)
logging.warning(msg)
if toolchains == "NONE":
if package_sets == "NONE":
logging.warning(
logging.warning(
"Please specify toolchains to remove, or 'ALL' to remove all toolchains"
"Please specify package_sets to remove, or 'ALL' to remove all toolchains"
)
)
sys.exit(1)
sys.exit(1)
if "ALL" in toolchains:
if "ALL" in package_sets:
# we need to remove the entire release folder
# we need to remove the entire release folder
logging.info(
logging.warning(
f"Removing release {mpsd_release} from {root_dir}"
f"Removing release {mpsd_release} from {root_dir}"
"do you want to continue? [y/n]"
"do you want to continue? [y/n]"
)
)
if not force or input().lower() == "y":
if force_remove or input().lower() == "y":
shutil.rmtree(root_dir / mpsd_release)
folders_to_remove = os.listdir(root_dir / mpsd_release)
 
# skip logs folder
 
folders_to_remove.remove("logs")
 
for folder in folders_to_remove:
 
shutil.rmtree(root_dir / mpsd_release / folder)
 
sys.exit(0)
 
for package_set in package_sets:
 
# we load the spack environment and remove the package_set
 
spack_env = ""
 
commands_to_execute = [
 
f"source {spack_env}",
 
f"spack env remove -y {package_set}",
 
]
 
run(" && ".join(commands_to_execute), shell=True, check=True)
 
def start_new_environment(release, from_release, target_dir):
def start_new_environment(release, from_release, target_dir):
"""Start new MPSD software environment version."""
"""Start new MPSD software environment version."""
@@ -1191,7 +1206,7 @@ def main():
@@ -1191,7 +1206,7 @@ def main():
# Check the command and run related function
# Check the command and run related function
if args.action == "remove":
if args.action == "remove":
remove_environment(args.release, args.package_set, root_dir)
remove_environment(args.release, root_dir, args.package_set)
elif args.action == "start-new":
elif args.action == "start-new":
start_new_environment(args.from_release, args.to_release, root_dir)
start_new_environment(args.from_release, args.to_release, root_dir)
elif args.action == "install":
elif args.action == "install":
Loading