-
Notifications
You must be signed in to change notification settings - Fork 25
/
xmzoomeye-redis
55 lines (48 loc) · 1.55 KB
/
xmzoomeye-redis
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
#
# Authors: limanman
# OsChina: http://xmdevops.blog.51cto.com/
# Purpose:
#
"""
# 说明: 导入公共模块
import os
import sys
from app import db as _db
from app import create_app
from flask_script import Manager, Server, Option, Command
from flask_migrate import Migrate, MigrateCommand
# 说明: 导入其它模块
app = create_app()
manager = Manager(app)
migrate = Migrate(app, _db)
# 说明: 添加额外功能
class RunServer(Server):
def __init__(self, pid_file=app.config.get('PID_FILE'), *args, **kwargs):
super(RunServer, self).__init__(*args, **kwargs)
self.pid_file = pid_file
def __call__(self, app, host, port, use_debugger, use_reloader, threaded, processes, passthrough_errors):
if use_debugger is None:
use_debugger = app.debug
if use_debugger is None:
use_debugger = True
if use_reloader is None:
use_reloader = app.debug
if self.pid_file:
with open(self.pid_file, 'w+b') as f:
f.write(str(os.getpid()))
app.run(host=host,
port=port,
debug=use_debugger,
use_debugger=use_debugger,
use_reloader=use_reloader,
threaded=threaded,
processes=processes,
passthrough_errors=passthrough_errors,
**self.server_options)
manager.add_command('db', MigrateCommand)
manager.add_command('runserver', RunServer())
if __name__ == '__main__':
manager.run()