#!/usr/bin/env python3

from pathlib import Path

target_dir = Path('.')

ignore_dir = target_dir / "tests" / "sanity"
module_dir = target_dir / "plugins" / "modules"
module_utils_dir = target_dir / "plugins" / "module_utils"
ignore_dir.mkdir(parents=True, exist_ok=True)

skip_list = [
    "compile-2.6!skip",  # Py3.8+
    "compile-2.7!skip",  # Py3.8+
    "compile-3.5!skip",  # Py3.8+
    "import-2.6!skip",  # Py3.8+
    "import-2.7!skip",  # Py3.8+
    "import-3.5!skip",  # Py3.8+
    "future-import-boilerplate!skip",  # Py2 only
    "metaclass-boilerplate!skip",  # Py2 only
]

for version in ["2.9", "2.10", "2.11", "2.12"]:
    ignore_file = ignore_dir / f"ignore-{version}.txt"
    ignore_content = ignore_file.read_text().split("\n")
    ignore_content.append(f"tests/sanity/refresh_ignore_files shebang!skip")

    for f in module_dir.glob("*.py"):
        if f.is_symlink():
            continue
        for test in skip_list:
            ignore_content.append(f"{f} {test}")
    for f in module_utils_dir.glob("*.py"):
        if f.is_symlink():
            continue
        for test in skip_list:
            ignore_content.append(f"{f} {test}")
    ignore_file = ignore_dir / f"ignore-{version}.txt"
    ignore_file.write_text("\n".join(sorted(set(ignore_content))).lstrip("\n"))
