Skip to content

Commit

Permalink
added reverse value map info to codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Whiteley committed Mar 6, 2009
1 parent 98cce85 commit 7aec09d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cim_provider2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,22 @@ def is_required (obj):
return '(Required)'
return ''
#################
def build_reverse_val_map(obj):
vm = obj.qualifiers['valuemap'].value
if 'values' in obj.qualifiers:
vals = obj.qualifiers['values'].value
else:
vals = vm
tmap = zip(vals,vm)
rv = {}
for val, vm in tmap:
try:
vmi = int(vm)
except ValueError:
continue
rv[vmi] = str(val) # we want normal strings, not unicode
return rv
#################
def build_val_map(obj):
vm = obj.qualifiers['valuemap'].value
if 'values' in obj.qualifiers:
Expand Down Expand Up @@ -1140,6 +1156,11 @@ def build_val_map(obj):
return map

valuemaps = {}
rvaluemaps = pywbem.NocaseDict()

for prop in cc.properties.values():
if 'valuemap' in prop.qualifiers and 'values' in prop.qualifiers:
rvaluemaps[prop.name] = build_reverse_val_map(prop)

for obj in cc.properties.values() + cc.methods.values():
if 'valuemap' in obj.qualifiers:
Expand Down Expand Up @@ -1453,6 +1474,9 @@ class %s(object):''' % group
value = value+'_'
code+= '''
%s = %s''' % (value, vm)
if group in rvaluemaps:
code+= '''
_reverse_map = %s''' % repr(rvaluemaps[group])
for pname, vms in maps.items():
if pname == '<vms>':
continue
Expand Down

0 comments on commit 7aec09d

Please sign in to comment.