-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanage.py
executable file
·51 lines (43 loc) · 1.35 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
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import os
from flask import current_app
from flask_script import Manager, Server
from flask_script.commands import ShowUrls, Clean
from flask_migrate import MigrateCommand
from backend.socket_listeners import socketio, app
from flask_socketio import join_room, leave_room, emit
from backend import create_app
from backend.models import db, User
# default to dev config because no one should use this in
# production anyway
# env = os.environ.get('BACKEND_ENV', 'dev')
# app = create_app('backend.settings.%sConfig' % env.capitalize())
manager = Manager(app)
manager.add_command("server", Server(threaded=True))
manager.add_command("show-urls", ShowUrls())
manager.add_command("clean", Clean())
manager.add_command("db", MigrateCommand)
@manager.shell
def make_shell_context():
""" Creates a python REPL with several default imports
in the context of the app
"""
return dict(app=app, db=db, User=User)
@manager.command
def createdb():
""" Creates a database with all of the tables defined in
your SQLAlchemy models
"""
db.drop_all()
db.create_all()
user = User('user', 'user', 'user', '[email protected]', 'tag', 'masters')
db.session.add(user)
db.session.commit()
@manager.command
def runsocket():
socketio.run(
app,
host="0.0.0.0"
)
if __name__ == "__main__":
manager.run()