in pantri/scripts/lib/utils.py [0:0]
def remove(paths):
"""
remove(paths)
This will remove files/directories recursively. Supports "paths" being a
list of paths and wildcard in file names.
Remove does nothing if path does not exist.
"""
# recursively call remove if paths is a list
if isinstance(paths, list):
for file_path in paths:
remove(file_path)
return
# Using glob to support wildcard in filenames
for file_path in glob.glob(paths):
# Only attempt to remove path if it exists
if not os.path.exists(file_path):
continue
# Remove directory
if os.path.isdir(file_path):
try:
shutil.rmtree(file_path)
except Exception:
logging.getLogger("pantri").error("Error: %s not removed" % file_path)
continue
# Remove files.
if os.path.isfile(file_path):
try:
os.remove(file_path)
except Exception:
logging.getLogger("pantri").error("Error: %s not removed" % file_path)