master.py: split generation of trophies and generation of icons

May be used in development environment when database is populated and 
deleting/recreating trophies throws an error because it will broke 
non-null relationships.
This commit is contained in:
Darks 2020-10-31 10:15:07 +01:00
parent 93e5fc380a
commit ee01a4c768
Signed by: Darks
GPG Key ID: 7515644268BE1433
1 changed files with 10 additions and 1 deletions

View File

@ -186,8 +186,15 @@ def create_trophies():
db.session.commit()
print(f"Created {len(tr)} trophies.")
# Create their icons
create_trophies_icons()
def create_trophies_icons():
tr = []
with open(os.path.join(app.root_path, "data", "trophies.yaml")) as fp:
tr = yaml.safe_load(fp.read())
# Create their icons in /app/static/images/trophies
names = [slugify.slugify(t["name"]) for t in tr]
src = os.path.join(app.root_path, "data", "trophies.png")
dst = os.path.join(app.root_path, "static", "images", "trophies")
@ -210,6 +217,7 @@ def create_trophies():
for (name, icon) in zip(names, trophy_iterator(img)):
icon.save(os.path.join(dst, f"{name}.png"))
def create_forums():
# Clean up forums
forums("clear")
@ -285,6 +293,7 @@ commands = {
"forums": forums,
"create-groups-and-privs": create_groups_and_privs,
"create-trophies": create_trophies,
"create-trophies-icons": create_trophies_icons,
"create-forums": create_forums,
"add-group": add_group,
"enable-user": enable_user,