From 6d66ceb7e93ffabd96b32b72901ea7625b0134ba Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:15:44 -0500 Subject: [PATCH] Don't call max() in every iteration --- bin/calculate_mirror_size.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/calculate_mirror_size.py b/bin/calculate_mirror_size.py index 82867db..86cecba 100755 --- a/bin/calculate_mirror_size.py +++ b/bin/calculate_mirror_size.py @@ -69,11 +69,12 @@ if __name__ == "__main__": ) with TemporaryDirectory() as tmp_dir: dir_sizes = [] + max_dir_len = len(max(mirror_dirs, key=len)) for dir in mirror_dirs: rsync_cmd = f"rsync -a -n --stats {args['-R']}/{dir}/ | grep '^Total file size' | tr -d ','" output = subprocess.run(rsync_cmd, shell=True, capture_output=True) logstr = ( - dir.rjust(len(max(mirror_dirs, key=len))) + dir.rjust(max_dir_len) + " " + human_bytes(int(output.stdout.split()[3])) )