-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathadd_copyright.py
49 lines (42 loc) · 1.67 KB
/
add_copyright.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# updates the copyright information for all .cs files
# usage: call recursive_traversal, with the following parameters
# parent directory, old copyright text content, new copyright text content
import os
# Directories to exclude
excludedir = ["./dependencies", "./thirdparty", "./modules/core/3rdparty"]
# single filed to exclude
excludefile = []
def update_source(filename, oldcopyright, copyright):
utfstr = chr(0xef)+chr(0xbb)+chr(0xbf)
fdata = file(filename,"r+").read()
isUTF = False
if (fdata.startswith(utfstr)):
isUTF = True
fdata = fdata[3:]
if (oldcopyright != None):
if (fdata.startswith(oldcopyright)):
fdata = fdata[len(oldcopyright):]
if not (fdata.startswith(copyright)):
print "updating "+filename
fdata = copyright + fdata
if (isUTF):
file(filename,"w").write(utfstr+fdata)
else:
file(filename,"w").write(fdata)
def recursive_traversal(dir, oldcopyright, copyright):
global excludedir, excludefile
fns = os.listdir(dir)
print "listing "+dir
for fn in fns:
fullfn = os.path.join(dir,fn)
if (fullfn in excludedir or fullfn in excludefile):
continue
if (os.path.isdir(fullfn)):
recursive_traversal(fullfn, oldcopyright, copyright)
else:
if (fullfn.endswith(".cpp") or fullfn.endswith(".hpp")or fullfn.endswith(".java") or fullfn.endswith(".h") or fullfn.endswith(".mm") or fullfn.endswith(".m")):
update_source(fullfn, oldcopyright, copyright)
oldcright = file("COPYRIGHT","r+").read()
cright = file("COPYRIGHT","r+").read()
recursive_traversal(".", oldcright, cright)
exit()