Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Anthony Barbier | 2fe7d1c | 2017-09-15 13:07:36 +0100 | [diff] [blame] | 2 | #FIXME: Remove this file before the release |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | |
| 4 | import glob |
| 5 | import os.path |
| 6 | |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 7 | mit_copyright = open("scripts/copyright_mit.txt",'r').read() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 8 | |
| 9 | def add_cpp_copyright( f, content): |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 10 | global mit_copyright |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 11 | out = open(f,'w') |
| 12 | out.write("/*\n") |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 13 | for line in mit_copyright.split('\n')[:-1]: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 14 | 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 | |
| 23 | def add_python_copyright( f, content): |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 24 | global mit_copyright |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | out = open(f,'w') |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 26 | for line in mit_copyright.split('\n')[:-1]: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | 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 | |
| 35 | def 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 |
| 50 | def 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 Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 61 | for top in ['./arm_compute', './tests','./src','./examples','./utils/','./framework','./support']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | 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 Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 74 | if extension in ['.cpp', '.h', '.hpp', '.inl', '.cl']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | 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)) |