Skip to content

Commit

Permalink
utils: import cli printer from reana-commons
Browse files Browse the repository at this point in the history
Signed-off-by: Dinos Kousidis <[email protected]>
  • Loading branch information
dinosk committed Apr 19, 2018
1 parent 02f2d3b commit 3b9f994
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 31 deletions.
4 changes: 2 additions & 2 deletions reana_client/cli/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ..errors import FileUploadError
from ..api.client import UploadType
from ..config import default_organization, default_user
from ..utils import cli_printer
from reana_commons.utils import click_table_printer


@click.group(
Expand Down Expand Up @@ -100,7 +100,7 @@ def code_list(ctx, user, organization, workflow, _filter, output_format):
rows=None, cols=list(_filter))
click.echo(tablib_data.export(output_format))
else:
cli_printer(headers, _filter, data)
click_table_printer(headers, _filter, data)

except Exception as e:
logging.debug(traceback.format_exc())
Expand Down
4 changes: 2 additions & 2 deletions reana_client/cli/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ..config import default_organization, default_user
from ..errors import FileUploadError
from ..api.client import UploadType
from ..utils import cli_printer
from reana_commons.utils import click_table_printer


@click.group(
Expand Down Expand Up @@ -99,7 +99,7 @@ def inputs_list(ctx, user, organization, workflow, _filter, output_format):
rows=None, cols=list(_filter))
click.echo(tablib_data.export(output_format))
else:
cli_printer(headers, _filter, data)
click_table_printer(headers, _filter, data)

except Exception as e:
logging.debug(traceback.format_exc())
Expand Down
4 changes: 2 additions & 2 deletions reana_client/cli/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import tablib

from ..config import default_download_path, default_organization, default_user
from ..utils import cli_printer
from reana_commons.utils import click_table_printer


@click.group(
Expand Down Expand Up @@ -100,7 +100,7 @@ def outputs_list(ctx, user, organization, workflow, _filter, output_format):
rows=None, cols=list(_filter))
click.echo(tablib_data.export(output_format))
else:
cli_printer(headers, _filter, data)
click_table_printer(headers, _filter, data)

except Exception as e:
logging.debug(traceback.format_exc())
Expand Down
7 changes: 4 additions & 3 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
from ..config import (default_organization, default_user,
reana_yaml_default_file_path)
from ..utils import get_workflow_name_and_run_number, load_reana_spec, \
load_workflow_spec, is_uuid_v4, workflow_uuid_or_name, cli_printer
load_workflow_spec, is_uuid_v4, workflow_uuid_or_name
from reana_commons.utils import click_table_printer


class _WorkflowStatus(Enum):
Expand Down Expand Up @@ -107,7 +108,7 @@ def workflow_list(ctx, user, organization, _filter, output_format):

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

except Exception as e:
logging.debug(traceback.format_exc())
Expand Down Expand Up @@ -322,7 +323,7 @@ def workflow_status(ctx, user, organization, workflow, _filter, output_format):

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

except Exception as e:
logging.debug(traceback.format_exc())
Expand Down
22 changes: 0 additions & 22 deletions reana_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,3 @@ def get_analysis_root():
analysis_root = parent_dir
analysis_root += '/'
return analysis_root


def cli_printer(headers, _filter, data):
"""Print a response in a tabulated format."""
_filter = [h.lower() for h in _filter] + [h.upper() for h in _filter]
headers = [h for h in headers if not _filter or h in _filter]
# Maximum header width
header_widths = [len(h) for h in headers]

for row in data:
for idx in range(len(headers)):
# If a row contains an element which is wider update maximum width
if header_widths[idx] < len(str(row[idx])):
header_widths[idx] = len(str(row[idx]))
# Prepare the format string with the maximum widths
formatted_output_parts = ['{{:<{0}}}'.format(hw)
for hw in header_widths]
formatted_output = ' '.join(formatted_output_parts)
# Print the table with the headers capitalized
click.echo(formatted_output.format(*[h.upper() for h in headers]))
for row in data:
click.echo(formatted_output.format(*row))
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'strict-rfc3339==0.7', # FIXME remove once yadage-schemas solves deps.
'tablib>=0.12.1',
'webcolors==1.7', # FIXME remove once yadage-schemas solves deps.
'reana-commons',
]

packages = find_packages()
Expand Down

0 comments on commit 3b9f994

Please sign in to comment.