From bc2b2c4a817bcb552bc79c7c4873397236321445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Vidal=20Garc=C3=ADa?= Date: Mon, 25 Oct 2021 14:37:32 +0200 Subject: [PATCH] quota-show: display raw values by default closes #575 --- reana_client/cli/quotas.py | 19 ++++++++----------- reana_client/config.py | 9 +-------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/reana_client/cli/quotas.py b/reana_client/cli/quotas.py index 72fdd259..03760403 100644 --- a/reana_client/cli/quotas.py +++ b/reana_client/cli/quotas.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # This file is part of REANA. -# Copyright (C) 2020 CERN. +# Copyright (C) 2020, 2021 CERN. # # REANA is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -12,13 +12,14 @@ import click +from reana_commons.config import REANA_RESOURCE_HEALTH_COLORS + from reana_client.cli.utils import ( NotRequiredIf, add_access_token_options, check_connection, human_readable_or_raw_option, ) -from reana_client.config import HEALTH_TO_MSG_TYPE from reana_client.printer import display_message @@ -97,25 +98,21 @@ def quota_show( ) sys.exit(1) if not report: - human_readable_or_raw = ( - "human_readable" # when no report always show human readable - ) usage = quota[resource].get("usage") limit = quota[resource].get("limit") limit_str = "" percentage = "" - msg_type = None + kwargs = dict() if limit and limit.get("raw", 0) > 0: health = quota[resource].get("health") percentage = usage_percentage(usage.get("raw"), limit.get("raw")) - limit_str = "out of {} used".format(limit.get(human_readable_or_raw)) - msg_type = HEALTH_TO_MSG_TYPE.get(health) + limit_str = f"out of {limit.get(human_readable_or_raw)} used" + kwargs = dict(fg=REANA_RESOURCE_HEALTH_COLORS.get(health)) else: limit_str = "used" - return display_message( - "{} {} {}".format(usage[human_readable_or_raw], limit_str, percentage), - msg_type=msg_type, + return click.secho( + f"{usage[human_readable_or_raw]} {limit_str} {percentage}", **kwargs ) result = ( diff --git a/reana_client/config.py b/reana_client/config.py index 89320fce..a650aff1 100644 --- a/reana_client/config.py +++ b/reana_client/config.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- # # This file is part of REANA. -# Copyright (C) 2017, 2018 CERN. +# Copyright (C) 2017, 2018, 2019, 2020, 2021 CERN. # # REANA is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """REANA client configuration.""" -import os import pkg_resources @@ -78,12 +77,6 @@ PRINTER_COLOUR_INFO = "cyan" """Default colour for info messages on terminal.""" -HEALTH_TO_MSG_TYPE = { - "critical": "error", - "healthy": "success", - "warning": "warning", -} - JOB_STATUS_TO_MSG_COLOR = { "failed": "red", "finished": "green",