2022-05-15 21:20:05 +02:00
|
|
|
import os
|
|
|
|
import importlib
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
from flask import current_app
|
|
|
|
|
|
|
|
|
|
|
|
def get_app_directories() -> list:
|
|
|
|
directories = []
|
|
|
|
src_dir = current_app.config['SRC_DIR']
|
|
|
|
excluded_dirs = current_app.config['EXCLUDED_DIRS']
|
|
|
|
|
|
|
|
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}")
|