Code factorisation

master
Lertsenem 2015-09-16 18:53:23 +02:00
parent b473e698f1
commit 310535f2b3
1 changed files with 1 additions and 24 deletions

View File

@ -147,30 +147,7 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
# Everything went well, time to remove the backup
# --------------------------------------
if overwrite:
# As before, try it as a dir first
try:
logger.info("Removing backup directory %s" % (dst + ".bak"))
shutil.rmtree(dst + ".bak")
except FileNotFoundError:
logger.warning("Backup file %s seems to be already gone"
% (dst + ".bak"))
except PermissionError:
logger.warning("Cannot remove backup dir %s, you will have to " \
"do it manually"
% (dst + ".bak"))
# If not, try it as a file
except NotADirectoryError:
try:
logger.info("Removing backup file %s" % (dst + ".bak"))
os.remove(dst + ".bak")
except PermissionError:
logger.warning("Cannot remove backup file %s, you will have " \
"to do it manually"
% (dst + ".bak"))
delete_file_or_dir((dst + ".bak"), logger)
# The End.
return True