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

Added es query to uploads cli commands.

parent 6f0d6cca
Pipeline #69459 passed with stages
in 15 minutes and 24 seconds
......@@ -16,8 +16,10 @@ from typing import List
import click
from tabulate import tabulate
from mongoengine import Q
from elasticsearch_dsl import Q as ESQ
from pymongo import UpdateOne
import elasticsearch_dsl as es
import json
from nomad import processing as proc, config, infrastructure, utils, search, files, datamodel
from .admin import admin, __run_processing
......@@ -67,6 +69,15 @@ def uploads(ctx, user: str, staging: bool, processing: bool, outdated: bool, cod
def query_uploads(ctx, uploads):
json_query = json.loads(' '.join(uploads))
request = search.SearchRequest()
request.q = ESQ(json_query)
request.quantity('upload_id', size=10000)
uploads = list(request.execute()['quantities']['upload_id']['values'])
except Exception:
query = ctx.obj.query
if len(uploads) > 0:
query &= Q(upload_id__in=uploads)
......@@ -149,6 +149,15 @@ class TestAdminUploads:
assert result.exit_code == 0
assert '1 uploads selected' in result.stdout
def test_ls_query(self, published):
upload_id = published.upload_id
result = click.testing.CliRunner().invoke(
cli, ['admin', 'uploads', 'ls', '{"match":{"upload_id":"%s"}}' % upload_id], catch_exceptions=False, obj=utils.POPO())
assert result.exit_code == 0
assert '1 uploads selected' in result.stdout
def test_rm(self, published):
upload_id = published.upload_id
Supports Markdown
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