mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-27 03:44:19 +00:00
28 lines
908 B
Python
28 lines
908 B
Python
from app.models import Corpus, CorpusStatus
|
|
import os
|
|
import shutil
|
|
from app import db
|
|
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]:
|
|
print(f'Resetting corpus {corpus}')
|
|
shutil.rmtree(os.path.join(corpus.path, 'cwb'), ignore_errors=True)
|
|
os.mkdir(os.path.join(corpus.path, 'cwb'))
|
|
os.mkdir(os.path.join(corpus.path, 'cwb', 'data'))
|
|
os.mkdir(os.path.join(corpus.path, 'cwb', 'registry'))
|
|
corpus.status = CorpusStatus.UNPREPARED
|
|
corpus.num_analysis_sessions = 0
|
|
db.session.commit()
|