Skip to content

Commit

Permalink
Fixed Pylint issues; fixed incorrect attribute; fixed docstrings
Browse files Browse the repository at this point in the history
Details:

* Increased max length of global names form 38/39 to 48/49.

* Fixed a fair number of easy to fix Pylint issues.

* Fixed use of incorrect attribute self._wbemserver (should have been
  self._wbem_server).

* Fixed format of docstring parameters, exceptions, return values.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Apr 8, 2020
1 parent 144012b commit a5cc793
Show file tree
Hide file tree
Showing 20 changed files with 300 additions and 275 deletions.
12 changes: 6 additions & 6 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ function-name-hint=_{0,2}([a-z][a-z0-9_]{0,28}[a-z0-9]|[a-z][a-zA-Z0-9]{1,29})(_
# other variables; one leading underscore is allowed, and one trailing
# underscore is allowed to avoid conflists with built-in names.
# Names matching this expression are compatible with PEP-8.
variable-rgx=_{0,1}([A-Z]([A-Z0-9_]{0,38}[A-Z0-9])?|[a-z]([a-z0-9_]{0,38}[a-z0-9])?|[a-z]([a-zA-Z0-9]{1,39})?)_{0,1}$
variable-rgx=_{0,1}([A-Z]([A-Z0-9_]{0,48}[A-Z0-9])?|[a-z]([a-z0-9_]{0,48}[a-z0-9])?|[a-z]([a-zA-Z0-9]{1,49})?)_{0,1}$

# Naming hint for variable names
variable-name-hint=_{0,1}([A-Z]([A-Z0-9_]{0,38}[A-Z0-9])?|[a-z]([a-z0-9_]{0,38}[a-z0-9])?|[a-z]([a-zA-Z0-9]{1,39})?)_{0,1}$
variable-name-hint=_{0,1}([A-Z]([A-Z0-9_]{0,48}[A-Z0-9])?|[a-z]([a-z0-9_]{0,48}[a-z0-9])?|[a-z]([a-zA-Z0-9]{1,49})?)_{0,1}$

# Regular expression matching correct constant names.
#
# The expression below allows "UPPER_CASE_WITH_UNDERSCORES"; leading underscores
# for privacy are allowed.
# Names matching this expression are compatible with PEP-8.
const-rgx=(_{0,1}[A-Z][A-Z0-9_]{0,38}[A-Z0-9]|(__.*__))$
const-rgx=(_{0,1}[A-Z][A-Z0-9_]{0,48}[A-Z0-9]|(__.*__))$

# Naming hint for constant names
const-name-hint=(_{0,1}[A-Z][A-Z0-9_]{0,38}[A-Z0-9]|(__.*__))$
const-name-hint=(_{0,1}[A-Z][A-Z0-9_]{0,48}[A-Z0-9]|(__.*__))$

# Regular expression matching correct attribute names.
#
Expand Down Expand Up @@ -226,10 +226,10 @@ argument-name-hint=([a-z][a-z0-9_]{0,28}[a-z0-9]|[a-z][a-zA-Z0-9]{1,29})_{0,1}$
# and "lower_case_with_underscores" and "mixedCaseWithoutUnderscores" for
# other variables; leading underscores for privacy are allowed.
# Names matching this expression are compatible with PEP-8.
class-attribute-rgx=_{0,2}([A-Z][A-Z0-9_]{0,38}[A-Z0-9]|[a-z][a-z0-9_]{0,38}[a-z0-9]|[a-z][a-zA-Z0-9]{0,39}|(__.*__))$
class-attribute-rgx=_{0,2}([A-Z][A-Z0-9_]{0,48}[A-Z0-9]|[a-z][a-z0-9_]{0,48}[a-z0-9]|[a-z][a-zA-Z0-9]{0,49}|(__.*__))$

# Naming hint for class attribute names
class-attribute-name-hint=_{0,2}([A-Z][A-Z0-9_]{0,38}[A-Z0-9]|[a-z][a-z0-9_]{0,38}[a-z0-9]|[a-z][a-zA-Z0-9]{0,39}|(__.*__))$
class-attribute-name-hint=_{0,2}([A-Z][A-Z0-9_]{0,48}[A-Z0-9]|[a-z][a-z0-9_]{0,48}[a-z0-9]|[a-z][a-zA-Z0-9]{0,49}|(__.*__))$

# Regular expression matching correct inline iteration names.
#
Expand Down
46 changes: 24 additions & 22 deletions pywbemtools/pywbemcli/_association_shrub.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,14 @@
from collections import defaultdict, OrderedDict, namedtuple
import six
import click

# TODO: Future Could we combine this tree into tree file???
from asciitree import LeftAligned

from pywbem import CIMInstanceName, CIMClassName, \
CIMFloat, CIMInt, CIMError, CIMDateTime
from ._utils import _to_unicode, _ensure_unicode

from pydicti import dicti
from pywbem import CIMInstanceName, CIMClassName, CIMFloat, CIMInt, CIMError, \
CIMDateTime

from ._common import output_format_is_table, format_table, shorten_path_str, \
warning_msg

from ._utils import _ensure_unicode, _to_unicode

# Same as in pwbem.cimtypes.py
Expand Down Expand Up @@ -146,8 +141,10 @@ def sorted_references(self, source_path):
Get reference instances from host sorted by instance name
Parameters:
source_path(:class:`pywbem:CIMInstancePath):
source_path (:class:`pywbem:CIMInstancePath):
Source path for the References request to the host
Returns:
list of :class:`pywbem:CIMClassNames` returns from host
Expand All @@ -163,17 +160,22 @@ def sorted_associator_names(self, source_path, role=None, assoc_class=None,
Get associated instances from host sorted by instance name.
Parameters:
source_path(:class:`pywbem:CIMInstancePath):
role(:term:`string`)
source_path (:class:`pywbem:CIMInstancePath):
role (:term:`string`):
Optional string defining Role parameter of the Associators
call to the host
assoc_class(:class:`pywbem:CIMClass`)
assoc_class (:class:`pywbem:CIMClass`):
Optional string defining ResutRole parameter of the Associators
call to the host.
result_role(:term:`string`)
result_role (:term:`string`):
Optional string defining ResutRole parameter of the Associators
call to the host
result_class(:class:`pywbem:CIMClass`)
result_class (:class:`pywbem:CIMClass`):
Optional string defining ResutRole parameter of the Associators
call to the host
Expand Down Expand Up @@ -563,11 +565,11 @@ def to_wbem_uri_folded(self, path, format='standard', max_len=15):

ret = []

def case(str_):
def case(astring):
"""Return the string in the correct lexical case for the format."""
if format == 'canonical':
str_ = str_.lower()
return str_
astring = astring.lower()
return astring

def case_sorted(keys):
"""Return the keys in the correct order for the format."""
Expand Down Expand Up @@ -675,14 +677,14 @@ def build_inst_names(self, inst_names_tuple, ref_cln, replacements,
Parameters:
inst_names_tuple(:func:`~py:collections.namedtuple` object):
inst_names_tuple (:func:`~py:collections.namedtuple` object):
namedtuple containing instancename and integer representing
reference instance.
ref_cln (:term:`string`):
Classname of the reference class.
replacements (:class:`dicti`)
replacements (:class:`dicti`):
No-case dictionary containing the name of each key to be considered
for replacement with either the value None or a defined value
for the key. If the value is None the key will be replaced with
Expand Down Expand Up @@ -828,11 +830,11 @@ def sort_instances(instances):
executed. to_wbem_uri(formt='canonical') accomplishes that
Parameters:
inames(list of CIMInstanceName):
inames (list of CIMInstanceName):
Returns:
list of CIMInstance name sorted.
"""
if len(instances) <= 1:
return instances
Expand All @@ -852,11 +854,11 @@ def sort_instance_names(inames):
executed. to_wbem_uri(formt='canonical') accomplishes that
Parameters:
inames(list of CIMInstanceName):
inames (list of CIMInstanceName):
Returns:
list of CIMInstance name sorted.
"""
if len(inames) <= 1:
return inames
Expand Down
26 changes: 14 additions & 12 deletions pywbemtools/pywbemcli/_cmd_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def _filter_classes_for_qualifiers(qualifier_filters, results, names_only, iq):
for qname, show_if_true in qualifier_filters.items():
if qname in cls.qualifiers:
qvalue = cls.qualifiers[qname].value
show_this = True if qvalue == show_if_true else False
show_this = (qvalue == show_if_true)
else:
show_this = not show_if_true
if not show_this:
Expand Down Expand Up @@ -535,7 +535,7 @@ def enumerate_classes_filtered(context, classname, options):
Returns:
List of classes or classnames that satisfy the criteria
Exceptions:
Raises:
pywbem Error exceptions generated by EnumerateClassNames and
enumerateClasses
"""
Expand Down Expand Up @@ -580,23 +580,26 @@ def get_format_group(context, options):
for enumerate, get, associators, or references unless options such as
summary, or names_only are set.
"""

# Summary always output as TABLE
if 'summary' in options and options['summary']:

# This accounts for the fact that the results of a summary can be
# either table or simply a string output
if context.output_format and context.output_format in TABLE_FORMATS:
return ['TABLE']
else:
# Temporary hack. We need another format group, i.e. txt or str
# That displays in non-structured manner. Or drop this output
# completely.
return ['CIM']

# Temporary hack. We need another format group, i.e. txt or str
# That displays in non-structured manner. Or drop this output
# completely.
return ['CIM']

# Names_only may be output as Table or as CIM Object.
elif 'names_only' in options and options['names_only']:
if 'names_only' in options and options['names_only']:
return ['CIM', 'TABLE']

# otherwise only CIM allowed today.
else:
return ['CIM']
return ['CIM']


#####################################################################
Expand Down Expand Up @@ -735,8 +738,7 @@ def get_namespaces(context, namespaces):
Returns either the namespaces provided or if that is None, the set of
namespaces that are defined in the wbem server as a list
Exceptions:
Raises:
CIMError if status code not CIM_ERR_NOT_FOUND
"""
ns_names = []
Expand Down
16 changes: 4 additions & 12 deletions pywbemtools/pywbemcli/_cmd_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def show_connection_information(context, connection, separate_line=True,
context.spinner_stop()

click.echo(format_table(rows, headers, title='Connection status:',
table_format=output_format))
table_format=output_format))


def get_current_connection_name(context):
Expand All @@ -387,14 +387,12 @@ def raise_repository_empty(connections):


def select_connection(name, context, connections):
# pylint: disable=inconsistent-return-statement
"""
Use the interactive mode to select the connection from the list of
connections in the connections file. If the name is provided, it is tested
against the names in the connections file. If it is not provided,
"""
context.spinner_stop()
# get all names from dictionary

if not connections:
raise_repository_empty(connections)
Expand All @@ -407,13 +405,8 @@ def select_connection(name, context, connections):
.format(name, connections.connections_file))

conn_names = sorted(list(six.iterkeys(connections)))

# TODO: Really do not need the if on conn_names. already tested above
if conn_names:
# TODO the Ctrl_C should be part of the pick from list
return pick_one_from_list(context, conn_names,
"Select a connection or Ctrl_C to abort.")
raise_repository_empty(connections)
return pick_one_from_list(context, conn_names,
"Select a connection or Ctrl-C to abort.")


################################################################
Expand Down Expand Up @@ -606,8 +599,7 @@ def build_row(options, name, svr):
return [name, svr.server, svr.default_namespace, svr.user,
svr.timeout, svr.use_pull, svr.verify, svr.certfile,
svr.keyfile, "\n".join(svr.mock_server)]
else:
return[name, svr.server, "\n".join(svr.mock_server)]
return [name, svr.server, "\n".join(svr.mock_server)]

connections = ConnectionRepository()
output_format = validate_output_format(context.output_format, 'TABLE')
Expand Down
Loading

0 comments on commit a5cc793

Please sign in to comment.