nopaque/app/corpora/cli.py

25 lines
735 B
Python
Raw Normal View History

2023-05-15 10:00:13 +00:00
from app.models import Corpus, CorpusStatus
import os
import shutil
2023-05-15 10:22:38 +00:00
from app import db
2023-05-15 10:00:13 +00:00
from . import bp
@bp.cli.command('reset')
def reset():
''' Reset built corpora. '''
status = [
CorpusStatus.QUEUED,
CorpusStatus.BUILDING,
CorpusStatus.BUILT,
CorpusStatus.STARTING_ANALYSIS_SESSION,
CorpusStatus.RUNNING_ANALYSIS_SESSION,
CorpusStatus.CANCELING_ANALYSIS_SESSION
]
for corpus in [x for x in Corpus.query.all() if x.status in status]:
2023-05-15 10:22:38 +00:00
print(f'Resetting corpus {corpus}')
2023-05-15 10:00:13 +00:00
shutil.rmtree(os.path.join(corpus.path, 'cwb'), ignore_errors=True)
2023-05-15 10:22:38 +00:00
corpus.status = CorpusStatus.UNPREPARED
2023-05-15 10:00:13 +00:00
corpus.num_analysis_sessions = 0
2023-05-15 10:22:38 +00:00
db.session.commit()