From ea7cee968dfbfc276dde0a1c1b093f60c985f134 Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 21 Aug 2022 16:47:50 +0300 Subject: Add scripts/check_license.py --- scripts/check_license.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 scripts/check_license.py (limited to 'scripts') 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 +# ============================================================ +""" 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() -- cgit v1.2.1