| 1 |
# Copyright (c) 2015 Microsoft Corporation |
| 2 |
|
| 3 |
import os |
| 4 |
import re |
| 5 |
|
| 6 |
cr = re.compile("Copyright") |
| 7 |
aut = re.compile("Automatically generated") |
| 8 |
|
| 9 |
cr_notice = """ |
| 10 |
/*++ |
| 11 |
Copyright (c) 2015 Microsoft Corporation |
| 12 |
|
| 13 |
--*/ |
| 14 |
|
| 15 |
""" |
| 16 |
|
| 17 |
def has_cr(file): |
| 18 |
ins = open(file) |
| 19 |
lines = 0 |
| 20 |
line = ins.readline() |
| 21 |
while line and lines < 20: |
| 22 |
m = cr.search(line) |
| 23 |
if m: |
| 24 |
ins.close() |
| 25 |
return True |
| 26 |
m = aut.search(line) |
| 27 |
if m: |
| 28 |
ins.close() |
| 29 |
return True |
| 30 |
line = ins.readline() |
| 31 |
ins.close() |
| 32 |
return False |
| 33 |
|
| 34 |
def add_cr(file): |
| 35 |
tmp = "%s.tmp" % file |
| 36 |
ins = open(file) |
| 37 |
ous = open(tmp,'w') |
| 38 |
ous.write(cr_notice) |
| 39 |
line = ins.readline() |
| 40 |
while line: |
| 41 |
ous.write(line) |
| 42 |
line = ins.readline() |
| 43 |
ins.close() |
| 44 |
ous.close() |
| 45 |
os.system("move %s %s" % (tmp, file)) |
| 46 |
|
| 47 |
def add_missing_cr(dir): |
| 48 |
for root, dirs, files in os.walk(dir): |
| 49 |
for f in files: |
| 50 |
if f.endswith('.cpp') or f.endswith('.h') or f.endswith('.c') or f.endswith('.cs'): |
| 51 |
path = "%s\\%s" % (root, f) |
| 52 |
if not has_cr(path): |
| 53 |
print("Missing CR for %s" % path) |
| 54 |
add_cr(path) |
| 55 |
|
| 56 |
add_missing_cr('src') |
| 57 |
add_missing_cr('examples') |