aboutsummaryrefslogtreecommitdiff
path: root/api/dynamic_import.py
blob: eb8f0c2bd86d701939900fec7f17597f27ee7d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from app import app
import importlib
import os
import log
import glob

files = glob.glob(os.path.dirname(__file__) + "/**/*.py", recursive=True)
files.remove(__file__)
files = [str(filename)
        .replace(os.path.dirname(__file__) + "/", '')
        .replace("/", ".")
        .replace(".py", '')
        for filename in files]

for file in files:
    mod = importlib.import_module(file)
    if not hasattr(mod, "dynamic_route"): continue
    app.register_blueprint(mod.dynamic_route[1], url_prefix=mod.dynamic_route[0])
    path = (mod.dynamic_route[0] + "/" + mod.dynamic_route[1].name).replace('//', '/')
    log.info(f"dynamically routing {path}")