76 |
*/ |
*/ |
77 |
""" |
""" |
78 |
|
|
79 |
|
doCopyrightRe = re.compile(r"(?://|#)\s*\([cC]\)\s*:?\s*([^\n]+)") |
80 |
|
|
81 |
def process_dir(arg, dir, names): |
def process_dir(arg, dir, names): |
82 |
for name in names: |
for name in names: |
83 |
file = os.path.join(dir, name) |
file = os.path.join(dir, name) |
84 |
if os.path.isdir(file): continue |
if os.path.isdir(file): continue |
85 |
firstlines = open(file, 'r').readlines(500) |
firstlines = open(file, 'r').readlines(1000) |
86 |
if not len(firstlines): continue |
if len(firstlines) < 2: continue |
87 |
|
|
88 |
mat = re.match(r"(?://|#)\s*\([cC]\)\s*([^\n]+)", firstlines[0]) |
theLine = 0 |
89 |
|
mat = doCopyrightRe.match(firstlines[0]) |
90 |
|
if mat == None: |
91 |
|
mat = doCopyrightRe.match(firstlines[1]) |
92 |
|
theLine = 1 |
93 |
|
|
94 |
if mat != None: |
if mat != None: |
95 |
author = mat.group(1) |
author = mat.group(1) |
96 |
first = firstlines[0] |
first = firstlines[0] |
97 |
|
|
98 |
if first.startswith('#'): |
if first.startswith('#'): |
99 |
pymode = 1; chars = 5 |
pymode = 1 |
100 |
else: |
else: |
101 |
pymode = 0; |
pymode = 0; |
|
if first.startswith('// '): |
|
|
chars = 7 |
|
|
else: |
|
|
chars = 6 |
|
102 |
|
|
103 |
lines = [] |
lines = [] |
104 |
for l in open(file, 'r').readlines(): |
for l in open(file, 'r').readlines(): |
115 |
if not pymode: |
if not pymode: |
116 |
notice = '\n'.join(notice_lines) |
notice = '\n'.join(notice_lines) |
117 |
notice = java_template % (name, notice, author) |
notice = java_template % (name, notice, author) |
118 |
text = notice + '\n'.join(lines[1:]) + '\n' |
text = '\n'.join(lines[0:theLine]) + notice + '\n'.join(lines[(theLine+1):]) + '\n' |
119 |
else: |
else: |
120 |
lines = lines[1:] |
lines[theLine:(theLine+1)] = notice_lines + [''] |
|
lines[0:0] = notice_lines + [''] |
|
121 |
text = '\n'.join(lines) + '\n' |
text = '\n'.join(lines) + '\n' |
122 |
|
|
123 |
print "Inserting copyright statement into file %s" % (file,) |
print "Inserting copyright statement into file %s" % (file,) |