-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
67 lines (48 loc) · 1.5 KB
/
manage.py
File metadata and controls
67 lines (48 loc) · 1.5 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
import os
import unittest
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from app import blueprint
from app.main import create_app, db, config_env, socketio
from app.main.apis import miner_socket
from app.main.model import user, miner, gpu
from app.main.base_logger import logger
logger = logger.getLogger(__name__)
app = create_app()
app.register_blueprint(blueprint)
app.app_context().push()
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
# TODO: there is no way in hell that this is SOP
def get_app():
return app
@manager.command
def run():
socketio.run(app, port=5001)
@manager.command
def test():
"""Runs the unit tests."""
tests = unittest.TestLoader().discover('app/test', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
@manager.command
def drop_all():
from app.main.model import Base
from dotenv import load_dotenv
from sqlalchemy import create_engine
load_dotenv()
engine = create_engine(config_env.SQLALCHEMY_DATABASE_URI, echo=True)
Base.metadata.drop_all(engine)
@manager.command
def create_all():
from app.main.model import Base
from dotenv import load_dotenv
from sqlalchemy import create_engine
load_dotenv()
engine = create_engine(config_env.SQLALCHEMY_DATABASE_URI, echo=True)
Base.metadata.create_all(engine)
if __name__ == '__main__':
manager.run()