diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-04-24 20:50:36 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-04-24 20:50:36 +0100 |
commit | c1df493901693db36f6e89472df18737a23fdc61 (patch) | |
tree | fcb067713946c6b138f329a4d27a3587c61810b6 /license-summary | |
parent | c78dcbfe9c96696565b4d50187a81da5a87b8f04 (diff) | |
download | license-summary-c1df493901693db36f6e89472df18737a23fdc61.tar.gz |
Simplify code that produces reports
Diffstat (limited to 'license-summary')
-rwxr-xr-x | license-summary | 40 |
1 files 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') |