from app.models import Corpus, CorpusStatus def init_app(app): @app.cli.group('corpus') def corpus(): ''' Corpus commands. ''' pass @corpus.command('dismantle') def dismantle(): ''' Dismantle 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]: corpus.status = CorpusStatus.SUBMITTED corpus.num_analysis_sessions = 0