History

scripts/spdxcheck: Add directory statistics

For better insights. Directories accounted: 4646 Directories complete: 2565 55%

Thomas Gleixner committed 4 years ago

Commit a377ce71 parent 149d6231 file · +27 −0Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/spdxcheck.py+27−0
@@ -28,6 +28,15 @@ class SPDXdata(object): · 27 unmodified lines
2828 self.licenses = [ ]
2929 self.exceptions = { }
3030
31+class dirinfo(object):
32+ def __init__(self):
33+ self.missing = 0
34+ self.total = 0
35+
36+ def update(self, miss):
37+ self.total += 1
38+ self.missing += miss
39+
3140 # Read the spdx data from the LICENSES directory
3241 def read_spdxdata(repo):
3342
@@ -93,6 +102,7 @@ class id_parser(object): · 59 unmodified lines
93102 self.checked = 0
94103 self.spdx_valid = 0
95104 self.spdx_errors = 0
105+ self.spdx_dirs = {}
96106 self.curline = 0
97107 self.deepest = 0
98108
@@ -167,6 +177,7 @@ class id_parser(object): · 68 unmodified lines
167177 def parse_lines(self, fd, maxlines, fname):
168178 self.checked += 1
169179 self.curline = 0
180+ fail = 1
170181 try:
171182 for line in fd:
172183 line = line.decode(locale.getpreferredencoding(False), errors='ignore')
@@ -192,6 +203,7 @@ class id_parser(object): · 19 unmodified lines
192203 # Should we check for more SPDX ids in the same file and
193204 # complain if there are any?
194205 #
206+ fail = 0
195207 break
196208
197209 except ParserException as pe:
@@ -203,6 +215,11 @@ class id_parser(object): · 5 unmodified lines
203215 sys.stdout.write('%s: %d:0 %s\n' %(fname, self.curline, pe.txt))
204216 self.spdx_errors += 1
205217
218+ base = os.path.dirname(fname)
219+ di = self.spdx_dirs.get(base, dirinfo())
220+ di.update(fail)
221+ self.spdx_dirs[base] = di
222+
206223 def scan_git_tree(tree):
207224 for el in tree.traverse():
208225 # Exclude stuff which would make pointless noise
@@ -289,6 +306,16 @@ if __name__ == '__main__': · 80 unmodified lines
289306 pc = int(100 * parser.spdx_valid / parser.checked)
290307 sys.stderr.write('Files with SPDX: %12d %3d%%\n' %(parser.spdx_valid, pc))
291308 sys.stderr.write('Files with errors: %12d\n' %parser.spdx_errors)
309+ ndirs = len(parser.spdx_dirs)
310+ dirsok = 0
311+ if ndirs:
312+ sys.stderr.write('\n')
313+ sys.stderr.write('Directories accounted: %8d\n' %ndirs)
314+ for di in parser.spdx_dirs.values():
315+ if not di.missing:
316+ dirsok += 1
317+ pc = int(100 * dirsok / ndirs)
318+ sys.stderr.write('Directories complete: %8d %3d%%\n' %(dirsok, pc))
292319
293320 sys.exit(0)
294321