Skip to content

Commit

Permalink
Removed support for old connection show format; cleanup
Browse files Browse the repository at this point in the history
Details:

* Removed support for old 'connection show' output format

* Adjusted the testcases accordingly.

* Cleaned up the code in show_connection_information(), by removing
  the code that processed the connection.mock_server because that is
  now done in fold_strings().

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Apr 8, 2020
1 parent cad7247 commit e1fdd2b
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 280 deletions.
89 changes: 31 additions & 58 deletions pywbemtools/pywbemcli/_cmd_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
from .pywbemcli import cli
from ._common import CMD_OPTS_TXT, GENERAL_OPTS_TXT, \
SUBCMD_HELP_TXT, pick_one_from_list, format_table, \
raise_pywbem_error_exception, validate_output_format, \
fold_strings, output_format_is_table
raise_pywbem_error_exception, validate_output_format, fold_strings
from ._common_options import add_options, help_option
from ._pywbem_server import PywbemServer
from ._connection_repository import ConnectionRepository
Expand Down Expand Up @@ -316,6 +315,9 @@ def show_connection_information(context, connection, separate_line=True,
could also have been part of the context object since this is just the
info from that object.
"""

output_format = validate_output_format(context.output_format, 'TABLE')

# Build state string, mock_server obj, password
state_str = ''
if show_state:
Expand All @@ -327,74 +329,45 @@ def show_connection_information(context, connection, separate_line=True,
if state:
state_str = ' ({})'.format(", ".join(state))

if isinstance(connection.mock_server, (list, tuple)):
mock_server = ', '.join(connection.mock_server)
else:
mock_server = connection.mock_server

if connection.password:
disp_password = connection.password if show_password else '******'
else:
disp_password = connection.password

if output_format_is_table(context.output_format):
headers = ["name", 'value (state)']
if isinstance(connection.mock_server, (list, tuple)):
mock_server = ', '.join(connection.mock_server)
else:
mock_server = connection.mock_server
headers = ["name", 'value (state)']

if connection.ca_certs:
ca_certs = fold_strings(connection.ca_certs, 20,
fold_list_items=True,
break_long_words=False)
else:
ca_certs = None
mock_server = fold_strings(mock_server, 20,
if connection.mock_server:
mock_server = fold_strings(connection.mock_server, 20,
fold_list_items=True,
break_long_words=False,
break_on_hyphens=False)
else:
mock_server = None

rows = [['name', "{}{}".format(connection.name, state_str)],
['server', connection.server],
['default-namespace', connection.default_namespace],
['user', connection.user],
['password', disp_password],
['timeout', connection.timeout],
['use-pull', connection.use_pull],
['verify', connection.verify],
['certfile', connection.certfile],
['keyfile', connection.keyfile],
['pmock-server', mock_server],
['ca_certs', ca_certs]]

context.spinner_stop()

click.echo(format_table(rows, headers, title='Connection status:',
table_format=context.output_format))
if connection.ca_certs:
ca_certs = fold_strings(connection.ca_certs, 20,
fold_list_items=True,
break_long_words=False)
else:
context.spinner_stop()
ca_certs = None

rows = [['name', "{}{}".format(connection.name, state_str)],
['server', connection.server],
['default-namespace', connection.default_namespace],
['user', connection.user],
['password', disp_password],
['timeout', connection.timeout],
['use-pull', connection.use_pull],
['verify', connection.verify],
['certfile', connection.certfile],
['keyfile', connection.keyfile],
['mock-server', mock_server],
['ca-certs', ca_certs]]

context.spinner_stop()

click.echo('\nname: {cn}{st}{sep}server: {sv}{sep}'
'default-namespace: {dns}{sep}'
'user: {usr}{sep}password: {pw}{sep}timeout: {to}{sep}'
'use-pull: {up}{sep}'
'verify: {ve}{sep}certfile: {cf}{sep}keyfile: {kf}{sep}'
'mock-server: {ms}{sep}ca-certs: {crts}{sep}'
.format(cn=connection.name,
st=state_str,
sv=connection.server,
dns=connection.default_namespace,
usr=connection.user,
pw=disp_password,
to=connection.timeout,
up=connection.use_pull,
ve=connection.verify,
cf=connection.certfile,
kf=connection.keyfile,
ms=mock_server,
crts=connection.ca_certs,
sep='\n ' if separate_line else ', '))
click.echo(format_table(rows, headers, title='Connection status:',
table_format=output_format))


def get_current_connection_name(context):
Expand Down
Loading

0 comments on commit e1fdd2b

Please sign in to comment.