mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
# First things first: apply monkey patch, so that no code gets executed without
|
|
# patched libraries!
|
|
import eventlet
|
|
|
|
|
|
eventlet.monkey_patch()
|
|
|
|
|
|
from dotenv import load_dotenv # noqa
|
|
import os # noqa
|
|
|
|
# Load environment variables
|
|
DOTENV_FILE = os.path.join(os.path.dirname(__file__), '.env')
|
|
if os.path.exists(DOTENV_FILE):
|
|
load_dotenv(DOTENV_FILE)
|
|
|
|
|
|
from app import create_app, db, socketio # noqa
|
|
from app.models import (Corpus, CorpusFile, Job, JobInput, JobResult,
|
|
QueryResult, Role, User) # noqa
|
|
from flask_migrate import Migrate, upgrade # noqa
|
|
|
|
|
|
app = create_app(os.environ.get('NOPAQUE_CONFIG', 'development'))
|
|
migrate = Migrate(app, db, compare_type=True)
|
|
|
|
|
|
@app.shell_context_processor
|
|
def make_shell_context():
|
|
return {'Corpus': Corpus,
|
|
'CorpusFile': CorpusFile,
|
|
'db': db,
|
|
'Job': Job,
|
|
'JobInput': JobInput,
|
|
'JobResult': JobResult,
|
|
'QueryResult': QueryResult,
|
|
'Role': Role,
|
|
'User': User}
|
|
|
|
|
|
@app.cli.command()
|
|
def deploy():
|
|
"""Run deployment tasks."""
|
|
# migrate database to latest revision
|
|
upgrade()
|
|
|
|
# create or update user roles
|
|
Role.insert_roles()
|
|
|
|
|
|
@app.cli.command()
|
|
def tasks():
|
|
from app.tasks import TaskRunner
|
|
task_runner = TaskRunner()
|
|
task_runner.run()
|
|
|
|
|
|
@app.cli.command()
|
|
def test():
|
|
"""Run the unit tests."""
|
|
import unittest
|
|
tests = unittest.TestLoader().discover('tests')
|
|
unittest.TextTestRunner(verbosity=2).run(tests)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
host = os.environ.get('NOPAQUE_HOST', '0.0.0.0')
|
|
port = int(os.environ.get('NOPAQUE_PORT', '5000'))
|
|
socketio.run(app, host=host, port=port)
|