<commit_before>#!/usr/bin/python3
#
# Copyright (C) 2021 <NAME> <<EMAIL>>
# Copyright (C) 2021 <NAME> <<EMAIL>>
#
# SPDX-License-Identifier: LGPL-2.1+

import glob
import os
import sys


def __get_license(fn: str) -> str:
    with open(fn, "r") as f:
        for line in f.read().split("\n"):
            if line.find("SPDX-License-Identifier:") > 0:
                return line.split(":")[1]
    return ""


def test_files() -> int:

    rc: int = 0
    build_dir = ""

    for fn in glob.glob("**/*.[c|h|py|sh]", recursive=True):
        if "meson-private" in fn:
            continue
        if os.path.isdir(fn):
            continue
        if "config.h" in fn:
            build_dir = os.path.dirname(fn)
            continue
        if build_dir and fn.startswith(build_dir):
            continue
        if fn.startswith("subprojects"):
            continue
        lic = __get_license(fn)
        if not lic:
            print("{} does not specify a license".format(fn))
            rc = 1
            continue
        if not "GPL" in lic:
            print("{} does not contain LGPL or GPL ({})".format(fn, lic))
            rc = 1
            continue
    return rc


if __name__ == "__main__":

    # all done!
    sys.exit(test_files())<commit_msg>trivial: check-license: exclude files from build directory earlier<commit_after>#!/usr/bin/python3
#
# Copyright (C) 2021 <NAME> <<EMAIL>>
# Copyright (C) 2021 <NAME> <<EMAIL>>
#
# SPDX-License-Identifier: LGPL-2.1+

import glob
import os
import sys


def __get_license(fn: str) -> str:
    with open(fn, "r") as f:
        for line in f.read().split("\n"):
            if line.find("SPDX-License-Identifier:") > 0:
                return line.split(":")[1]
    return ""


def test_files() -> int:

    rc: int = 0
    build_dirs = [os.path.dirname(cf) for cf in glob.glob("**/config.h")]

    for fn in glob.glob("**/*.[c|h|py|sh]", recursive=True):
        if "meson-private" in fn:
            continue
        if os.path.isdir(fn):
            continue
        if fn.startswith(tuple(build_dirs)):
            continue
        if fn.startswith("subprojects"):
            continue
        lic = __get_license(fn)
        if not lic:
            print("{} does not specify a license".format(fn))
            rc = 1
            continue
        if not "GPL" in lic:
            print("{} does not contain LGPL or GPL ({})".format(fn, lic))
            rc = 1
            continue
    return rc


if __name__ == "__main__":

    # all done!
    sys.exit(test_files())
{'fraction_non_alphanumeric': 0.14347826086956522, 'fraction_numerical': 0.012648221343873518, 'mean_word_length': 1.93279258400927, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7528220', 'n_tokens_mistral': 851, 'n_tokens_neox': 808, 'n_words': 226}