Skip to content

Commit

Permalink
Merge 5310306 into 3691c37
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-maier committed Aug 16, 2020
2 parents 3691c37 + 5310306 commit ed4e93c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
7 changes: 7 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ Released: not yet
* Test: Enabled coveralls to run on all Python versions in the Travis CI,
resulting in a combined coverage for all Python versions.

* For instance display in table format, added the display of
the units of properties to the table headers. If a property
in the class has a PUnit or Units qualifier set, the unit
is translated to a human readable SI unit using the pywbem.siunit_obj()
function, and appended to the property name in square brackets.
(See issue #727)

**Cleanup**

* Remove unused NocaseList from __common.py
Expand Down
5 changes: 4 additions & 1 deletion minimum-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ wheel==0.33.5; python_version >= '3.8'

# Direct dependencies for install (must be consistent with requirements.txt)

pywbem==0.17.0
# pywbem==0.17.0
# Alternative to test against current github master pywbem
git+https://github.com/pywbem/pywbem.git@andy/unit-support#egg=pywbem
# TODO: Upgrade to pywbem 1.1.0 once released.

six==1.10.0
Click==7.0
Expand Down
41 changes: 38 additions & 3 deletions pywbemtools/pywbemcli/_display_cimobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import click

from pywbem import CIMInstanceName, CIMInstance, CIMClass, \
CIMQualifierDeclaration, CIMClassName, ValueMapping
CIMQualifierDeclaration, CIMClassName, ValueMapping, siunit_obj

from ._common import format_table, fold_strings, DEFAULT_MAX_CELL_WIDTH, \
output_format_is_table, sort_cimobjects, format_keys
Expand Down Expand Up @@ -478,10 +478,45 @@ def _display_instances_as_table(insts, table_width, table_format,
else:
max_cell_width = table_width

header_line = []
# TODO: Decide whether and how the showing of units should be controlled.
show_units = True

if show_units:
# Retrieve the most derived class of these instances. This is necessary
# because that is the only class that has all properties that may be
# needed.
derived_class_obj = None
for inst in insts:
classname = inst.classname
if inst.path is None:
# The only operation returning instances without a path is
# query execution. For now, we simply don't display units in
# that case.
# TODO: Pass a namespace for query execution to display units
continue
namespace = inst.path.namespace
class_obj = context.conn.GetClass(
classname, namespace=namespace,
IncludeQualifiers=True, LocalOnly=False)
if not derived_class_obj or context.conn.is_subclass(
namespace, class_obj, derived_class_obj):
derived_class_obj = class_obj

# Construct the header line
header_line = [] # list of header strings
if include_classes:
header_line.append("classname")
header_line.extend(prop_names)
for pname in prop_names:
if show_units and derived_class_obj:
prop_obj = derived_class_obj.properties[pname]
siunit = siunit_obj(prop_obj)
if siunit is not None:
hdr = "{} [{}]".format(pname, siunit)
else:
hdr = pname
else:
hdr = pname
header_line.append(hdr)

# Fold long property names
new_header_line = []
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

# Direct dependencies (except pip, setuptools, wheel):

pywbem>=0.17.0
# pywbem>=0.17.0
# Alternative to test against current github master pywbem
#git+https://github.com/pywbem/pywbem.git@master#egg=pywbem
git+https://github.com/pywbem/pywbem.git@andy/unit-support#egg=pywbem
# TODO: Upgrade to pywbem 1.1.0 once released.

six>=1.10.0
# Click 7.1 has a bug with output capturing
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/simple_assoc_mock_model.mof
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Qualifier Values : string[],
Scope(property, method, parameter),
Flavor(EnableOverride, ToSubclass, Translatable);

Qualifier PUnit : string = null,
Scope(property, method, parameter);

class TST_Person{
[Key, Description ("This is key prop")]
string name;
Expand All @@ -43,6 +46,7 @@ class TST_Person{
// This is good test of case insensitivity for class names.
class TST_Personsub : TST_Person{
string secondProperty = "empty";
[PUnit ("byte * 10^3")]
uint32 counter;
};

Expand Down

0 comments on commit ed4e93c

Please sign in to comment.