enhanced boilerplate checking

Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
Mike Brown 2018-01-11 13:39:14 -06:00
parent 5bfa5e451a
commit bf157d2fe5
7 changed files with 50 additions and 18 deletions

View File

@ -1,4 +1,4 @@
# Copyright YEAR The Kubernetes Authors. # Copyright YEAR AUTHORS.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -11,4 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.

View File

@ -1,4 +1,4 @@
# Copyright YEAR The Kubernetes Authors. # Copyright YEAR AUTHORS.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -11,4 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright YEAR The Kubernetes Authors. Copyright YEAR AUTHORS.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -13,4 +13,3 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright 2015 The Kubernetes Authors. # Copyright 2015 The Kubernetes Authors.
# Copyright 2018 The Containerd Authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -100,12 +101,13 @@ def file_passes(filename, refs, regexs):
file=verbose_out) file=verbose_out)
return False return False
# trim our file to the same number of lines as the reference file
data = data[:len(ref)]
p = regexs["year"] p = regexs["year"]
for d in data: found = 0
for d in ref:
if p.search(d): if p.search(d):
found = 1
break
if found == 0:
print('File %s is missing the year' % filename, file=verbose_out) print('File %s is missing the year' % filename, file=verbose_out)
return False return False
@ -113,8 +115,38 @@ def file_passes(filename, refs, regexs):
p = regexs["date"] p = regexs["date"]
for i, d in enumerate(data): for i, d in enumerate(data):
(data[i], found) = p.subn('YEAR', d) (data[i], found) = p.subn('YEAR', d)
if found != 0:
p = regexs["authors"]
found = 0
for d in ref:
if p.search(d):
found = 1
break break
if found == 0:
print('File %s is missing AUTHORS' % filename, file=verbose_out)
return False
# Replace all occurrences of the regex "The validNameHere Authors" with "AUTHORS"
p = regexs["auth"]
for i, d in enumerate(data):
(data[i], found) = p.subn('AUTHORS', d)
# Remove extra copyright notices only one is necessary
p = regexs["copyright"]
keepgoing = 1
while keepgoing == 1:
keepgoing = 0
count = 0
for d in data:
if p.search(d):
count = count + 1
if count > 1:
keepgoing = 1
data.remove(d)
break
# trim our file to the same number of lines as the reference file
data = data[:len(ref)]
# if we don't match the reference at this point, fail # if we don't match the reference at this point, fail
if ref != data: if ref != data:
@ -185,6 +217,10 @@ def get_regexs():
regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE) regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE)
# strip #!.* from shell scripts # strip #!.* from shell scripts
regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE) regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE)
regexs["authors"] = re.compile( 'AUTHORS' )
authors = [ 'The Kubernetes Authors', 'The Containerd Authors' ]
regexs["auth"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), authors)) )
regexs["copyright"] = re.compile( 'Copyright YEAR AUTHORS' )
return regexs return regexs
def main(): def main():

View File

@ -1,4 +1,4 @@
# Copyright YEAR The Kubernetes Authors. # Copyright YEAR AUTHORS.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -11,4 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.

View File

@ -1,4 +1,4 @@
# Copyright YEAR The Kubernetes Authors. # Copyright YEAR AUTHORS.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -11,4 +11,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# Copyright 2017 The Kubernetes Authors. # Copyright 2017 The Kubernetes Authors.
# Copyright 2018 The Containerd Authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.