blob: ad1dab6f402d6dc78cca41f8c158105b4a9f81f9 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001#!/usr/bin/env python3
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002import glob
3import os.path
4
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01005mit_copyright = open("scripts/copyright_mit.txt",'r').read()
Anthony Barbier6ff3b192017-09-04 18:44:23 +01006
7def add_cpp_copyright( f, content):
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01008 global mit_copyright
Anthony Barbier6ff3b192017-09-04 18:44:23 +01009 out = open(f,'w')
10 out.write("/*\n")
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010011 for line in mit_copyright.split('\n')[:-1]:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010012 out.write(" *");
13 if line.strip() != "":
14 out.write(" %s" %line)
15 out.write("\n")
16 out.write(" */\n")
17 out.write(content.strip())
18 out.write("\n")
19 out.close()
20
21def add_python_copyright( f, content):
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010022 global mit_copyright
Anthony Barbier6ff3b192017-09-04 18:44:23 +010023 out = open(f,'w')
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010024 for line in mit_copyright.split('\n')[:-1]:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025 out.write("#");
26 if line.strip() != "":
27 out.write(" %s" %line)
28 out.write("\n")
29 out.write(content.strip())
30 out.write("\n")
31 out.close()
32
33def remove_comment( content ):
34 comment=True
35 out=""
36 for line in content.split('\n'):
37 if comment:
38 if line.startswith(' */'):
39 comment=False
40 elif line.startswith('/*') or line.startswith(' *'):
41 #print(line)
42 continue
43 else:
44 raise Exception("ERROR: not a comment ? '%s'"% line)
45 else:
46 out += line + "\n"
47 return out
48def remove_comment_python( content ):
49 comment=True
50 out=""
51 for line in content.split('\n'):
52 if comment and line.startswith('#'):
53 continue
54 else:
55 comment = False
56 out += line + "\n"
57 return out
58
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010059for top in ['./arm_compute', './tests','./src','./examples','./utils/','./framework','./support']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 for root, _, files in os.walk(top):
61 for f in files:
62 path = os.path.join(root, f)
63
64 if f in ['.clang-tidy', '.clang-format']:
65 print("Skipping file: {}".format(path))
66 continue
67
68 with open(path, 'r', encoding='utf-8') as fd:
69 content = fd.read()
70 _, extension = os.path.splitext(f)
71
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010072 if extension in ['.cpp', '.h', '.hpp', '.inl', '.cl']:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 if not content.startswith('/*'):
74 add_cpp_copyright(path, content)
75 elif extension == '.py' or f in ['SConstruct', 'SConscript']:
76 if not content.startswith('# Copyright'):
77 add_python_copyright(path, content)
78 elif f == 'CMakeLists.txt':
79 if not content.startswith('# Copyright'):
80 add_python_copyright(path, content)
81 else:
82 raise Exception("Unhandled file: {}".format(path))