2022-05-15 21:20:05 +02:00
|
|
|
import importlib
|
2023-01-14 17:38:03 +01:00
|
|
|
import os
|
2022-05-15 21:20:05 +02:00
|
|
|
import warnings
|
|
|
|
|
|
|
|
from flask import current_app
|
|
|
|
|
|
|
|
|
|
|
|
def get_app_directories() -> list:
|
|
|
|
directories = []
|
2023-01-14 17:38:03 +01:00
|
|
|
src_dir = current_app.config["SRC_DIR"]
|
|
|
|
excluded_dirs = current_app.config["EXCLUDED_DIRS"]
|
2022-05-15 21:20:05 +02:00
|
|
|
|
|
|
|
for dirname in os.listdir(src_dir):
|
|
|
|
path = src_dir / dirname
|
|
|
|
if os.path.isdir(path) and dirname not in excluded_dirs:
|
|
|
|
directories.append(dirname)
|
|
|
|
return directories
|
|
|
|
|
|
|
|
|
|
|
|
def import_models() -> None:
|
|
|
|
directories = get_app_directories()
|
|
|
|
|
|
|
|
models_module = "models"
|
|
|
|
for dirname in directories:
|
|
|
|
try:
|
2023-01-09 22:32:58 +01:00
|
|
|
importlib.import_module(f"app.{dirname}.{models_module}")
|
2022-05-15 21:20:05 +02:00
|
|
|
except ModuleNotFoundError:
|
|
|
|
warnings.warn(f"Not found module {models_module}.py in package {dirname}")
|