Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branches: master,openlmi-tools-lmiwbem
---------------------------------------------------------------
commit 65d720fa243eedd0f43f0b96c5f22964f6bfb22c
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Mar 6 14:16:04 2014 +0100
fix inverse constant values
---------------------------------------------------------------
cli/lmi/shell/LMIClass.py | 2 +-
cli/lmi/shell/LMIConstantValues.py | 33 ++++++++++++++++++++++++---------
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/cli/lmi/shell/LMIClass.py b/cli/lmi/shell/LMIClass.py
index f8a0a69..730fddc 100644
--- a/cli/lmi/shell/LMIClass.py
+++ b/cli/lmi/shell/LMIClass.py
@@ -133,7 +133,7 @@ class LMIClass(LMIWrapperBaseObject):
self._namespace.name, LocalOnly=False)
# Store the constant values as a list. This can consume some time, if computed on
demand.
self._valuemap_properties_list = [k for (k, v) in
self._cim_class.properties.iteritems() \
- if "ValueMap" in v.qualifiers]
+ if "ValueMap" in v.qualifiers and "Values" in
v.qualifiers]
# NOTE: usage with Key=something, Value=something is deprecated
# NOTE: inst_filter is either None or dict
diff --git a/cli/lmi/shell/LMIConstantValues.py b/cli/lmi/shell/LMIConstantValues.py
index 93fe796..f2550f4 100644
--- a/cli/lmi/shell/LMIConstantValues.py
+++ b/cli/lmi/shell/LMIConstantValues.py
@@ -14,7 +14,9 @@
# along with this program; if not, see <
http://www.gnu.org/licenses/>.
import abc
+import logging
import sys
+import re
from LMIUtil import lmi_cast_to_lmi
@@ -32,20 +34,33 @@ class LMIConstantValues(object):
__metaclass__ = abc.ABCMeta
def __init__(self, cim_obj, cast_type):
- # Keys can contain various undesirable characters, such as python
- # operators, etc. So we drop them.
- keys = map(lambda v: "".join(c for c in v if c.isalnum()),
- cim_obj.qualifiers["Values"].value)
- values = cim_obj.qualifiers["ValueMap"].value
+ logger = logging.getLogger(__name__)
+ items = zip(
+ cim_obj.qualifiers["Values"].value,
+ cim_obj.qualifiers["ValueMap"].value)
self._value_map = {}
self._value_map_inv = {}
self._cast_type = cast_type
# Fill two dictionaries for bidirectional access to constant values.
- for i in range(0, len(keys)):
+ cnt = 1
+ for (key, value) in items:
try:
- key = keys[i]
- val = lmi_cast_to_lmi(self._cast_type, values[i])
- self._value_map[key] = val
+ # Cast constant value first. If we get ValueError, no key
+ # modifications are necessary.
+ val = lmi_cast_to_lmi(self._cast_type, value)
+
+ # Keys can contain various undesirable characters, such as
+ # python operators, etc. So we drop them.
+ mod_key = re.sub("\W", "", key)
+ if mod_key[0].isdigit():
+ mod_key = "Key_" + mod_key
+ if mod_key in self._value_map:
+ mod_key += str(cnt)
+ cnt += 1
+ logger.warn("Constant value mapped as: '%s' ->
'%s'" % (key, mod_key))
+
+ self._value_map[mod_key] = val
+ # For inverse mapping, we use unmodified key.
self._value_map_inv[val] = key
except ValueError, e:
# Can not cast such value as interval. Can be found in