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