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