mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 17:25:44 +00:00
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
from flask import current_app
|
|
from flask_migrate import upgrade
|
|
import click
|
|
import os
|
|
from app.models import Role, User, TesseractOCRModel, TranskribusHTRModel
|
|
|
|
|
|
def _make_default_dirs():
|
|
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
|
|
|
default_directories = [
|
|
os.path.join(base_dir, 'tmp'),
|
|
os.path.join(base_dir, 'users')
|
|
]
|
|
for directory in default_directories:
|
|
if os.path.exists(directory):
|
|
if not os.path.isdir(directory):
|
|
raise NotADirectoryError(f'{directory} is not a directory')
|
|
else:
|
|
os.mkdir(directory)
|
|
|
|
|
|
def register(app):
|
|
@app.cli.command()
|
|
def deploy():
|
|
''' Run deployment tasks. '''
|
|
# Make default directories
|
|
_make_default_dirs()
|
|
|
|
# migrate database to latest revision
|
|
upgrade()
|
|
|
|
# Insert/Update default database values
|
|
current_app.logger.info('Insert/Update default roles')
|
|
Role.insert_defaults()
|
|
current_app.logger.info('Insert/Update default users')
|
|
User.insert_defaults()
|
|
current_app.logger.info('Insert/Update default TesseractOCRModels')
|
|
TesseractOCRModel.insert_defaults()
|
|
current_app.logger.info('Insert/Update default TranskribusHTRModels')
|
|
TranskribusHTRModel.insert_defaults()
|
|
|
|
@app.cli.group()
|
|
def converter():
|
|
''' Converter commands. '''
|
|
pass
|
|
|
|
@converter.command()
|
|
@click.argument('json_db')
|
|
@click.argument('data_dir')
|
|
def sandpaper(json_db, data_dir):
|
|
''' Sandpaper converter '''
|
|
from app.converters.sandpaper import convert
|
|
convert(json_db, data_dir)
|
|
|
|
@app.cli.group()
|
|
def test():
|
|
''' Test commands. '''
|
|
pass
|
|
|
|
@test.command('run')
|
|
def run_test():
|
|
''' Run unit tests. '''
|
|
from unittest import TestLoader, TextTestRunner
|
|
from unittest.suite import TestSuite
|
|
tests: TestSuite = TestLoader().discover('tests')
|
|
TextTestRunner(verbosity=2).run(tests)
|