From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
To: Linux Media Mailing List <linux-media@vger.kernel.org>
Cc: "Mauro Carvalho Chehab" <mchehab+samsung@kernel.org>,
"Mauro Carvalho Chehab" <mchehab@infradead.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Joe Perches" <joe@perches.com>,
linux-kernel@vger.kernel.org, "Jonathan Corbet" <corbet@lwn.net>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Sven Eckelmann" <sven@narfation.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Thierry Reding" <treding@nvidia.com>,
"Vincenzo Frascino" <vincenzo.frascino@arm.com>
Subject: [PATCH 5/6] scripts/spdxcheck.py: keep track on what line SPDX header was found
Date: Thu, 5 Sep 2019 16:57:52 -0300 [thread overview]
Message-ID: <8d73ce62170345f748f990861bf5352c4423281b.1567712829.git.mchehab+samsung@kernel.org> (raw)
In-Reply-To: <cover.1567712829.git.mchehab+samsung@kernel.org>
According with Documentation/process/license-rules.rst, SPDX headers
can be found only at the first lines.
However, this script doesn't enforce it, and several files violate
that. It could be useful to be able to show a histogram with the
number of files that have the SPDX header on each line number.
This feature is optional, enabled with -H or --histogram.
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---
scripts/spdxcheck.py | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/scripts/spdxcheck.py b/scripts/spdxcheck.py
index 6374e078a5f2..c969b050366f 100755
--- a/scripts/spdxcheck.py
+++ b/scripts/spdxcheck.py
@@ -189,7 +189,9 @@ class id_parser(object):
# Should we check for more SPDX ids in the same file and
# complain if there are any?
#
- break
+ return self.curline - 1
+
+ return -1
except ParserException as pe:
if pe.tok:
@@ -200,7 +202,7 @@ class id_parser(object):
sys.stdout.write('%s: %d:0 %s\n' %(fname, self.curline, col, pe.txt))
self.spdx_errors += 1
-def scan_git_tree(tree):
+def scan_git_tree(ln_count, tree):
for el in tree.traverse():
# Exclude stuff which would make pointless noise
# FIXME: Put this somewhere more sensible
@@ -211,12 +213,15 @@ def scan_git_tree(tree):
if not os.path.isfile(el.path):
continue
with open(el.path, 'rb') as fd:
- parser.parse_lines(fd, args.maxlines, el.path)
+ ln = parser.parse_lines(fd, args.maxlines, el.path)
+ if ln >= 0:
+ ln_count[ln] += 1;
+ return ln_count
-def scan_git_subtree(tree, path):
+def scan_git_subtree(ln_count, tree, path):
for p in path.strip('/').split('/'):
tree = tree[p]
- scan_git_tree(tree)
+ scan_git_tree(ln_count, tree)
if __name__ == '__main__':
@@ -225,6 +230,7 @@ if __name__ == '__main__':
ap.add_argument('-m', '--maxlines', type=int, default=15,
help='Maximum number of lines to scan in a file. Default 15')
ap.add_argument('-v', '--verbose', action='store_true', help='Verbose statistics output')
+ ap.add_argument('-H', '--histogram', action='store_true', help='Verbose histogram about SPDX header position')
args = ap.parse_args()
# Sanity check path arguments
@@ -255,23 +261,31 @@ if __name__ == '__main__':
sys.stderr.write('%s\n' %traceback.format_exc())
sys.exit(1)
+ ln_count= [0] * args.maxlines
+
try:
if len(args.path) and args.path[0] == '-':
stdin = os.fdopen(sys.stdin.fileno(), 'rb')
- parser.parse_lines(stdin, args.maxlines, '-')
+ ln = parser.parse_lines(stdin, args.maxlines, '-')
+ if ln >= 0:
+ ln_count[ln] += 1;
+
else:
if args.path:
for p in args.path:
if os.path.isfile(p):
- parser.parse_lines(open(p, 'rb'), args.maxlines, p)
+ ln = parser.parse_lines(open(p, 'rb'), args.maxlines, p)
+ if ln >= 0:
+ ln_count[ln] += 1;
+
elif os.path.isdir(p):
- scan_git_subtree(repo.head.reference.commit.tree, p)
+ scan_git_subtree(ln_count, repo.head.reference.commit.tree, p)
else:
sys.stderr.write('path %s does not exist\n' %p)
sys.exit(1)
else:
# Full git tree scan
- scan_git_tree(repo.head.commit.tree)
+ scan_git_tree(ln_count, repo.head.commit.tree)
if args.verbose:
sys.stderr.write('\n')
@@ -284,6 +298,11 @@ if __name__ == '__main__':
sys.stderr.write('Lines checked: %12d\n' %parser.lines_checked)
sys.stderr.write('Files with SPDX: %12d\n' %parser.spdx_valid)
sys.stderr.write('Files with errors: %12d\n' %parser.spdx_errors)
+ sys.stderr.write('\n')
+ if args.histogram:
+ for i in range(0, len(ln_count)):
+ if ln_count[i] > 0:
+ sys.stderr.write('Files with SPDX at line #%-5d: %12d\n' % (i + 1, ln_count[i]))
sys.exit(0)
--
2.21.0
next prev parent reply other threads:[~2019-09-05 19:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-05 19:57 [PATCH 0/6] Address issues with SPDX requirements and PEP-263 Mauro Carvalho Chehab
2019-09-05 19:57 ` [PATCH 1/6] docs: sphinx: add SPDX header for some sphinx extensions Mauro Carvalho Chehab
2019-09-05 19:57 ` [PATCH 2/6] tools: perf: fix SPDX header in the light of PEP-263 Mauro Carvalho Chehab
2019-09-05 19:57 ` [PATCH 3/6] tools: intel_pstate_tracer.py: " Mauro Carvalho Chehab
2019-09-05 19:57 ` [PATCH 4/6] docs: license-rules.txt: cover SPDX headers on Python scripts Mauro Carvalho Chehab
2019-09-05 19:57 ` Mauro Carvalho Chehab [this message]
2019-09-05 19:57 ` [PATCH 6/6] scripts/spdxcheck.py: check if the line number follows the strict rule Mauro Carvalho Chehab
2019-09-06 12:04 ` [PATCH v2 " Mauro Carvalho Chehab
2019-09-05 20:05 ` [PATCH 0/6] Address issues with SPDX requirements and PEP-263 Joe Perches
2019-09-06 12:02 ` Mauro Carvalho Chehab
2019-09-06 12:22 ` Joe Perches
2019-09-07 13:34 ` Jonathan Corbet
2019-09-07 14:36 ` Markus Heiser
2019-09-07 16:22 ` Mauro Carvalho Chehab
2019-09-07 17:33 ` Markus Heiser
2019-09-07 18:04 ` Mauro Carvalho Chehab
2019-09-07 18:37 ` Markus Heiser
2019-09-07 21:17 ` Thomas Gleixner
2019-09-08 10:03 ` Matthew Wilcox
2019-09-08 14:46 ` Thomas Gleixner
2019-09-10 6:31 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8d73ce62170345f748f990861bf5352c4423281b.1567712829.git.mchehab+samsung@kernel.org \
--to=mchehab+samsung@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@infradead.org \
--cc=sven@narfation.org \
--cc=tglx@linutronix.de \
--cc=treding@nvidia.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=vincenzo.frascino@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).