Skip to content
Snippets Groups Projects
Commit 197b8381 authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

Improvements and debugging for copyrightchecker

parent e72c0d43
Branches
Tags
No related merge requests found
...@@ -25,10 +25,11 @@ import re ...@@ -25,10 +25,11 @@ import re
from argparse import ArgumentParser from argparse import ArgumentParser
from os import walk from os import walk
from os.path import join from os.path import join
from pprint import pprint
# Copyright template for C++ code files and headers # Copyright template for C++ code files and headers
CPP_TEMPLATE = r'\/\* Copyright \(c\) 20\d\d(?:-20\d\d)? Skyward Experimental Rocketry\n' + \ CPP_TEMPLATE = r'\/\* Copyright \(c\) 20\d\d(?:-20\d\d)? Skyward Experimental Rocketry\n' + \
r' \* Authors: (.+)\n' + \ r' \* (Authors?): (.+)\n' + \
r' \*\n' + \ r' \*\n' + \
r' \* Permission is hereby granted, free of charge, to any person obtaining a copy\n' + \ r' \* Permission is hereby granted, free of charge, to any person obtaining a copy\n' + \
r' \* of this software and associated documentation files \(the "Software"\), to deal\n' + \ r' \* of this software and associated documentation files \(the "Software"\), to deal\n' + \
...@@ -48,6 +49,7 @@ r' \* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FR ...@@ -48,6 +49,7 @@ r' \* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FR
r' \* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n' + \ r' \* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n' + \
r' \* THE SOFTWARE.\n' + \ r' \* THE SOFTWARE.\n' + \
r' \*\/' r' \*\/'
AUTHOR_DELIMITER = ','
def config_cmd_parser(): def config_cmd_parser():
parser = ArgumentParser( parser = ArgumentParser(
...@@ -81,6 +83,10 @@ args = parser.parse_args() ...@@ -81,6 +83,10 @@ args = parser.parse_args()
totalCheckdFilesCounter = 0 totalCheckdFilesCounter = 0
filesWithErrorsCounter = 0 filesWithErrorsCounter = 0
# Statistics
authors = {}
averageAuthorsPerFile = 0
if(not args.directory): if(not args.directory):
print('[chopyrightchecker] No directory specified') print('[chopyrightchecker] No directory specified')
print('') print('')
...@@ -102,7 +108,33 @@ for dirpath, dirnames, filenames in walk(args.directory): ...@@ -102,7 +108,33 @@ for dirpath, dirnames, filenames in walk(args.directory):
filesWithErrorsCounter += 1 filesWithErrorsCounter += 1
# The file's copyright notice does not match the template! # The file's copyright notice does not match the template!
print('The file {0} does not match the correct copyright notice!'.format(currentFilepath)) print('[chopyrightchecker] Wrong copyright notice in file {0}'.format(currentFilepath))
else:
fileAuthors = [a.strip() for a in match.group(2).split(AUTHOR_DELIMITER)]
# Check the number of authors against 'Author' or `Authors`
if len(fileAuthors) == 1 and match.group(1)[-1] == 's':
print('[chopyrightchecker] \'Authors\' should to be changed to \'Author\' in {0}'.format(currentFilepath))
if len(fileAuthors) > 1 and match.group(1)[-1] != 's':
print('[chopyrightchecker] \'Author\' should to be changed to \'Authors\' in {0}'.format(currentFilepath))
# Save statistics on authors
for author in fileAuthors:
if author in authors:
authors[author] += 1
else:
authors[author] = 1
averageAuthorsPerFile += len(fileAuthors)
averageAuthorsPerFile /= totalCheckdFilesCounter
print('[chopyrightchecker] Checked {} files'.format(totalCheckdFilesCounter))
if filesWithErrorsCounter == 0:
print('[chopyrightchecker] All the files have the correct copyright notice')
else:
print('[chopyrightchecker] {} files do not match with the copyright template'.format(filesWithErrorsCounter))
print('Checked {0} files, {1} files do not match with the copyright template'.format(totalCheckdFilesCounter, filesWithErrorsCounter)) print('[chopyrightchecker] {:.2} authors per file'.format(averageAuthorsPerFile))
print('[chopyrightchecker] Number of mentrions per author:')
for author in authors:
print('[chopyrightchecker] {:3} - {}'.format(authors[author], author))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment