ddnet/scripts/copyright.py
GreYFoX 35d16bd58c Merge branch 'master' of git://github.com/oy/teeworlds into DDRace0611
Conflicts:
	src/engine/console.h
	src/engine/server.h
	src/engine/server/server.cpp
	src/engine/shared/config_variables.h
	src/engine/shared/console.cpp
	src/engine/shared/console.h
	src/engine/shared/network_server.cpp
	src/game/client/components/console.cpp
	src/game/client/components/console.h
	src/game/client/components/menus_browser.cpp
	src/game/client/gameclient.cpp
	src/game/editor/editor.cpp
	src/game/editor/editor.h
	src/game/editor/io.cpp
	src/game/editor/layer_tiles.cpp
	src/game/editor/popups.cpp
	src/game/gamecore.cpp
	src/game/mapitems.h
	src/game/server/entities/character.cpp
	src/game/server/entities/laser.cpp
	src/game/server/gamecontext.cpp
	src/game/server/gamecontroller.cpp
	src/game/server/gamecontroller.h
	src/game/server/gamemodes/ctf.cpp
	src/game/server/player.cpp
	src/game/variables.h
2011-08-13 02:01:40 +02:00

66 lines
1.9 KiB
Python

import os, re, sys
match = re.search('(.*)/', sys.argv[0])
if match != None:
os.chdir(match.group(1))
os.chdir('../')
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):
global updated_files
f = open(filename, "rb")
lines = f.readlines()
f.close()
i = 0
length_lines = len(lines)
if length_lines > 0:
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")):
i += 1
length_notice = len(notice)
if i > 0:
j = 0
while lines[j] == notice[j]:
j += 1
if j == length_notice:
return
k = j
j = 0
while j < length_notice -1 - k:
lines = [notice[j]] + lines
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))