-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmanage.py
32 lines (22 loc) · 833 Bytes
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import importlib
import os
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from src.models.basemodel import db
from main import create_app
app = create_app()
MODELS_DIRECTORY = "models"
EXCLUDE_FILES = ["__init__.py"]
def scan_models():
for dir_path, dir_names, file_names in os.walk(MODELS_DIRECTORY):
for file_name in file_names:
if file_name.endswith("py") and file_name not in EXCLUDE_FILES:
file_path_wo_ext, _ = os.path.splitext((os.path.join(dir_path, file_name)))
module_name = file_path_wo_ext.replace(os.sep, ".")
importlib.import_module(module_name)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
scan_models()
manager.run()