nopaque/nopaque.py

63 lines
1.5 KiB
Python
Raw Normal View History

# First things first: apply monkey patch, so that no code gets executed without
# patched libraries!
2019-08-26 12:21:06 +00:00
import eventlet
eventlet.monkey_patch()
from app import cli, create_app, db, scheduler, socketio # noqa
from app.models import (
Corpus,
CorpusFile,
Job,
JobInput,
JobResult,
Permission,
Role,
2022-10-12 08:23:05 +00:00
TesseractOCRPipelineModel,
SpaCyNLPPipelineModel,
User
) # noqa
2021-12-07 13:18:05 +00:00
from flask import Flask # noqa
from typing import Any, Dict # noqa
2019-07-03 08:31:23 +00:00
2021-12-07 13:18:05 +00:00
app: Flask = create_app()
cli.register(app)
2021-12-07 13:18:05 +00:00
@app.context_processor
def make_context() -> Dict[str, Any]:
''' Adds variables to the template context. '''
return {'Permission': Permission}
@app.shell_context_processor
2021-12-07 13:18:05 +00:00
def make_shell_context() -> Dict[str, Any]:
''' Adds variables to the shell context. '''
return {
'Corpus': Corpus,
'CorpusFile': CorpusFile,
'db': db,
'Job': Job,
'JobInput': JobInput,
'JobResult': JobResult,
'Permission': Permission,
'Role': Role,
2022-10-12 08:23:05 +00:00
'TesseractOCRPipelineModel': TesseractOCRPipelineModel,
'SpaCyNLPPipelineModel': SpaCyNLPPipelineModel,
2021-12-07 13:18:05 +00:00
'User': User
}
def main():
with app.app_context():
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
for corpus in Corpus.query.filter(Corpus.num_analysis_sessions > 0).all():
corpus.num_analysis_sessions = 0
db.session.commit()
scheduler.start()
socketio.run(app, host='0.0.0.0')
if __name__ == '__main__':
main()