Support properties of type string
Properties used within set speed events may be of type string to trigger
an action. These should be handled where the defined type attribute is
given as 'std::string' and a parsed value is an instance of python str
type.
Resolves openbmc/openbmc#292
Change-Id: Ib188e7abc212062a1c61950abaa28434a4726521
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py
index c071aea..1568137 100755
--- a/control/gen-fan-zone-defs.py
+++ b/control/gen-fan-zone-defs.py
@@ -243,6 +243,7 @@
"""
Converts a list of dictionary entries to a std::map initialization list.
"""
+ listOfDict = listOfDict.replace('\'', '\"')
listOfDict = listOfDict.replace('[', '{')
listOfDict = listOfDict.replace(']', '}')
listOfDict = listOfDict.replace(':', ',')
@@ -285,9 +286,15 @@
param += "),"
param += "}"
elif p == 'property':
- param += (
- str(edata['property']['type']).lower() +
- ">(" + str(eActions[p]).lower() + ")")
+ if isinstance(eActions[p], str) or \
+ "string" in str(edata['property']['type']).lower():
+ param += (
+ str(edata['property']['type']).lower() +
+ ">(\"" + str(eActions[p]) + "\")")
+ else:
+ param += (
+ str(edata['property']['type']).lower() +
+ ">(" + str(eActions[p]).lower() + ")")
else:
# Default type to 'size_t' when not given
param += ("size_t>(" + str(eActions[p]).lower() + ")")
@@ -301,7 +308,13 @@
else:
param += (str(eActions[p]['type']).lower() + ">(")
if p != 'map':
- param += str(eActions[p]['value']).lower() + ")"
+ if isinstance(eActions[p]['value'], str) or \
+ "string" in str(eActions[p]['type']).lower():
+ param += \
+ "\"" + str(eActions[p]['value']) + "\")"
+ else:
+ param += \
+ str(eActions[p]['value']).lower() + ")"
else:
param += (
str(eActions[p]['type']).lower() +
@@ -458,7 +471,11 @@
members['interface'] = grp['interface']
members['property'] = grp['property']['name']
members['type'] = grp['property']['type']
- members['value'] = grp['property']['value']
+ if isinstance(grp['property']['value'], str) or \
+ "string" in str(members['type']).lower():
+ members['value'] = "\"" + grp['property']['value'] + "\""
+ else:
+ members['value'] = grp['property']['value']
group.append(members)
precond['pcgrp'] = group
@@ -484,8 +501,13 @@
str(pcgrp['interface']) + "\",\"" +
str(pcgrp['property']) + "\"," +
"static_cast<" +
- str(pcgrp['type']).lower() + ">" +
- "(" + str(pcgrp['value']).lower() + ")}")
+ str(pcgrp['type']).lower() + ">")
+ if isinstance(pcgrp['value'], str) or \
+ "string" in str(pcgrp['type']).lower():
+ value['value'] += ("(" + str(pcgrp['value']) + ")}")
+ else:
+ value['value'] += \
+ ("(" + str(pcgrp['value']).lower() + ")}")
values.append(value)
param['values'] = values
params.append(param)