File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -77,10 +77,13 @@ def lang_type(filename):
77
77
elif filename.endswith(".proto"):
78
78
return "C"
79
79
else:
80
- print("Unsupported filetype" )
80
+ print("Unsupported filetype %s", filename )
81
81
exit(0)
82
82
83
83
84
+ PYTHON_ENCODE = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)")
85
+
86
+
84
87
def main(argv=None):
85
88
parser = argparse.ArgumentParser(
86
89
description='Checker for copyright declaration.')
@@ -89,8 +92,15 @@ def main(argv=None):
89
92
90
93
retv = 0
91
94
for filename in args.filenames:
92
- first_line = io.open(filename).readline()
93
- if "COPYRIGHT" in first_line.upper() : continue
95
+ fd = io.open(filename)
96
+ first_line = fd.readline()
97
+ if "COPYRIGHT" in first_line.upper(): continue
98
+ if filename.endswith(".py"):
99
+ second_line = fd.readline()
100
+ if first_line.startswith("#!") or PYTHON_ENCODE.match(
101
+ second_line) != None or PYTHON_ENCODE.match(
102
+ first_line) != None:
103
+ continue
94
104
original_contents = io.open(filename).read()
95
105
new_contents = generate_copyright(
96
106
COPYRIGHT, lang_type(filename)) + original_contents
You can’t perform that action at this time.
0 commit comments