forked from ton-society/the-open-league
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.py
33 lines (28 loc) · 1.45 KB
/
validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import glob
from PIL import Image
import importlib.util
import sys
from models.icons import get_icon_name
from models.season_config import SeasonConfig
if __name__ == '__main__':
for file in glob.glob("seasons/s*py"):
# some weird Python introspection hacks to ge all seasons and extract all projects
season_name = file.split("/")[1].split(".")[0]
import_stmt = f"seasons.{season_name}"
print(f"Importing {import_stmt}")
m = __import__(import_stmt, globals(), locals(), ['SeasonConfig'])
# print(m.__dict__)
for name, season_config in dict([(name, cls) for name, cls in m.__dict__.items() if isinstance(cls, SeasonConfig)]).items():
print(f"Checking {name} from {season_name}")
names = set()
for project in season_config.projects:
assert project.name not in names, f"Duplicate found: {project.name}"
names.add(project.name)
image = get_icon_name(season_config, project)
if image.endswith(".svg"):
continue
assert image.endswith(".png"), "Only png and svg formats are supported"
image_obj = Image.open("projects/icons/" + image)
assert image_obj.size == (100, 100), f"Image {image} for project {project.name} " \
f"has wrong dimensions: %dx%d" % image_obj.size