From d27a7e75e4ba9ed0c682f9e9774b8acd304cabad Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 16 Jan 2017 16:00:20 +0100 Subject: renamed scripts/ to util/ --- util/header-gpl3.txt | 20 ++++++++++++++++++ util/licensecheck.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 util/header-gpl3.txt create mode 100755 util/licensecheck.py (limited to 'util') diff --git a/util/header-gpl3.txt b/util/header-gpl3.txt new file mode 100644 index 0000000..939e526 --- /dev/null +++ b/util/header-gpl3.txt @@ -0,0 +1,20 @@ +/** LICENSE ******************************************************************** + ** + ** smolbote: yet another qute browser + ** Copyright (C) $CURRENTYEAR$ $AUTHOR$ + ** + ** This program is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + ** + ******************************************************************************/ + diff --git a/util/licensecheck.py b/util/licensecheck.py new file mode 100755 index 0000000..be6de9a --- /dev/null +++ b/util/licensecheck.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +# TODO: username argument +# TODO: updating licenses + +import argparse +import datetime + +def getLicense(licenseFile): + with open(licenseFile) as rawlicense: + licensetext = rawlicense.read() + + # fill in name and year + licensetext = licensetext.replace('$AUTHOR$', 'Xian Nox') + licensetext = licensetext.replace('$CURRENTYEAR$', str(datetime.datetime.now().year)) + + return licensetext + +def hasLicense(sourceFile): + with open(sourceFile) as source: + if source.readline().startswith('/** LICENSE **'): + return True + else: + return False + +def fix(sourceFile, licenseText): + with open(sourceFile, 'r') as source: + origData = source.read() + with open(sourceFile, 'w') as source: + source.write(licenseText + origData) + +def main(license, src, verbose=False): + if verbose is True: + print("Using license header {0}".format(license)) + print("Going through {0}".format(src)) + + # read license file + licensetext = getLicense(license) + #print(licensetext) + + # open source file and check for license + for filename in src: + if hasLicense(filename): + print("{0} has license".format(filename)) + else: + fix(filename, licensetext) + print("{0} license added".format(filename)) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Check source files for license') + parser.add_argument('-l', '--license', required=True) + parser.add_argument('-v', '--verbose', action='store_true') + parser.add_argument('src', nargs='*') + args = parser.parse_args() + + main(args.license, args.src, args.verbose) +else: + print('Do not use this as an import!') + sys.exit(-1) -- cgit v1.2.1