67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Fail if tracked Agrarian assets include paid or unclear costs."""
|
|
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
REGISTER = ROOT / "Docs" / "Art" / "AssetLicenses.md"
|
|
|
|
ALLOWED_COSTS = {"free", "$0", "0", "n/a", "na"}
|
|
BLOCKED_WORDS = {
|
|
"paid",
|
|
"purchased",
|
|
"purchase",
|
|
"subscription",
|
|
"unknown",
|
|
"unclear",
|
|
"tbd",
|
|
"marketplace bundle",
|
|
}
|
|
|
|
|
|
def parse_markdown_table_rows(text: str) -> list[list[str]]:
|
|
rows: list[list[str]] = []
|
|
for line in text.splitlines():
|
|
stripped = line.strip()
|
|
if not stripped.startswith("|") or "---" in stripped:
|
|
continue
|
|
cells = [cell.strip() for cell in stripped.strip("|").split("|")]
|
|
if cells and cells[0] != "Asset":
|
|
rows.append(cells)
|
|
return rows
|
|
|
|
|
|
def main() -> None:
|
|
if not REGISTER.exists():
|
|
raise SystemExit(f"Missing asset license register: {REGISTER}")
|
|
|
|
rows = parse_markdown_table_rows(REGISTER.read_text(encoding="utf-8"))
|
|
failures: list[str] = []
|
|
|
|
for row in rows:
|
|
if len(row) < 5:
|
|
failures.append(f"Malformed asset license row: {' | '.join(row)}")
|
|
continue
|
|
|
|
asset = row[0]
|
|
cost = row[4].strip().lower()
|
|
full_row = " ".join(row).lower()
|
|
|
|
if not cost:
|
|
failures.append(f"{asset}: cost is blank")
|
|
elif cost not in ALLOWED_COSTS:
|
|
failures.append(f"{asset}: cost {row[4]!r} is not free-only")
|
|
|
|
for blocked in BLOCKED_WORDS:
|
|
if blocked in full_row:
|
|
failures.append(f"{asset}: blocked free-only word found: {blocked!r}")
|
|
|
|
if failures:
|
|
raise SystemExit("\n".join(failures))
|
|
|
|
print(f"Asset license free-only verification complete: {len(rows)} entries.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|