Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Emilio Corigliano
Skyward Boardcore
Commits
197b8381
Commit
197b8381
authored
4 years ago
by
Alberto Nidasio
Browse files
Options
Downloads
Patches
Plain Diff
Improvements and debugging for copyrightchecker
parent
e72c0d43
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/copyrightchecker.py
+37
-5
37 additions, 5 deletions
scripts/copyrightchecker.py
with
37 additions
and
5 deletions
scripts/copyrightchecker.py
+
37
−
5
View file @
197b8381
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment