rm
This function can be use as a substitute of shutil.rmtree, that deals with the dry-run mode and symbolic links.
def rm(*file_or_tree):
"""
Removing some files or directories.
Does nothing in case dry run is set.
"""
LOGGER.action("remove {}".format(" ".join(map(str, file_or_tree))))
if dry_run:
return
for f in file_or_tree:
p = Path(f)
if not (p.exists() or p.is_symlink()):
LOGGER.debug(f"{f} not removed because already missing")
return
if p.is_dir() and not p.is_symlink():
shutil.rmtree(f)
else:
p.unlink()