1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/CI/validate_json.py

29 lines
661 B
Python
Raw Normal View History

#!/usr/bin/env python3
2023-09-16 01:52:04 +02:00
import re
import sys
2023-09-15 22:55:48 +02:00
from pathlib import Path
from pprint import pprint
2023-09-16 01:52:04 +02:00
# VCMI supports JSON with comments, but not JSON5
import jstyleson
validation_failed = False
2023-09-15 22:55:48 +02:00
for path in sorted(Path(".").glob("**/*.json"), key=lambda path: str(path).lower()):
2023-09-15 22:55:48 +02:00
# because path is an object and not a string
path_str = str(path)
if path_str.startswith("."):
continue
2023-09-15 22:55:48 +02:00
try:
with open(path_str, "r") as file:
jstyleson.load(file)
print(f"{path_str}")
2023-09-15 22:55:48 +02:00
except Exception as exc:
print(f"{path_str}: {exc}")
validation_failed = True
2023-09-15 22:55:48 +02:00
if validation_failed:
sys.exit(1)