-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
44 lines (33 loc) · 1.2 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import json
from pathlib import Path
from flask.cli import FlaskGroup
from api import db
from api.models import CompletedTask, Field
from app import app
from jobs.populate_db import run_pipeline
from tests.test_pipeline import run_test_pipeline
cli = FlaskGroup(app)
BASE_DIR = app.config["BASE_DIR"]
@cli.command("insert_fields")
def insert_fields():
"""Insert data about annotations fields into the DB"""
with open(Path(f"{BASE_DIR}/tests/fixtures/fields.json")) as fields:
field_data = json.load(fields)
db.session.bulk_insert_mappings(Field, field_data)
db.session.commit()
@cli.command("update_db")
def update_db():
"""Fetches and inserts tool data from Toolhub"""
run_pipeline()
@cli.command("load_mock_data")
def load_mock_data():
"""Inserts the mock tool and task data into db"""
with open(Path(f"{BASE_DIR}/tests/fixtures/data.json")) as data:
test_data = json.load(data)
test_tool_data = test_data[0]["tool_data"]
run_test_pipeline(test_tool_data)
test_task_data = test_data[1]["task_data"]
db.session.bulk_insert_mappings(CompletedTask, test_task_data)
db.session.commit()
if __name__ == "__main__":
cli()