nopaque/app/cli.py

41 lines
998 B
Python
Raw Normal View History

2021-11-16 14:23:57 +00:00
from . import db
from .models import Corpus, Role
from flask_migrate import upgrade
def register(app):
@app.cli.command()
def deploy():
"""Run deployment tasks."""
# migrate database to latest revision
upgrade()
# create or update user roles
Role.insert_roles()
@app.cli.group()
def daemon():
"""Daemon commands."""
pass
2021-09-22 12:13:59 +00:00
@daemon.command('run')
2021-09-22 11:58:46 +00:00
def run_daemon():
"""Run daemon"""
2021-11-16 14:23:57 +00:00
for corpus in Corpus.query.filter(Corpus.num_analysis_sessions > 0):
corpus.num_analysis_sessions = 0
db.session.commit()
from app.daemon import Daemon
daemon = Daemon()
daemon.run()
@app.cli.group()
def test():
"""Test commands."""
pass
2021-09-22 12:13:59 +00:00
@test.command('run')
2021-09-22 11:58:46 +00:00
def run_test():
"""Run unit tests."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)