Load HLDS locations in app

This commit is contained in:
Midgard 2020-01-24 15:47:29 +01:00
parent e6b707e3d7
commit 303349e376
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 37 additions and 18 deletions

View file

@ -15,6 +15,7 @@ from flask_migrate import Migrate, MigrateCommand
from flask_oauthlib.client import OAuth, OAuthException
from flask_script import Manager, Server
import hlds
from admin import init_admin
from login import init_login
from models import db
@ -70,6 +71,9 @@ def register_plugins(app: Flask) -> Manager:
# Initialize SQLAlchemy
db.init_app(app)
# Load locations
locations = hlds.load_all()
# Initialize Flask-Migrate
migrate = Migrate(app, db)
app_manager = Manager(app)

View file

@ -1,7 +1,9 @@
#!/usr/bin/env python3
from os import path
from glob import glob
from os import path, walk
from tatsu import parse as tatsu_parse
import itertools
# TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674
@ -15,6 +17,7 @@ def kind_comparer(compare_to):
def parse(menu):
parsed = tatsu_parse(GRAMMAR, menu)
return parsed
return dict((
*((att["key"], att["value"]) for att in parsed["attributes"]),
("id", parsed["id"]),
@ -24,12 +27,24 @@ def parse(menu):
))
def parse_file(filename):
with open(filename, "r") as fh:
return parse(fh.read())
def load_all():
# TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674
data_dir = path.join(path.dirname(__file__), "..", "..", "data")
files = glob(path.join(data_dir, "**.hlds"))
menus = map(parse_file, files)
return list(itertools.chain.from_iterable(menus))
def main(filename):
import json
from tatsu.util import asjson
with open(filename) as fh:
ast = parse(fh.read())
ast = parse_file(filename)
print(json.dumps(asjson(ast), indent="\t"))