1#!/usr/bin/env python3 2import glob 3import os.path 4import sys 5 6mit_copyright = open("scripts/copyright_mit.txt",'r').read() 7 8def add_cpp_copyright( f, content): 9 global mit_copyright 10 out = open(f,'w') 11 out.write("/*\n") 12 for line in mit_copyright.split('\n')[:-1]: 13 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): 23 global mit_copyright 24 out = open(f,'w') 25 for line in mit_copyright.split('\n')[:-1]: 26 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 60def check_file( path ): 61 root, f = os.path.split(path) 62 if f in ['.clang-tidy', '.clang-format']: 63 print("Skipping file: {}".format(path)) 64 return 65 66 with open(path, 'r', encoding='utf-8') as fd: 67 content = fd.read() 68 _, extension = os.path.splitext(f) 69 70 if extension in ['.cpp', '.h', '.hpp', '.inl', '.cl', '.in', '.cs']: 71 if not content.startswith('/*'): 72 add_cpp_copyright(path, content) 73 elif extension == '.py' or f in ['SConstruct', 'SConscript']: 74 if not content.startswith('# Copyright'): 75 add_python_copyright(path, content) 76 elif f == 'CMakeLists.txt': 77 if not content.startswith('# Copyright'): 78 add_python_copyright(path, content) 79 else: 80 raise Exception("Unhandled file: {}".format(path)) 81 82if len(sys.argv) > 1: 83 for path in sys.argv[1:]: 84 check_file(path) 85else: 86 for top in ['./arm_compute', './tests','./src','./examples','./utils/','./opencl-1.2-stubs/','./opengles-3.1-stubs/','./support']: 87 for root, _, files in os.walk(top): 88 for f in files: 89 path = os.path.join(root, f) 90 check_file(path) 91