diff --git a/csppfetch/__init__.py b/csppfetch/__init__.py index e2db4ef0291ee29f9b209d03f4c93b880cc64f4c..d444babf4325264542833d2714f18fa01695c564 100644 --- a/csppfetch/__init__.py +++ b/csppfetch/__init__.py @@ -511,13 +511,23 @@ class CleaningStats: self.size_deleted = 0 self.num_kept = 0 self.size_kept = 0 + def deleted(self, filename, size): self.num_deleted += 1 self.size_deleted += size + def kept(self, filename, size): self.num_kept += 1 self.size_kept += size + def report(self): + """ Return list of strings suitable for output to user, one per line """ + return [ + f'Removed {self.num_deleted:,} files totaling {human_bytes(self.size_deleted)} bytes', + f'Kept {self.num_kept:,} files totaling {human_bytes(self.size_kept)} bytes', + ] + + def unlink_if_old(filename, expiration_time, stats): """ If filename's mtime is older than expiration_time, remove it diff --git a/example/aitf-clean-temporal b/example/aitf-clean-temporal index 45cea89a1d3db16c19a9b4935f24d986ad40e422..87376c61b4bc1177bda6c2d973c07855568872f3 100755 --- a/example/aitf-clean-temporal +++ b/example/aitf-clean-temporal @@ -112,8 +112,8 @@ def main(): csppfetch.delete_old_files(args.temporal_dir+"/L2", args.oldest, stats) if args.want_summary: sys.stdout.write('Expiring Old Temporal Data Summary\n') - sys.stdout.write(f' Removed {stats.num_deleted} files totaling {stats.size_deleted} bytes\n') - sys.stdout.write(f' Kept {stats.num_kept} files totaling {stats.size_kept} bytes\n') + for line in stats.report(): + sys.stdout.write(f" {line}\n") else: # No lock sys.stdout.write("Cleaning skipped; another process is already doing so.") diff --git a/example/aitf-data-for-run b/example/aitf-data-for-run index 149695e4d9e4cf6d138a1d35c01b5dfaadf8773c..a373c20e80413a67ef6d4b29eeb0b930469b057f 100755 --- a/example/aitf-data-for-run +++ b/example/aitf-data-for-run @@ -171,8 +171,8 @@ def main(): stats = aitf.ancil.csppfetch.delete_old_files(args.cache, expiration) if args.want_summary: sys.stdout.write('Expiring Old Data Summary\n') - sys.stdout.write(f' Removed {stats.num_deleted} files totaling {stats.size_deleted} bytes\n') - sys.stdout.write(f' Kept {stats.num_kept} files totaling {stats.size_kept} bytes\n') + for line in stats.report(): + sys.stdout.write(f' {line}\n') return 0 diff --git a/example/aitf-update-cache b/example/aitf-update-cache index 9797d539d57951ba0a1375924397e860906d9deb..6d7df93dc885bb71184557dca61b6e32f06d8386 100755 --- a/example/aitf-update-cache +++ b/example/aitf-update-cache @@ -153,8 +153,8 @@ def main(): stats = aitf.ancil.csppfetch.delete_old_files(args.dir, expiration) if args.want_summary: sys.stdout.write('Expiring Old Data Summary\n') - sys.stdout.write(f' Removed {stats.num_deleted} files totaling {stats.size_deleted} bytes\n') - sys.stdout.write(f' Kept {stats.num_kept} files totaling {stats.size_kept} bytes\n') + for line in stats.report(): + sys.stdout.write(f' {line}\n') return 0