system-pri/backend/app/utils.py

29 lines
773 B
Python

import importlib
import os
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:
importlib.import_module(f"app.{dirname}.{models_module}")
except ModuleNotFoundError:
warnings.warn(f"Not found module {models_module}.py in package {dirname}")