diff --git a/reana_client/cli/workflow.py b/reana_client/cli/workflow.py index c0e5602b..efe2dcb5 100644 --- a/reana_client/cli/workflow.py +++ b/reana_client/cli/workflow.py @@ -308,6 +308,51 @@ 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_jobs') + succeeded_jobs = row['progress'].get('succeeded') + if row['progress']['total_jobs'] > 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 row['progress'] and \ + row['progress'].get('current_step_name'): + current_step_name = row['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])) @@ -322,64 +367,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()