mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
Updated copyright.py
This commit is contained in:
parent
32e52d51ce
commit
d7b623f532
|
@ -1,26 +1,64 @@
|
||||||
import sys, os
|
import os, re, sys
|
||||||
|
match = re.search("(.*?)/[^/]*?$", sys.argv[0])
|
||||||
|
if match != None:
|
||||||
|
os.chdir(os.getcwd() + "/" + match.group(1))
|
||||||
|
|
||||||
notice = "/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */\n"
|
notice = [b"/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */\n", b"/* If you are missing that file, acquire a complete release at teeworlds.com. */\n"]
|
||||||
|
exclude = ["../src%sengine%sexternal" % (os.sep, os.sep), "../src%sosxlaunch" % os.sep]
|
||||||
|
updated_files = 0
|
||||||
|
|
||||||
def fix_copyright_notice(filename):
|
def fix_copyright_notice(filename):
|
||||||
|
global updated_files
|
||||||
f = open(filename, "rb")
|
f = open(filename, "rb")
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if "/*" in lines[0] and "copyright" in lines[0]:
|
i = 0
|
||||||
lines[0] = notice
|
length_lines = len(lines)
|
||||||
else:
|
if length_lines > 0:
|
||||||
lines = [notice] + lines
|
while i <= length_lines and (lines[i].decode("utf-8").lstrip()[:2] == "//" or lines[i].decode("utf-8").lstrip()[:2] == "/*" and lines[i].decode("utf-8").rstrip()[-2:] == "*/") and ("Magnus" in lines[i].decode("utf-8") or "magnus" in lines[i].decode("utf-8") or "Auvinen" in lines[i].decode("utf-8") or "auvinen" in lines[i].decode("utf-8") or "license" in lines[i].decode("utf-8") or "teeworlds" in lines[i].decode("utf-8")):
|
||||||
file(filename, "wb").writelines(lines)
|
i += 1
|
||||||
|
length_notice = len(notice)
|
||||||
for root, dirs, files in os.walk("src"):
|
if i > 0:
|
||||||
for name in files:
|
j = 0
|
||||||
filename = os.path.join(root, name)
|
while lines[j] == notice[j]:
|
||||||
process = 0
|
j += 1
|
||||||
if ".h" == filename[-2:] or ".c" == filename[-2:] or ".cpp" == filename[-4:]:
|
if j == length_notice:
|
||||||
process = 1
|
return
|
||||||
if os.sep + "external" + os.sep in filename:
|
k = j
|
||||||
process = 0
|
j = 0
|
||||||
|
while j < length_notice -1 - k:
|
||||||
if process:
|
lines = [notice[j]] + lines
|
||||||
fix_copyright_notice(filename)
|
j += 1
|
||||||
|
while j < length_notice:
|
||||||
|
lines[j] = notice[j]
|
||||||
|
j += 1
|
||||||
|
if length_lines == 0 or i == 0:
|
||||||
|
j = length_notice - 1
|
||||||
|
while j >= 0:
|
||||||
|
lines = [notice[j]] + lines
|
||||||
|
j -= 1
|
||||||
|
open(filename, "wb").writelines(lines)
|
||||||
|
updated_files += 1
|
||||||
|
|
||||||
|
skip = False
|
||||||
|
for root, dirs, files in os.walk("../src"):
|
||||||
|
for excluding in exclude:
|
||||||
|
if root[:len(excluding)] == excluding:
|
||||||
|
skip = True
|
||||||
|
break
|
||||||
|
if skip == True:
|
||||||
|
skip = False
|
||||||
|
continue
|
||||||
|
for name in files:
|
||||||
|
filename = os.path.join(root, name)
|
||||||
|
|
||||||
|
if filename[-2:] != ".c" and filename[-4:] != ".cpp" and filename[-2:] != ".h":
|
||||||
|
continue
|
||||||
|
|
||||||
|
fix_copyright_notice(filename)
|
||||||
|
|
||||||
|
output = "file"
|
||||||
|
if updated_files != 1:
|
||||||
|
output += "s"
|
||||||
|
print("*** updated %d %s ***" % (updated_files, output))
|
||||||
|
|
Loading…
Reference in a new issue