Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
commit c2c033dc7e9bcd65b89bb1eb19b933fc347144dc Author: Peter Hatina phatina@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 67c21c1..7f9f19c 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 f97b831..6420e8a 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 LMIBaseObject import LMIBaseObject from LMIUtil import lmi_cast_to_lmi @@ -33,20 +35,33 @@ class LMIConstantValues(LMIBaseObject): __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
cura-tools-devel@lists.fedorahosted.org