Skip to content

Commit

Permalink
Merge 96d6c26 into 2ab0021
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis authored Jul 31, 2018
2 parents 2ab0021 + 96d6c26 commit 2ddc336
Showing 1 changed file with 62 additions and 50 deletions.
112 changes: 62 additions & 50 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,59 @@ def workflow_start(ctx, workflow, access_token):
def workflow_status(ctx, workflow, _filter, output_format,
access_token, verbose):
"""Get status of previously created workflow."""
def show_progress(succeeded_jobs, total_jobs):
if total_jobs:
return '{0}/{1}'.format(succeeded_jobs, total_jobs)
else:
return '-/-'

def get_data_from_row(row, data, headers):
name, run_number = get_workflow_name_and_run_number(
row['name'])
total_jobs = row['progress'].get('total')
if total_jobs:
total_jobs = total_jobs.get('total')
else:
total_jobs = 0
succeeded_jobs = row['progress'].get('finished')
if succeeded_jobs:
succeeded_jobs = succeeded_jobs.get('total')
else:
succeeded_jobs = 0
if row['progress']['total'] > 0:
if 'progress' not in headers:
headers += ['progress']

data.append(list(map(
str,
[name,
run_number,
row['created'],
row['status'],
show_progress(succeeded_jobs, total_jobs)])))

def add_verbose_columns(response, verbose_headers, headers, data):
for k in verbose_headers:
if k == 'command':
current_command = response['progress']['current_command']
if current_command:
if current_command.startswith('bash -c "cd '):
current_command = current_command[
current_command.
index(';') + 2:-2]
data[-1] += [current_command]
else:
if 'current_step_name' in response['progress'] and \
response['progress'].get('current_step_name'):
current_step_name = response['progress'].\
get('current_step_name')
data[-1] += [current_step_name]
else:
headers.remove('command')
else:
data[-1] += [response.get(k)]
return data

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 @@ -322,64 +375,23 @@ def workflow_status(ctx, workflow, _filter, output_format,
try:
response = ctx.obj.client.get_workflow_status(workflow,
access_token)
verbose_headers = ['id', 'user']
headers = ['name', 'run_number', 'created',
'status', 'progress', 'command']
headers = ['name', 'run_number', 'created', 'status', 'progress']
verbose_headers = ['id', 'user', '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])))

get_data_from_row(workflow, data, headers)
if verbose:
data[-1] += [workflow.get(k) for k in verbose_headers]
data = add_verbose_columns(workflow, verbose_headers,
headers, data)

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])))
get_data_from_row(response, data, headers)
if verbose:
data[-1] += [response.get(k) for k in verbose_headers]
data = add_verbose_columns(response, verbose_headers,
headers, data)

if output_format:
tablib_data = tablib.Dataset()
Expand Down

0 comments on commit 2ddc336

Please sign in to comment.