-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
39 lines (27 loc) · 1 KB
/
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
33
34
35
36
37
38
39
# -*- coding:utf-8 -*-
from main import app_factory
import flask_script, os
from flask_migrate import MigrateCommand
from werkzeug.utils import import_string
def load_commands(manager):
# Loading commands
crons = os.path.join(os.path.dirname(__file__), "crons")
for file in os.listdir(crons):
if not os.path.isfile(os.path.join(crons, file)):
continue
if file == '__init__.py':
continue
if file[-3:] != '.py':
continue
filename = file[:-3]
objectname = ''.join([x.capitalize() for x in filename.split('_')])
command = import_string('crons.{0}.{1}'.format(filename, objectname))
command_name = getattr(command, "name", None)
if command_name is None:
command_name = filename
manager.add_command(command_name, command())
if __name__ == "__main__":
manager = flask_script.Manager(app_factory)
manager.add_command('db', MigrateCommand)
load_commands(manager)
manager.run()