From c78dcbfe9c96696565b4d50187a81da5a87b8f04 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 24 Apr 2013 20:38:38 +0100 Subject: Add option --check --- license-summary | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/license-summary b/license-summary index 05ed6d1..c719389 100755 --- a/license-summary +++ b/license-summary @@ -37,6 +37,11 @@ class LicenseSummary(cliapp.Application): 'from report of files without a license summary', metavar='REGEXP') + self.settings.boolean( + ['check'], + 'fail if any files are missing a license summary, ' + 'or there are more than one summaries in use') + def setup(self): self.pat = re.compile(r'=\*= [Ll]icen[cs]es?:\s*(?P\S.*\S)\s*=\*=') self.summaries = {} -- cgit v1.2.1 From c1df493901693db36f6e89472df18737a23fdc61 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 24 Apr 2013 20:50:36 +0100 Subject: Simplify code that produces reports --- license-summary | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/license-summary b/license-summary index c719389..bc2494a 100755 --- a/license-summary +++ b/license-summary @@ -48,24 +48,32 @@ class LicenseSummary(cliapp.Application): self.filenames = set() def cleanup(self): - for s in sorted(self.summaries.keys()): - ss = sorted(self.summaries[s]) - self.output.write('%s (%d):\n' % (s, len(ss))) - for filename in ss: - self.output.write('\t%s\n' % filename) - if filename in self.filenames: - self.filenames.remove(filename) - for pattern in self.settings['exclude']: - remove = [x for x in self.filenames if re.search(pattern, x)] - for filename in remove: - self.filenames.remove(filename) - if self.filenames: - self.output.write('no summary (%d):\n' % len(self.filenames)) - for filename in sorted(self.filenames): - self.output.write('\t%s\n' % filename) + for summary in sorted(self.summaries.keys()): + self.report_group(summary, self.summaries[summary]) + + without_summary = self.filenames_without_summary() + if without_summary: + self.report_group('no summary', without_summary) + + def report_group(self, summary, filenames): + self.output.write('%s (%d):\n' % (summary, len(filenames))) + for filename in sorted(filenames): + self.output.write('\t%s\n' % filename) + + def filenames_without_summary(self): + return set(self.filenames).difference(self.filenames_with_summaries()) + + def filenames_with_summaries(self): + result = set() + for filenames in self.summaries.values(): + result = result.union(set(filenames)) + return result + + def process_input(self, name): + self.filenames.add(name) + return cliapp.Application.process_input(self, name) def process_input_line(self, filename, line): - self.filenames.add(filename) m = self.pat.search(line) if m: s = m.group('summary') -- cgit v1.2.1 From 7d492d428e526bfd1ad6aa469743dc31e2b161ad Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 24 Apr 2013 20:52:30 +0100 Subject: Check that all files have a license --- license-summary | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/license-summary b/license-summary index bc2494a..22b7181 100755 --- a/license-summary +++ b/license-summary @@ -23,6 +23,7 @@ import cliapp import re +import sys __version__ = '0.0' @@ -55,6 +56,17 @@ class LicenseSummary(cliapp.Application): if without_summary: self.report_group('no summary', without_summary) + if self.settings['check']: + error = 0 + if without_summary: + sys.stderr.write( + 'ERROR: The following files have no license summary:\n') + for filename in sorted(without_summary): + sys.stderr.write(' %s\n' % filename) + error = 1 + + sys.exit(error) + def report_group(self, summary, filenames): self.output.write('%s (%d):\n' % (summary, len(filenames))) for filename in sorted(filenames): -- cgit v1.2.1 From caeaeac50502940e5a372ce40c4fed7d87b62a72 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 24 Apr 2013 20:53:45 +0100 Subject: Check for more than one summary being used --- license-summary | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/license-summary b/license-summary index 22b7181..90d07c8 100755 --- a/license-summary +++ b/license-summary @@ -58,6 +58,7 @@ class LicenseSummary(cliapp.Application): if self.settings['check']: error = 0 + if without_summary: sys.stderr.write( 'ERROR: The following files have no license summary:\n') @@ -65,6 +66,9 @@ class LicenseSummary(cliapp.Application): sys.stderr.write(' %s\n' % filename) error = 1 + if len(self.summaries) > 1: + sys.stderr.write('ERROR: More than one summary in use\n') + sys.exit(error) def report_group(self, summary, filenames): -- cgit v1.2.1