Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit c7420db

Browse files
committed
added boilerplate to all files and a check in the test .sh file
1 parent 8be7997 commit c7420db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+989
-4
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Copyright 2016 The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Bump these on release
116
VERSION_MAJOR ?= 0
217
VERSION_MINOR ?= 2
318
VERSION_BUILD ?= 0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright YEAR The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+

boilerplate/boilerplate.Makefile.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright YEAR The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+

boilerplate/boilerplate.go.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Copyright YEAR The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+

boilerplate/boilerplate.py

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2015 Google, Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import print_function
18+
19+
import argparse
20+
import glob
21+
import json
22+
import mmap
23+
import os
24+
import re
25+
import sys
26+
27+
parser = argparse.ArgumentParser()
28+
parser.add_argument("filenames", help="list of files to check, all files if unspecified", nargs='*')
29+
30+
rootdir = os.path.dirname(__file__) + "/../"
31+
rootdir = os.path.abspath(rootdir)
32+
parser.add_argument("--rootdir", default=rootdir, help="root directory to examine")
33+
34+
default_boilerplate_dir = os.path.join(rootdir, "/boilerplate")
35+
parser.add_argument("--boilerplate-dir", default=default_boilerplate_dir)
36+
args = parser.parse_args()
37+
38+
39+
def get_refs():
40+
refs = {}
41+
42+
for path in glob.glob(os.path.join(args.boilerplate_dir, "boilerplate.*.txt")):
43+
extension = os.path.basename(path).split(".")[1]
44+
45+
ref_file = open(path, 'r')
46+
ref = ref_file.read().splitlines()
47+
ref_file.close()
48+
refs[extension] = ref
49+
50+
return refs
51+
52+
def file_passes(filename, refs, regexs):
53+
try:
54+
f = open(filename, 'r')
55+
except:
56+
return False
57+
58+
data = f.read()
59+
f.close()
60+
61+
basename = os.path.basename(filename)
62+
extension = file_extension(filename)
63+
if extension != "":
64+
ref = refs[extension]
65+
else:
66+
ref = refs[basename]
67+
68+
# remove build tags from the top of Go files
69+
if extension == "go":
70+
p = regexs["go_build_constraints"]
71+
(data, found) = p.subn("", data, 1)
72+
73+
# remove shebang from the top of shell files
74+
if extension == "sh":
75+
p = regexs["shebang"]
76+
(data, found) = p.subn("", data, 1)
77+
78+
data = data.splitlines()
79+
80+
# if our test file is smaller than the reference it surely fails!
81+
if len(ref) > len(data):
82+
return False
83+
84+
# trim our file to the same number of lines as the reference file
85+
data = data[:len(ref)]
86+
87+
p = regexs["year"]
88+
for d in data:
89+
if p.search(d):
90+
return False
91+
92+
# Replace all occurrences of the regex "2017|2016|2015|2014" with "YEAR"
93+
p = regexs["date"]
94+
for i, d in enumerate(data):
95+
(data[i], found) = p.subn('YEAR', d)
96+
if found != 0:
97+
break
98+
99+
# if we don't match the reference at this point, fail
100+
if ref != data:
101+
return False
102+
103+
return True
104+
105+
def file_extension(filename):
106+
return os.path.splitext(filename)[1].split(".")[-1].lower()
107+
108+
skipped_dirs = ['Godeps', 'third_party', '.git', "vendor"]
109+
110+
def normalize_files(files):
111+
newfiles = []
112+
for pathname in files:
113+
if any(x in pathname for x in skipped_dirs):
114+
continue
115+
newfiles.append(pathname)
116+
for i, pathname in enumerate(newfiles):
117+
if not os.path.isabs(pathname):
118+
newfiles[i] = os.path.join(args.rootdir, pathname)
119+
return newfiles
120+
121+
def get_files(extensions):
122+
files = []
123+
if len(args.filenames) > 0:
124+
files = args.filenames
125+
else:
126+
for root, dirs, walkfiles in os.walk(args.rootdir):
127+
# don't visit certain dirs. This is just a performance improvement
128+
# as we would prune these later in normalize_files(). But doing it
129+
# cuts down the amount of filesystem walking we do and cuts down
130+
# the size of the file list
131+
for d in skipped_dirs:
132+
if d in dirs:
133+
dirs.remove(d)
134+
135+
for name in walkfiles:
136+
pathname = os.path.join(root, name)
137+
files.append(pathname)
138+
139+
files = normalize_files(files)
140+
outfiles = []
141+
for pathname in files:
142+
basename = os.path.basename(pathname)
143+
extension = file_extension(pathname)
144+
if extension in extensions or basename in extensions:
145+
outfiles.append(pathname)
146+
return outfiles
147+
148+
def get_regexs():
149+
regexs = {}
150+
# Search for "YEAR" which exists in the boilerplate, but shouldn't in the real thing
151+
regexs["year"] = re.compile( 'YEAR' )
152+
# dates can be 2014, 2015, 2016 or 2017, company holder names can be anything
153+
regexs["date"] = re.compile( '(2014|2015|2016|2017)' )
154+
# strip // +build \n\n build constraints
155+
regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE)
156+
# strip #!.* from shell scripts
157+
regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE)
158+
return regexs
159+
160+
def main():
161+
regexs = get_regexs()
162+
refs = get_refs()
163+
filenames = get_files(refs.keys())
164+
165+
for filename in filenames:
166+
if not file_passes(filename, refs, regexs):
167+
print(filename, file=sys.stdout)
168+
169+
if __name__ == "__main__":
170+
sys.exit(main())

boilerplate/boilerplate.py.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright YEAR The Kubernetes Authors All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+

boilerplate/boilerplate.sh.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright YEAR The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+

cmd/analyze.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2017 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/analyze_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2017 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/diff.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2017 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/diff_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2017 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/root.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2017 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

cmd/root_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2017 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package cmd
218

319
import (

0 commit comments

Comments
 (0)