|
|
|
@ -49,10 +49,15 @@ def generate_copyright(template, lang='C'):
|
|
|
|
|
LANG_COMMENT_MARK = "//"
|
|
|
|
|
|
|
|
|
|
lines = template.split(NEW_LINE_MARK)
|
|
|
|
|
ans = LANG_COMMENT_MARK + " " + COPYRIGHT_HEADER + NEW_LINE_MARK
|
|
|
|
|
BLANK = " "
|
|
|
|
|
ans = LANG_COMMENT_MARK + BLANK + COPYRIGHT_HEADER + NEW_LINE_MARK
|
|
|
|
|
for lino, line in enumerate(lines):
|
|
|
|
|
if lino == 0 or lino == 1 or lino == len(lines) - 1: continue
|
|
|
|
|
ans += LANG_COMMENT_MARK + " " + line + NEW_LINE_MARK
|
|
|
|
|
if len(line) == 0:
|
|
|
|
|
BLANK = ""
|
|
|
|
|
else:
|
|
|
|
|
BLANK = " "
|
|
|
|
|
ans += LANG_COMMENT_MARK + BLANK + line + NEW_LINE_MARK
|
|
|
|
|
|
|
|
|
|
return ans + "\n"
|
|
|
|
|
|
|
|
|
@ -62,6 +67,8 @@ def lang_type(filename):
|
|
|
|
|
return "Python"
|
|
|
|
|
elif filename.endswith(".h"):
|
|
|
|
|
return "C"
|
|
|
|
|
elif filename.endswith(".c"):
|
|
|
|
|
return "C"
|
|
|
|
|
elif filename.endswith(".hpp"):
|
|
|
|
|
return "C"
|
|
|
|
|
elif filename.endswith(".cc"):
|
|
|
|
@ -92,16 +99,14 @@ def main(argv=None):
|
|
|
|
|
|
|
|
|
|
retv = 0
|
|
|
|
|
for filename in args.filenames:
|
|
|
|
|
fd = io.open(filename)
|
|
|
|
|
fd = io.open(filename, encoding="utf-8")
|
|
|
|
|
first_line = fd.readline()
|
|
|
|
|
if "COPYRIGHT" in first_line.upper(): continue
|
|
|
|
|
if filename.endswith(".py"):
|
|
|
|
|
second_line = fd.readline()
|
|
|
|
|
if first_line.startswith("#!") or PYTHON_ENCODE.match(
|
|
|
|
|
second_line) != None or PYTHON_ENCODE.match(
|
|
|
|
|
first_line) != None:
|
|
|
|
|
continue
|
|
|
|
|
original_contents = io.open(filename).read()
|
|
|
|
|
second_line = fd.readline()
|
|
|
|
|
if "COPYRIGHT (C)" in first_line.upper(): continue
|
|
|
|
|
if first_line.startswith("#!") or PYTHON_ENCODE.match(
|
|
|
|
|
second_line) != None or PYTHON_ENCODE.match(first_line) != None:
|
|
|
|
|
continue
|
|
|
|
|
original_contents = io.open(filename, encoding="utf-8").read()
|
|
|
|
|
new_contents = generate_copyright(
|
|
|
|
|
COPYRIGHT, lang_type(filename)) + original_contents
|
|
|
|
|
print('Auto Insert Copyright Header {}'.format(filename))
|
|
|
|
|