@fixtures.command()<EOL>@cli.with_appcontext<EOL>def records():
import pkg_resources<EOL>from dojson.contrib.marc21 import marc21<EOL>from dojson.contrib.marc21.utils import create_record, split_blob<EOL>from flask_login import login_user, logout_user<EOL>from invenio_accounts.models import User<EOL>from invenio_deposit.api import Deposit<EOL>users = User.query.all()<EOL>data_path = pkg_resources.resource_filename(<EOL>'<STR_LIT>', '<STR_LIT>'<EOL>)<EOL>with open(data_path) as source:<EOL><INDENT>with current_app.test_request_context():<EOL><INDENT>indexer = RecordIndexer()<EOL>with db.session.begin_nested():<EOL><INDENT>for index, data in enumerate(split_blob(source.read()),<EOL>start=<NUM_LIT:1>):<EOL><INDENT>login_user(users[index % len(users)])<EOL>record = marc21.do(create_record(data))<EOL>indexer.index(Deposit.create(record))<EOL>logout_user()<EOL><DEDENT><DEDENT>db.session.commit()<EOL><DEDENT><DEDENT>
Load records.