system-pri/backend/app/utils.py

30 lines
823 B
Python
Raw Normal View History

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 21:18:40 +01:00
importlib.import_module(f"backend.app.{dirname}.{models_module}")
2022-05-15 21:20:05 +02:00
except ModuleNotFoundError:
2023-01-04 22:51:58 +01:00
print(models_module, dirname)
2022-05-15 21:20:05 +02:00
warnings.warn(f"Not found module {models_module}.py in package {dirname}")