From 9ccda29f22dc39c310b512b7f7a0f933fb3a0f6c Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Nov 05 2017 18:24:19 +0000 Subject: Output tables nicely --- diff --git a/analyze-protections.py b/analyze-protections.py index 4e7c03a..1378732 100755 --- a/analyze-protections.py +++ b/analyze-protections.py @@ -186,6 +186,9 @@ def analyze(Types, Protections, name): if type in {'simple', 'forking', 'dbus', 'notify'}: count_protections(Protections, name, config) + return True + + return False def find_srpm_names(files): ans = collections.defaultdict(list) @@ -203,6 +206,12 @@ def find_srpm_names(files): return ans +def report_counter(title, c, total): + print(f'####################### {title:^20} ########################') + width = max(len(k) for k in c) + for k,v in c.most_common(): + print(f'{k:<{width}} {v:>8} {v/total:6.1%}') + if __name__ == '__main__': opts = parser().parse_args() @@ -211,6 +220,7 @@ if __name__ == '__main__': Types = collections.Counter() Protections = collections.Counter() + n1 = 0 for srpm, files in by_srpm.items(): for file in files: if file.is_symlink(): @@ -218,9 +228,10 @@ if __name__ == '__main__': continue print(f'==================== {file.name:<20} {"(" + srpm + ")":<15} =======================') try: - analyze(Types, Protections, file.name) + n1 += analyze(Types, Protections, file.name) except SyntaxError as e: print(e) - pprint.pprint(Types) - pprint.pprint(Protections) + n = sum(Types.values()) + report_counter('Type=', Types, n) + report_counter('Protections', Protections, n1)