From f36b411029d8cfe3f3d9570765c89fa0761f2c46 Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Mon, 2 May 2022 17:22:35 -0500 Subject: [PATCH 1/3] feat: add --stats --- btrfs-snapshots-diff.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/btrfs-snapshots-diff.py b/btrfs-snapshots-diff.py index 8cd1ce4..07e37cd 100755 --- a/btrfs-snapshots-diff.py +++ b/btrfs-snapshots-diff.py @@ -568,6 +568,9 @@ def main(): parser.add_argument( '-j', '--json', action='store_true', help='JSON output (commands only)' ) + parser.add_argument( + '--stats', action='store_true', help='Print simple statistics' + ) parser.add_argument( '--pretty', action='store_true', help=argparse.SUPPRESS ) @@ -619,6 +622,14 @@ def main(): exit(1) commands, paths = stream.decode(bogus=args.bogus) + if args.stats: + from collections import Counter + + print('Commands:') + command_counts = Counter(list(map(lambda d: d["command"], commands))) + for key, count in command_counts.most_common(): + print(f'{count}\t{key}') + if args.by_path: print(f'Found a valid Btrfs stream header, version {stream.version}\n') print_by_paths(paths, commands, args.filter, args.csv) From 901413c0a80850d091a3bff8d098c36c51a583cc Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Mon, 2 May 2022 17:33:30 -0500 Subject: [PATCH 2/3] exit afterwards --- btrfs-snapshots-diff.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/btrfs-snapshots-diff.py b/btrfs-snapshots-diff.py index 07e37cd..d1ba78a 100755 --- a/btrfs-snapshots-diff.py +++ b/btrfs-snapshots-diff.py @@ -630,6 +630,8 @@ def main(): for key, count in command_counts.most_common(): print(f'{count}\t{key}') + exit(0) + if args.by_path: print(f'Found a valid Btrfs stream header, version {stream.version}\n') print_by_paths(paths, commands, args.filter, args.csv) From 33403751385e9839951194f563d16a4110350507 Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:55:54 -0600 Subject: [PATCH 3/3] make it more pythonic --- btrfs-snapshots-diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/btrfs-snapshots-diff.py b/btrfs-snapshots-diff.py index d1ba78a..2a9ff6a 100755 --- a/btrfs-snapshots-diff.py +++ b/btrfs-snapshots-diff.py @@ -626,7 +626,7 @@ def main(): from collections import Counter print('Commands:') - command_counts = Counter(list(map(lambda d: d["command"], commands))) + command_counts = Counter(d["command"] for d in commands) for key, count in command_counts.most_common(): print(f'{count}\t{key}')