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

Added * argument for upload ids to admin upload cli. [skip ci]

parent 28708bc2
Pipeline #51971 skipped
......@@ -16,5 +16,11 @@
Swagger/bravado based python client library for the API and various usefull shell commands.
"""
from nomad.utils import POPO
from . import upload, run
from .__main__ import cli
from .__main__ import cli as cli_main
def cli():
cli_main(obj=POPO())
......@@ -20,7 +20,7 @@ import shutil
from tabulate import tabulate
from elasticsearch_dsl import A
from nomad import config as nomad_config, infrastructure, processing
from nomad import config as nomad_config, infrastructure, processing, utils
from nomad.search import Search
......@@ -29,7 +29,8 @@ from nomad.search import Search
@click.option('-v', '--verbose', help='sets log level to info', is_flag=True)
@click.option('--debug', help='sets log level to debug', is_flag=True)
@click.option('--config', help='the config file to use')
def cli(verbose: bool, debug: bool, config: str):
@click.pass_context
def cli(ctx, verbose: bool, debug: bool, config: str):
if config is not None:
nomad_config.load_config(config_file=config)
......@@ -144,4 +145,4 @@ def clean(dry, skip_calcs, skip_fs, skip_es):
if __name__ == '__main__':
cli() # pylint: disable=E1120
cli(obj={}) # pylint: disable=E1120
......@@ -20,23 +20,16 @@ from nomad import processing as proc, infrastructure, utils, search, files
from .__main__ import cli
uploads = None
query = None
@cli.group(help='Upload related commands')
@click.option('--upload', help='Select upload of with given id', type=str)
@click.option('--user', help='Select uploads of user with given id', type=str)
@click.option('--staging', help='Select only uploads in staging', is_flag=True)
@click.option('--processing', help='Select only processing uploads', is_flag=True)
def upload(upload: str, user: str, staging: bool, processing: bool):
@click.pass_context
def upload(ctx, user: str, staging: bool, processing: bool):
infrastructure.setup_mongo()
infrastructure.setup_elastic()
global query
query = Q()
if upload is not None:
query &= Q(upload_id=upload)
if user is not None:
query &= Q(user_id=user)
if staging:
......@@ -44,12 +37,24 @@ def upload(upload: str, user: str, staging: bool, processing: bool):
if processing:
query &= Q(process_status=proc.PROCESS_RUNNING) | Q(tasks_status=proc.RUNNING)
global uploads
uploads = proc.Upload.objects(query)
ctx.obj.query = query
ctx.obj.uploads = proc.Upload.objects(query)
def query_uploads(ctx, uploads):
query = ctx.obj.query
if len(uploads) > 0:
query &= Q(upload_id__in=uploads)
return query, proc.Upload.objects(query)
@upload.command(help='List selected uploads')
def ls():
@click.argument('UPLOADS', nargs=-1)
@click.pass_context
def ls(ctx, uploads):
_, uploads = query_uploads(ctx, uploads)
print('%d uploads selected, showing no more than first 10' % uploads.count())
print(tabulate(
[
......@@ -59,11 +64,15 @@ def ls():
@upload.command(help='Delete selected upload')
@click.argument('UPLOADS', nargs=-1)
@click.option('--with-coe-repo', help='Also attempt to delete from repository db', is_flag=True)
@click.option('--skip-es', help='Keep the elastic index version of the data.', is_flag=True)
@click.option('--skip-mongo', help='Keep uploads and calcs in mongo.', is_flag=True)
@click.option('--skip-files', help='Keep all related files.', is_flag=True)
def rm(with_coe_repo, skip_es, skip_mongo, skip_files):
@click.pass_context
def rm(ctx, uploads, with_coe_repo, skip_es, skip_mongo, skip_files):
_, uploads = query_uploads(ctx, uploads)
logger = utils.get_logger(__name__)
print('%d uploads selected, deleting ...' % uploads.count())
......@@ -100,9 +109,13 @@ def rm(with_coe_repo, skip_es, skip_mongo, skip_files):
@upload.command(help='Attempt to abort the processing of uploads.')
@click.argument('UPLOADS', nargs=-1)
@click.option('--calcs', is_flag=True, help='Only stop calculation processing.')
@click.option('--kill', is_flag=True, help='Use the kill signal and force task failure.')
def stop(calcs: bool, kill: bool):
@click.pass_context
def stop(ctx, uploads, calcs: bool, kill: bool):
query, _ = query_uploads(ctx, uploads)
logger = utils.get_logger(__name__)
def stop_all(query):
......
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