Skip to content

Commit

Permalink
Merge 0ce75c8 into e76d794
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Jul 23, 2018
2 parents e76d794 + 0ce75c8 commit af0239f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 145 deletions.
7 changes: 5 additions & 2 deletions reana_client/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def cli(ctx, loglevel):
level=loglevel)
ctx.obj = Config()

commands = []
commands.extend(workflow.workflow.commands.values())
commands.extend(files.files.commands.values())
for cmd in commands:
cli.add_command(cmd)
cli.add_command(ping.ping)
cli.add_command(workflow.workflow)
cli.add_command(files.files)
cli.add_command(status.status)
153 changes: 10 additions & 143 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def workflow(ctx):


@click.command(
'list',
'workflows',
help='List all available workflows.')
@click.option(
'--filter',
Expand All @@ -78,8 +78,8 @@ def workflow(ctx):
count=True,
help='Set status information verbosity.')
@click.pass_context
def workflow_list(ctx, _filter, output_format, access_token,
verbose):
def workflow_workflows(ctx, _filter, output_format, access_token,
verbose):
"""List all workflows user has."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
Expand Down Expand Up @@ -273,142 +273,8 @@ def workflow_start(ctx, workflow, access_token):


@click.command(
'status',
help='Get status of a previously created workflow.')
@click.option(
'-w',
'--workflow',
default=os.environ.get('REANA_WORKON', None),
callback=workflow_uuid_or_name,
help='Name or UUID of the workflow whose status should be resolved. '
'Overrides value of REANA_WORKON.')
@click.option(
'--filter',
'_filter',
multiple=True,
help='Filter output according to column titles (case-sensitive).')
@click.option(
'--json',
'output_format',
flag_value='json',
default=None,
help='Get output in JSON format.')
@click.option(
'-at',
'--access-token',
default=os.environ.get('REANA_ACCESS_TOKEN', None),
help='Access token of the current user.')
@click.option(
'-v',
'--verbose',
count=True,
help='Set status information verbosity.')
@click.pass_context
def workflow_status(ctx, workflow, _filter, output_format,
access_token, verbose):
"""Get status of previously created workflow."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))

if not access_token:
click.echo(
click.style(ERROR_MESSAGES['missing_access_token'],
fg='red'), err=True)
sys.exit(1)

if workflow:
try:
response = ctx.obj.client.get_workflow_status(workflow,
access_token)
verbose_headers = ['id', 'user']
headers = ['name', 'run_number', 'created',
'status', 'progress', 'command']
if verbose:
headers += verbose_headers
data = []
if isinstance(response, list):
for workflow in response:
name, run_number = get_workflow_name_and_run_number(
workflow['name'])
current_command = workflow['progress']['current_command']
if current_command:
if current_command.startswith('bash -c "cd '):
current_command = current_command[
current_command.
index(';') + 2:-2]
else:
if 'command' in headers:
headers.remove('command')
data.append(list(map(
str,
[name,
run_number,
workflow['created'],
workflow['status'],
'{0}/{1}'.
format(
workflow['progress']['succeeded'],
workflow['progress']['total_jobs']),
current_command])))

if verbose:
data[-1] += [workflow.get(k) for k in verbose_headers]
else:
name, run_number = get_workflow_name_and_run_number(
response['name'])
current_command = response['progress'].get('current_command')
if current_command:
if current_command.startswith('bash -c "cd '):
current_command = current_command[
current_command.
index(';') + 2:-2]
else:
if 'command' in headers:
headers.remove('command')
data.append(list(
map(str,
[name,
run_number,
response['created'],
response['status'],
'{0}/{1}'.
format(
response['progress'].get('succeeded', '-'),
response['progress'].get('total_jobs', '-')),
current_command])))
if verbose:
data[-1] += [response.get(k) for k in verbose_headers]

if output_format:
tablib_data = tablib.Dataset()
tablib_data.headers = headers
for row in data:
tablib_data.append(row)

if _filter:
data = data.subset(rows=None, cols=list(_filter))

click.echo(data.export(output_format))
else:
click_table_printer(headers, _filter, data)

except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
click.echo(
click.style('Workflow status could not be retrieved: \n{}'
.format(str(e)), fg='red'),
err=True)
else:
click.echo(
click.style('Workflow name must be provided either with '
'`--workflow` option or with REANA_WORKON '
'environment variable',
fg='red'),
err=True)


'logs',
help='Get workflow logs.')
@click.option(
'-w',
'--workflow',
Expand All @@ -423,7 +289,7 @@ def workflow_status(ctx, workflow, _filter, output_format,
help='Access token of the current user.')
@click.pass_context
def workflow_logs(ctx, workflow, access_token):
"""Get status of previously created workflow."""
"""Get workflow logs."""
logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))
Expand All @@ -448,7 +314,9 @@ def workflow_logs(ctx, workflow, access_token):
err=True)


@click.command('validate')
@click.command(
'validate',
help='Get workflow logs.')
@click.option(
'-f',
'--file',
Expand Down Expand Up @@ -485,9 +353,8 @@ def workflow_validate(ctx, file):
err=True)


workflow.add_command(workflow_list)
workflow.add_command(workflow_workflows)
workflow.add_command(workflow_create)
workflow.add_command(workflow_start)
workflow.add_command(workflow_status)
workflow.add_command(workflow_validate)
# workflow.add_command(workflow_logs)

0 comments on commit af0239f

Please sign in to comment.