2023-05-15 10:00:13 +00:00
|
|
|
from flask import current_app
|
|
|
|
from flask_migrate import upgrade
|
2024-03-07 14:49:04 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import List
|
2024-08-01 10:10:33 +00:00
|
|
|
from app import db
|
2023-05-15 10:00:13 +00:00
|
|
|
from app.models import (
|
2024-08-01 10:10:33 +00:00
|
|
|
Corpus,
|
2023-05-15 10:00:13 +00:00
|
|
|
CorpusFollowerRole,
|
|
|
|
Role,
|
|
|
|
SpaCyNLPPipelineModel,
|
|
|
|
TesseractOCRPipelineModel,
|
|
|
|
User
|
|
|
|
)
|
|
|
|
from . import bp
|
|
|
|
|
|
|
|
|
|
|
|
@bp.cli.command('deploy')
|
|
|
|
def deploy():
|
|
|
|
''' Run deployment tasks. '''
|
2024-08-01 10:10:33 +00:00
|
|
|
|
2023-05-15 10:00:13 +00:00
|
|
|
print('Make default directories')
|
|
|
|
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
2024-03-07 14:49:04 +00:00
|
|
|
default_dirs: List[Path] = [
|
2024-08-01 10:10:33 +00:00
|
|
|
Path('/var/log/nopaque'),
|
2024-03-07 14:49:04 +00:00
|
|
|
base_dir / 'tmp',
|
|
|
|
base_dir / 'users'
|
2023-05-15 10:00:13 +00:00
|
|
|
]
|
2024-03-07 14:49:04 +00:00
|
|
|
for default_dir in default_dirs:
|
|
|
|
if not default_dir.exists():
|
|
|
|
default_dir.mkdir()
|
|
|
|
if not default_dir.is_dir():
|
|
|
|
raise NotADirectoryError(f'{default_dir} is not a directory')
|
2023-05-15 10:00:13 +00:00
|
|
|
|
|
|
|
print('Migrate database to latest revision')
|
|
|
|
upgrade()
|
|
|
|
|
|
|
|
print('Insert/Update default Roles')
|
|
|
|
Role.insert_defaults()
|
|
|
|
print('Insert/Update default Users')
|
|
|
|
User.insert_defaults()
|
|
|
|
print('Insert/Update default CorpusFollowerRoles')
|
|
|
|
CorpusFollowerRole.insert_defaults()
|
|
|
|
print('Insert/Update default SpaCyNLPPipelineModels')
|
|
|
|
SpaCyNLPPipelineModel.insert_defaults()
|
|
|
|
print('Insert/Update default TesseractOCRPipelineModels')
|
|
|
|
TesseractOCRPipelineModel.insert_defaults()
|
2023-09-25 08:11:11 +00:00
|
|
|
|
2024-08-01 10:10:33 +00:00
|
|
|
print('Stop running analysis sessions')
|
|
|
|
for corpus in Corpus.query.filter(Corpus.num_analysis_sessions > 0).all():
|
|
|
|
corpus.num_analysis_sessions = 0
|
|
|
|
db.session.commit()
|
|
|
|
|
2023-09-25 08:11:11 +00:00
|
|
|
# TODO: Implement checks for if the nopaque network exists
|