diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/check_license.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/check_license.py b/scripts/check_license.py new file mode 100755 index 00000000..c1d2a296 --- /dev/null +++ b/scripts/check_license.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# ============================================================ +# The rekonq project +# ============================================================ +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net> +# ============================================================ +""" Check C/C++ files for license headers """ + + +import argparse +import sys +import re + + +def main(): + ''' main function ''' + parser = argparse.ArgumentParser(description='Check file for enabled license') + parser.add_argument('file', type=open, nargs='+', help='File to check') + parser.add_argument('--isc', type=bool, default=True, help='ISC [default=True]') + parser.add_argument('--gpl2', type=bool, default=True, help='GPLv2+ [default=True]') + parser.add_argument('--gpl3', type=bool, default=True, help='GPLv3 only [default=True]') + args = parser.parse_args() + + licenses = [] + if args.isc: + licenses.append('ISC') + if args.gpl2: + licenses.append('GPL-2.0-or-later') + if args.gpl3: + licenses.append('GPL-3.0-only') + + print('enabled licenses: ', licenses) + has_errors = False + + for file in args.file: + if not file.name.endswith(('.h', '.hh', '.hpp', '.c', '.cc', '.cpp')): + continue + + print(f'{ file.name }') + # check for header start + line = file.readline() + if re.search(r'^\/\* ={60}$', line) is None: + print(f'{ file.name }: missing header') + has_errors = True + continue + + line = file.readline() + + while line.startswith(' *'): + lic = re.search(r'^\s\* SPDX-License-Identifier: ([\w\d.-]{3,})$', line) + if lic is not None: + found = lic.group(1) + if found in licenses: + print(f'found license: { found }') + else: + print(f'found license { found } not in licenses { licenses }') + has_errors = True + + line = file.readline() + + sys.exit('Errors during check' if has_errors else 0) + + +if __name__ == '__main__': + main() |