diff --git a/easybuild/easyblocks/a/amber.py b/easybuild/easyblocks/a/amber.py index cfe62385b58..a9f064d0668 100644 --- a/easybuild/easyblocks/a/amber.py +++ b/easybuild/easyblocks/a/amber.py @@ -42,7 +42,7 @@ from easybuild.tools.build_log import EasyBuildError from easybuild.tools.modules import get_software_root from easybuild.tools.run import run_shell_cmd -from easybuild.tools.filetools import remove_dir, which +from easybuild.tools.filetools import clean_dir, which class EB_Amber(CMakeMake): @@ -130,8 +130,8 @@ def configure_step(self): return # CMake will search a previous install directory for Amber-compiled libs. We will therefore - # manually remove the install directory prior to configuration. - remove_dir(self.installdir) + # manually clean the install directory prior to configuration. + clean_dir(self.installdir) external_libs_list = [] diff --git a/easybuild/easyblocks/a/anaconda.py b/easybuild/easyblocks/a/anaconda.py index 3ef46f19a97..e2f64099808 100644 --- a/easybuild/easyblocks/a/anaconda.py +++ b/easybuild/easyblocks/a/anaconda.py @@ -33,7 +33,7 @@ import stat from easybuild.easyblocks.generic.binary import Binary -from easybuild.tools.filetools import adjust_permissions, remove_dir +from easybuild.tools.filetools import adjust_permissions, clean_dir from easybuild.tools.modules import MODULE_LOAD_ENV_HEADERS from easybuild.tools.run import run_shell_cmd @@ -59,7 +59,7 @@ def __init__(self, *args, **kwargs): def install_step(self): """Copy all files in build directory to the install directory""" - remove_dir(self.installdir) + clean_dir(self.installdir) install_script = self.src[0]['name'] adjust_permissions(os.path.join(self.builddir, install_script), stat.S_IRUSR | stat.S_IXUSR) diff --git a/easybuild/easyblocks/f/fdtd_solutions.py b/easybuild/easyblocks/f/fdtd_solutions.py index e9057991e03..95af2c77a84 100644 --- a/easybuild/easyblocks/f/fdtd_solutions.py +++ b/easybuild/easyblocks/f/fdtd_solutions.py @@ -64,7 +64,7 @@ def build_step(self): def install_step(self): """Install FDTD Solutions using copy tree.""" fdtd_dir = os.path.join(self.cfg['start_dir'], 'opt', 'lumerical', 'fdtd') - copy_dir(fdtd_dir, self.installdir, symlinks=self.cfg['keepsymlinks']) + copy_dir(fdtd_dir, self.installdir, symlinks=self.cfg['keepsymlinks'], dirs_exist_ok=True) def sanity_check_step(self): """Custom sanity check for FDTD Solutions.""" diff --git a/easybuild/easyblocks/g/gate.py b/easybuild/easyblocks/g/gate.py index 3ce302ac87b..9530c624073 100644 --- a/easybuild/easyblocks/g/gate.py +++ b/easybuild/easyblocks/g/gate.py @@ -40,6 +40,7 @@ from easybuild.easyblocks.generic.cmakemake import CMakeMake from easybuild.framework.easyconfig import CUSTOM from easybuild.tools.build_log import EasyBuildError +from easybuild.tools.filetools import clean_dir, copy_dir from easybuild.tools.run import run_shell_cmd from easybuild.tools.systemtools import get_shared_lib_ext @@ -138,8 +139,8 @@ def install_step(self): # copy all the things try: - shutil.rmtree(self.installdir) - shutil.copytree(self.cfg['start_dir'], self.installdir) + clean_dir(self.installdir) + copy_dir(self.cfg['start_dir'], self.installdir, dirs_exist_ok=True) except OSError as err: raise EasyBuildError("Failed to copy %s to %s: %s", self.cfg['start_dir'], self.installdir, err) diff --git a/easybuild/easyblocks/g/go.py b/easybuild/easyblocks/g/go.py index d3967539a1e..d51b3f7574f 100644 --- a/easybuild/easyblocks/g/go.py +++ b/easybuild/easyblocks/g/go.py @@ -29,13 +29,12 @@ @author: Kenneth Hoste (HPC-UGent) """ import os -import shutil from easybuild.tools import LooseVersion from easybuild.easyblocks.generic.configuremake import ConfigureMake from easybuild.tools.build_log import EasyBuildError -from easybuild.tools.filetools import remove_dir +from easybuild.tools.filetools import clean_dir, copy_dir from easybuild.tools.run import run_shell_cmd from easybuild.tools.modules import get_software_root @@ -76,7 +75,7 @@ def install_step(self): run_shell_cmd(cmd, work_dir=srcdir) try: - remove_dir(self.installdir) - shutil.copytree(self.cfg['start_dir'], self.installdir, symlinks=self.cfg['keepsymlinks']) + clean_dir(self.installdir) + copy_dir(self.cfg['start_dir'], self.installdir, symlinks=self.cfg['keepsymlinks'], dirs_exist_ok=True) except OSError as err: raise EasyBuildError("Failed to copy installation to %s: %s", self.installdir, err) diff --git a/easybuild/easyblocks/generic/binary.py b/easybuild/easyblocks/generic/binary.py index d05916da6f6..8c286ed808c 100644 --- a/easybuild/easyblocks/generic/binary.py +++ b/easybuild/easyblocks/generic/binary.py @@ -32,14 +32,13 @@ @author: Jens Timmerman (Ghent University) """ -import shutil import os import stat from easybuild.framework.easyblock import EasyBlock from easybuild.framework.easyconfig import CUSTOM from easybuild.tools.build_log import EasyBuildError -from easybuild.tools.filetools import adjust_permissions, copy_file, mkdir, remove_dir +from easybuild.tools.filetools import adjust_permissions, clean_dir, copy_dir, copy_file, mkdir from easybuild.tools.run import run_shell_cmd @@ -116,8 +115,8 @@ def install_step(self): if install_cmd is None and install_cmds is None: try: # shutil.copytree doesn't allow the target directory to exist already - remove_dir(self.installdir) - shutil.copytree(self.cfg['start_dir'], self.installdir, symlinks=self.cfg['keepsymlinks']) + clean_dir(self.installdir) + copy_dir(self.cfg['start_dir'], self.installdir, symlinks=self.cfg['keepsymlinks'], dirs_exist_ok=True) except OSError as err: raise EasyBuildError("Failed to copy %s to %s: %s", self.cfg['start_dir'], self.installdir, err) else: @@ -142,14 +141,8 @@ def post_processing_step(self): if self.cfg.get('staged_install', False): staged_installdir = self.installdir self.installdir = self.actual_installdir - try: - # copytree expects target directory to not exist yet - if os.path.exists(self.installdir): - remove_dir(self.installdir) - shutil.copytree(staged_installdir, self.installdir) - except OSError as err: - raise EasyBuildError("Failed to move staged install from %s to %s: %s", - staged_installdir, self.installdir, err) + clean_dir(self.installdir) + copy_dir(staged_installdir, self.installdir, dirs_exist_ok=True) super().post_processing_step() diff --git a/easybuild/easyblocks/generic/tarball.py b/easybuild/easyblocks/generic/tarball.py index 9930aadc28d..04cf8e59e5d 100644 --- a/easybuild/easyblocks/generic/tarball.py +++ b/easybuild/easyblocks/generic/tarball.py @@ -40,7 +40,7 @@ from easybuild.framework.extensioneasyblock import ExtensionEasyBlock from easybuild.framework.easyconfig import CUSTOM from easybuild.tools.build_log import EasyBuildError -from easybuild.tools.filetools import copy_dir, extract_file, remove_dir +from easybuild.tools.filetools import clean_dir, copy_dir, extract_file, remove_dir from easybuild.tools.run import run_shell_cmd @@ -102,27 +102,23 @@ def install_step(self, src=None): if self.cfg['install_type'] == 'subdir': # Wipe and install in a sub-directory with the name of the package install_path = os.path.join(self.installdir, self.name.lower()) - dirs_exist_ok = False install_logmsg = "Copying tarball contents of %s to sub-directory %s..." + remove_dir(install_path) elif self.cfg['install_type'] == 'merge': # Enable merging with root of existing installdir install_path = self.installdir - dirs_exist_ok = True install_logmsg = "Merging tarball contents of %s into %s..." elif self.cfg['install_type'] is None: - # Wipe and copy root of installation directory (default) + # Clean and copy root of installation directory (default) install_path = self.installdir - dirs_exist_ok = False - install_logmsg = "Copying tarball contents of %s into %s after wiping it..." + install_logmsg = "Copying tarball contents of %s into %s after cleaning it..." + clean_dir(install_path) else: raise EasyBuildError("Unknown option '%s' for index_type.", self.cfg['install_type']) self.log.info(install_logmsg, self.name, install_path) - if not dirs_exist_ok: - remove_dir(install_path) - - copy_dir(source_path, install_path, symlinks=self.cfg['keepsymlinks'], dirs_exist_ok=dirs_exist_ok) + copy_dir(source_path, install_path, symlinks=self.cfg['keepsymlinks'], dirs_exist_ok=True) def sanity_check_rpath(self): """Skip the rpath sanity check, this is binary software""" diff --git a/easybuild/easyblocks/j/java.py b/easybuild/easyblocks/j/java.py index 84944bf7096..f98f67ede61 100644 --- a/easybuild/easyblocks/j/java.py +++ b/easybuild/easyblocks/j/java.py @@ -36,7 +36,7 @@ from easybuild.easyblocks.generic.packedbinary import PackedBinary from easybuild.tools.build_log import EasyBuildError from easybuild.tools.config import build_option -from easybuild.tools.filetools import adjust_permissions, change_dir, copy_dir, copy_file, remove_dir, which +from easybuild.tools.filetools import adjust_permissions, change_dir, clean_dir, copy_dir, copy_file, which from easybuild.tools.run import run_shell_cmd from easybuild.tools.systemtools import AARCH64, POWER, RISCV64, X86_64, get_cpu_architecture, get_shared_lib_ext from easybuild.tools.utilities import nub @@ -82,8 +82,8 @@ def extract_step(self): def install_step(self): """Custom install step: just copy unpacked installation files.""" if LooseVersion(self.version) < LooseVersion('1.7'): - remove_dir(self.installdir) - copy_dir(os.path.join(self.builddir, 'jdk%s' % self.version), self.installdir) + clean_dir(self.installdir) + copy_dir(os.path.join(self.builddir, 'jdk%s' % self.version), self.installdir, dirs_exist_ok=True) else: PackedBinary.install_step(self) diff --git a/easybuild/easyblocks/m/molpro.py b/easybuild/easyblocks/m/molpro.py index 848989c98d8..1b2b5b72251 100644 --- a/easybuild/easyblocks/m/molpro.py +++ b/easybuild/easyblocks/m/molpro.py @@ -29,7 +29,6 @@ """ import glob import os -import shutil import re from easybuild.easyblocks.generic.binary import Binary @@ -39,7 +38,7 @@ from easybuild.tools import LooseVersion from easybuild.tools.build_log import EasyBuildError from easybuild.tools.config import build_option -from easybuild.tools.filetools import apply_regex_substitutions, change_dir, mkdir, read_file, symlink +from easybuild.tools.filetools import apply_regex_substitutions, change_dir, clean_dir, mkdir, read_file, symlink from easybuild.tools.run import run_shell_cmd @@ -208,8 +207,8 @@ def install_step(self): for src in self.src: if LooseVersion(self.version) >= LooseVersion('2015'): - # install dir must be non-existent - shutil.rmtree(self.installdir) + # install dir must be non-existent or empty + clean_dir(self.installdir) cmd = "./{0} -batch -prefix {1}".format(src['name'], self.installdir) else: cmd = "./{0} -batch -instbin {1}/bin -instlib {1}/lib".format(src['name'], self.installdir) diff --git a/easybuild/easyblocks/t/tkinter.py b/easybuild/easyblocks/t/tkinter.py index 31a0b776f09..26e54e30a04 100644 --- a/easybuild/easyblocks/t/tkinter.py +++ b/easybuild/easyblocks/t/tkinter.py @@ -39,7 +39,7 @@ from easybuild.easyblocks.generic.pythonpackage import det_pylibdir from easybuild.easyblocks.python import EB_Python from easybuild.tools.build_log import EasyBuildError -from easybuild.tools.filetools import move_file, remove_dir +from easybuild.tools.filetools import clean_dir, move_file from easybuild.tools.modules import get_software_root from easybuild.tools.systemtools import get_shared_lib_ext @@ -95,7 +95,7 @@ def install_step(self): # Reset the install directory and remove it if it already exists. It will not have been removed automatically # at the start of the install step, as self.installdir pointed at the temporary install directory. self.installdir = self.orig_installdir - remove_dir(self.installdir) + clean_dir(self.installdir) dest_pylibdir = os.path.join(self.installdir, det_pylibdir())