Skip to content

Commit

Permalink
Merge 950ccf5 into 7a7b414
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-maier committed Jun 28, 2020
2 parents 7a7b414 + 950ccf5 commit b50fc29
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -637,9 +637,9 @@ safety_$(pymn).done: develop_$(pymn).done Makefile minimum-constraints.txt
test: develop_$(pymn).done $(doc_utility_help_files)
@echo "makefile: Running unit and function tests"
ifeq ($(PLATFORM),Windows_native)
cmd /c "set PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) & py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s"
cmd /c "set PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) & set PYWBEMCLI_DEPRECATION_WARNINGS=false& py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s"
else
PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s
PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) PYWBEMCLI_DEPRECATION_WARNINGS=false py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s
endif
@echo "makefile: Done running tests"

Expand Down
4 changes: 4 additions & 0 deletions docs/changes.rst
Expand Up @@ -18,6 +18,10 @@ Released: not yet

**Deprecations:**

* Deprecated support for Python 2.7 and 3.4, because these Python versions have
reached their end of life. A future version of pywbemtools will remove support
for Python 2.7 and 3.4. (see issue #630).

**Bug fixes:**

* Fixed incorrect connection list output in readme files (see issue #593).
Expand Down
2 changes: 2 additions & 0 deletions docs/pywbemcli/cmdshelp.rst
Expand Up @@ -115,6 +115,8 @@ Help text for ``pywbemcli``:
[all|paths|summary], default: all. Default: EnvVar PYWBEMCLI_LOG, or all.

-v, --verbose / --no-verbose Display extra information about the processing.
--deprecation-warnings / --no-deprecation-warnings
Enable deprecation warnings. Default: EnvVar PYWBEMCLI_DEPRECATION_WARNINGS, or true.
--pdb Pause execution in the built-in pdb debugger just before executing the command within
pywbemcli. Default: EnvVar PYWBEMCLI_PDB, or false.

Expand Down
57 changes: 37 additions & 20 deletions docs/pywbemcli/generaloptions.rst
Expand Up @@ -198,6 +198,9 @@ Other miscellaneous general options
The :ref:`--verbose general option` displays extra information about the
pywbemcli internal processing.

The :ref:`--deprecation-warnings general option` controls the display of
deprecation warnings.

The :ref:`--version general option` displays pywbemcli version
information and the :ref:`--help general option` provides top level help

Expand Down Expand Up @@ -634,6 +637,19 @@ command completion.

.. index:: triple: --pdb; general options; pdb

.. _`--deprecation-warnings general option`:

``--deprecation-warnings`` general option
""""""""""""""""""""""""""""""""""""""""""""

The ``--deprecation-warnings``/``--no-deprecation-warnings`` general option is
a boolean option that controls the display of deprecation warnings on the
standard error stream.

By default, the display of deprecation warnings is enabled.

.. index:: triple: --deprecation-warnings; --no-deprecation-warnings; general options; deprecation warnings

.. _`--pdb general option`:

``--pdb`` general option
Expand Down Expand Up @@ -679,26 +695,27 @@ Environment variables for general options
Pywbemcli defines environment variables corresponding to its general options
as follows:

============================== ============================
Environment variable Corresponding general option
============================== ============================
PYWBEMCLI_SERVER ``--server``
PYWBEMCLI_NAME ``--name``
PYWBEMCLI_USER ``--user``
PYWBEMCLI_PASSWORD ``--password``
PYWBEMCLI_OUTPUT_FORMAT ``--output-format``
PYWBEMCLI_DEFAULT_NAMESPACE ``--default-namespace``
PYWBEMCLI_TIMEOUT ``--timeout``
PYWBEMCLI_KEYFILE ``--keyfile``
PYWBEMCLI_CERTFILE ``--certfile``
PYWBEMCLI_CA_CERTS ``--ca-certs``
PYWBEMCLI_USE_PULL ``--use-pull``
PYWBEMCLI_PULL_MAX_CNT ``--pull-max-cnt``
PYWBEMCLI_STATS_ENABLED ``--timestats``
PYWBEMCLI_MOCK_SERVER (1) ``--mock-server``
PYWBEMCLI_LOG ``--log``
PYWBEMCLI_PDB ``--pdb``
============================== ============================
================================= =============================
Environment variable Corresponding general option
================================= =============================
PYWBEMCLI_SERVER ``--server``
PYWBEMCLI_NAME ``--name``
PYWBEMCLI_USER ``--user``
PYWBEMCLI_PASSWORD ``--password``
PYWBEMCLI_OUTPUT_FORMAT ``--output-format``
PYWBEMCLI_DEFAULT_NAMESPACE ``--default-namespace``
PYWBEMCLI_TIMEOUT ``--timeout``
PYWBEMCLI_KEYFILE ``--keyfile``
PYWBEMCLI_CERTFILE ``--certfile``
PYWBEMCLI_CA_CERTS ``--ca-certs``
PYWBEMCLI_USE_PULL ``--use-pull``
PYWBEMCLI_PULL_MAX_CNT ``--pull-max-cnt``
PYWBEMCLI_STATS_ENABLED ``--timestats``
PYWBEMCLI_MOCK_SERVER (1) ``--mock-server``
PYWBEMCLI_LOG ``--log``
PYWBEMCLI_PDB ``--pdb``
PYWBEMCLI_DEPRECATION_WARNINGS ``--deprecation-warnings``
================================= =============================

Notes:

Expand Down
3 changes: 2 additions & 1 deletion pywbemtools/pywbemcli/_cmd_connection.py
Expand Up @@ -646,7 +646,8 @@ def cmd_connection_select(context, name, options):
context.timestats,
context.log,
context.verbose,
context.pdb)
context.pdb,
context.deprecation_warnings)

# Update the root context making this context the basis for future
# commands in the current interactive session
Expand Down
11 changes: 10 additions & 1 deletion pywbemtools/pywbemcli/_context_obj.py
Expand Up @@ -43,7 +43,8 @@ class ContextObj(object): # pylint: disable=useless-object-inheritance

# pylint: disable=unused-argument
def __init__(self, pywbem_server, output_format, use_pull,
pull_max_cnt, timestats, log, verbose, pdb):
pull_max_cnt, timestats, log, verbose, pdb,
deprecation_warnings):

self._pywbem_server = pywbem_server
self._output_format = output_format
Expand All @@ -53,6 +54,7 @@ def __init__(self, pywbem_server, output_format, use_pull,
self._log = log
self._verbose = verbose
self._pdb = pdb
self._deprecation_warnings = deprecation_warnings

self._spinner_enabled = None # Deferred init in getter
self._spinner_obj = click_spinner.Spinner()
Expand Down Expand Up @@ -113,6 +115,13 @@ def pdb(self):
"""
return self._pdb

@property
def deprecation_warnings(self):
"""
bool: Indicates whether to enable deprecation warnings.
"""
return self._deprecation_warnings

@property
def conn(self):
"""
Expand Down
1 change: 1 addition & 0 deletions pywbemtools/pywbemcli/_pywbem_server.py
Expand Up @@ -103,6 +103,7 @@ class PywbemServer(object):
mock_server_envvar = 'PYWBEMCLI_MOCK_SERVER'
log_envvar = 'PYWBEMCLI_LOG'
pdb_envvar = 'PYWBEMCLI_PDB'
deprecation_warnings_envvar = 'PYWBEMCLI_DEPRECATION_WARNINGS'
termwidth_envvar = 'PYWBEMCLI_TERMWIDTH'

def __init__(self, server=None, default_namespace=DEFAULT_NAMESPACE,
Expand Down
10 changes: 10 additions & 0 deletions pywbemtools/pywbemcli/_utils.py
Expand Up @@ -20,6 +20,7 @@
from __future__ import print_function, absolute_import

import six
import click


__all__ = []
Expand Down Expand Up @@ -67,3 +68,12 @@ def _eq_name(name1, name2):
if name2 is None:
return False
return name1.lower() == name2.lower()


def deprecation_warning(msg, ctx_obj):
"""
Display a deprecation warning on stderr, unless disabled via
ctx_obj.deprecation_warnings.
"""
if ctx_obj.deprecation_warnings:
click.echo(msg, err=True)
23 changes: 20 additions & 3 deletions pywbemtools/pywbemcli/pywbemcli.py
Expand Up @@ -32,6 +32,7 @@
from pywbem import LOGGER_SIMPLE_NAMES, \
LOG_DESTINATIONS, DEFAULT_LOG_DESTINATION, LOG_DETAIL_LEVELS, \
DEFAULT_LOG_DETAIL_LEVEL
from pywbem import __version__ as PYWBEM_VERSION

from ._context_obj import ContextObj, display_click_context
from ._common import GENERAL_OPTS_TXT, SUBCMD_HELP_TXT, OUTPUT_FORMAT_GROUPS
Expand All @@ -42,7 +43,7 @@
DEFAULT_CONNECTION_TIMEOUT, MAX_TIMEOUT, USE_AUTOSUGGEST
from ._connection_repository import ConnectionRepository
from ._click_extensions import PywbemcliTopGroup
from pywbem import __version__ as PYWBEM_VERSION
from ._utils import deprecation_warning

__all__ = ['cli']

Expand Down Expand Up @@ -237,6 +238,12 @@
@click.option('-v', '--verbose/--no-verbose',
default=None,
help='Display extra information about the processing.')
@click.option('--deprecation-warnings/--no-deprecation-warnings', is_flag=True,
default=True,
envvar=PywbemServer.deprecation_warnings_envvar,
help='Enable deprecation warnings. '
'Default: EnvVar {ev}, or true.'.
format(ev=PywbemServer.deprecation_warnings_envvar))
@click.option('--pdb', is_flag=True,
# defaulted in code
envvar=PywbemServer.pdb_envvar,
Expand All @@ -253,7 +260,7 @@
def cli(ctx, server, svr_name, default_namespace, user, password, timeout,
verify, certfile, keyfile, ca_certs, output_format, use_pull,
pull_max_cnt, mock_server, verbose=None, timestats=None, log=None,
pdb=None):
pdb=None, deprecation_warnings=None):
"""
Pywbemcli is a command line WBEM client that uses the DMTF CIM-XML protocol
to communicate with WBEM servers. Pywbemcli can:
Expand Down Expand Up @@ -578,6 +585,8 @@ def create_server_instance(svr_name):
verbose = ctx.obj.verbose
if pdb is None:
pdb = ctx.obj.pdb
if deprecation_warnings is None:
deprecation_warnings = ctx.obj.deprecation_warnings

# Create a command context for each command: An interactive command has
# its own command context as a child of the command context for the
Expand All @@ -586,12 +595,20 @@ def create_server_instance(svr_name):
resolved_use_pull,
resolved_pull_max_cnt,
resolved_timestats,
log, verbose, pdb)
log, verbose, pdb, deprecation_warnings)
if verbose and os.getenv('PYWBEMCLI_DIAGNOSTICS'):
print('CONTEXT_OBJ {!r}'.format(ctx.obj))
print('CLICK CTX {}'.format(ctx))
display_click_context(ctx, msg="After adding Context",
display_attrs=True)

_python_nm = sys.version_info[0:2]
if _python_nm == (2, 7) or _python_nm == (3, 4):
deprecation_warning(
"Deprecation: Pywbemcli support for Python {}.{} is deprecated "
"and will be removed in a future version".
format(_python_nm[0], _python_nm[1]), ctx.obj)

# Invoke command if one exists.
if ctx.invoked_subcommand is None:
ctx.invoke(repl)
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_common.py
Expand Up @@ -822,7 +822,8 @@ def test_pick_one_from_list(testcase, options, choices, exp_rtn):

# test option with only one choice bypasses user request
if not choices:
context = ContextObj(None, None, None, None, None, None, None, None)
context = ContextObj(None, None, None, None, None, None, None, None,
None)
act_rtn = pick_one_from_list(context, options, title)
else:
# setup mock for this test
Expand All @@ -836,7 +837,7 @@ def test_pick_one_from_list(testcase, options, choices, exp_rtn):
# The code to be tested
# Fake context object
context = ContextObj(None, None, None, None, None, None, None,
None)
None, None)
act_rtn = pick_one_from_list(context, options, title)
context.spinner_stop()
assert mock_prompt.call_count == len(choices)
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_general_options.py
Expand Up @@ -190,6 +190,10 @@
-v, --verbose / --no-verbose Display extra information about the
processing.
--deprecation-warnings / --no-deprecation-warnings
Enable deprecation warnings. Default: EnvVar
PYWBEMCLI_DEPRECATION_WARNINGS, or true.
--pdb Pause execution in the built-in pdb debugger
just before executing the command within
pywbemcli. Default: EnvVar PYWBEMCLI_PDB, or
Expand Down
4 changes: 2 additions & 2 deletions tools/click_help_capture.py
Expand Up @@ -148,7 +148,7 @@ def get_subcmd_group_names(script_cmd, script_name, cmd):
returns list of command groups/commands
"""
command = '{} {} --help'.format(script_cmd, cmd)
command = '{} --no-deprecation-warnings {} --help'.format(script_cmd, cmd)
# Disable python warnings for script call.
if sys.platform != 'win32':
command = 'export PYTHONWARNINGS="" && {}'.format(command)
Expand All @@ -169,7 +169,7 @@ def get_subcmd_group_names(script_cmd, script_name, cmd):
raise RuntimeError('Error: Shell execution of command {!r} failed with '
'rc={}: {}'.format(command, exitcode, std_err))
if std_err:
raise RuntimeError("Error: Unexpected stderr from command {!r}}:\n"
raise RuntimeError("Error: Unexpected stderr from command {!r}:\n"
"{}".format(command, std_err))

# Split stdout into list of lines
Expand Down

0 comments on commit b50fc29

Please sign in to comment.