Commit c45c69c2 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added an index all calcs command to cli.

parent 26398c72
Pipeline #52967 failed with stages
in 28 minutes and 36 seconds
# Copyright 2018 Markus Scheidgen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an"AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import click
from sys import stdout
from nomad import processing as proc, search, datamodel, infrastructure
from nomad.cli.cli import cli
......@@ -8,3 +25,28 @@ from nomad.cli.cli import cli
@click.pass_context
def admin(ctx):
pass
@admin.command(help='(Re-)index all calcs.')
def index():
infrastructure.setup_logging()
infrastructure.setup_mongo()
infrastructure.setup_elastic()
infrastructure.setup_repository_db()
all_calcs = proc.Calc.objects().count()
print('indexing %d ...' % all_calcs)
def calc_generator():
count = 0
for calc in proc.Calc.objects():
count += 1
if count % 1000 == 0:
stdout.write('\r indexed %10d of %10d calcs' % (count, all_calcs))
stdout.flush()
yield datamodel.CalcWithMetadata(**calc.metadata)
failed = search.index_all(calc_generator())
print('')
print('indexing completed, %d failed entries' % failed)
......@@ -42,6 +42,21 @@ class TestAdmin:
assert Calc.objects(upload_id=upload_id).first() is None
assert search.entry_search(search_parameters=dict(upload_id=upload_id))['pagination']['total'] > 0
def test_index(self, published):
upload_id = published.upload_id
calc = Calc.objects(upload_id=upload_id).first()
calc.metadata['comment'] = 'specific'
calc.save()
assert search.entry_search(search_parameters=dict(comment='specific'))['pagination']['total'] == 0
result = click.testing.CliRunner().invoke(
cli, ['admin', 'index'], catch_exceptions=False, obj=utils.POPO())
assert result.exit_code == 0
assert 'index' in result.stdout
assert search.entry_search(search_parameters=dict(comment='specific'))['pagination']['total'] == 1
@pytest.mark.usefixtures('reset_config', 'no_warn')
class TestAdminUploads:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment