Refactored to deleteVersion function for better readability

This commit is contained in:
Kevin Veen-Birkenbach 2024-01-12 20:11:12 +01:00
parent eac64089f8
commit 695618a170

View File

@ -36,6 +36,13 @@ def isDirectoryDeletable(version, versions_directory, version_path):
print("Directory %s is used by another process. Skipped." % (version_path)) print("Directory %s is used by another process. Skipped." % (version_path))
return False return False
def deleteVersion(version_path, backups_folder_path):
print("Deleting %s to free space." % (version_path))
shutil.rmtree(version_path)
new_disc_usage_percent=psutil.disk_usage(backups_folder_path).percent
difference_percent=old_disc_usage_percent-new_disc_usage_percent
print("{:6.2f} %% of drive freed".format(difference_percent))
backups_folder_path=args.backups_folder_path backups_folder_path=args.backups_folder_path
for host_backup_directory_name in os.listdir(backups_folder_path): for host_backup_directory_name in os.listdir(backups_folder_path):
host_backup_directory_path = os.path.join(backups_folder_path, host_backup_directory_name) host_backup_directory_path = os.path.join(backups_folder_path, host_backup_directory_name)
@ -54,11 +61,7 @@ for host_backup_directory_name in os.listdir(backups_folder_path):
continue continue
if isSmallerThenMaximumBackupSize(maximum_backup_size_percent,backups_folder_path): if isSmallerThenMaximumBackupSize(maximum_backup_size_percent,backups_folder_path):
print("Deleting %s to free space." % (version_path)) deleteVersion(version_path, backups_folder_path)
shutil.rmtree(version_path)
new_disc_usage_percent=psutil.disk_usage(backups_folder_path).percent
difference_percent=old_disc_usage_percent-new_disc_usage_percent
print("{:6.2f} %% of drive freed".format(difference_percent))
continue continue
print_used_disc_space(backups_folder_path) print_used_disc_space(backups_folder_path)