Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 2 | import glob |
| 3 | import os.path |
| 4 | |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 5 | mit_copyright = open("scripts/copyright_mit.txt",'r').read() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 6 | |
| 7 | def add_cpp_copyright( f, content): |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 8 | global mit_copyright |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 9 | out = open(f,'w') |
| 10 | out.write("/*\n") |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 11 | for line in mit_copyright.split('\n')[:-1]: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 12 | 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 | |
| 21 | def add_python_copyright( f, content): |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 22 | global mit_copyright |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 23 | out = open(f,'w') |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 24 | for line in mit_copyright.split('\n')[:-1]: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 25 | 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 | |
| 33 | def 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 |
| 48 | def 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 Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 59 | for top in ['./arm_compute', './tests','./src','./examples','./utils/','./framework','./support']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 60 | 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 Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 72 | if extension in ['.cpp', '.h', '.hpp', '.inl', '.cl']: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | 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)) |