import re
import os

def check_recipe(file_path):
    with open(file_path, "r", encoding="utf-8") as f:
        content = f.read()

    # Check if tarball is created from DESTDIR or uses --transform
    desttar = bool(re.search(r"tar.*DESTDIR|tar.*--transform", content, re.IGNORECASE))

    # Check if license is installed (common pattern)
    license_patterns = [
        r"/usr/share/licenses/.*",
        r"install.*COPYING",
        r"install.*LICENSE",
    ]
    license_found = any(re.search(pat, content, re.IGNORECASE) for pat in license_patterns)

    return {"desttar": desttar, "license": license_found}


# Example usage: scan a folder of recipes
recipes_dir = "/home/gabry/lfs-repo/recipes"
for recipe_file in os.listdir(recipes_dir):
    if recipe_file.endswith(".py"):
        path = os.path.join(recipes_dir, recipe_file)
        result = check_recipe(path)

        # Only print recipes missing either desttar or license
        if not (result['desttar'] and result['license']):
            print(f"{recipe_file}: desttar: {'yes' if result['desttar'] else 'no'}, "
                  f"license: {'yes' if result['license'] else 'no'}")

