summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2019-02-07 11:08:15 -0600
committerMatthew Barth <msbarth@us.ibm.com>2019-02-07 12:21:28 -0600
commitf0dd3b5a3c6c54b4f38844b573e3f157f8064088 (patch)
treeb6bfa10f9e05ca5585a1d27c6901db96b84e0c52
parentbed15f0cee4784acdf151cca14efdfb98cb9d397 (diff)
downloadsdbusplus-f0dd3b5a3c6c54b4f38844b573e3f157f8064088.tar.gz
sdbusplus-f0dd3b5a3c6c54b4f38844b573e3f157f8064088.zip
Support default string values
For properties of type string, allow a default value to be set for the property on the interface. This provides the ability to have a default value to an intended free-form string instead of using enumerated values. Tested: Verified generated interface object initializes a string property to a default value Only properties of type string with a default defined are initialized with the given default value as a string Change-Id: I1e75dff1c26a4a872e9e3e7959106470c32c9be7 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r--tools/sdbusplus/property.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index 83d9f3a..661bce4 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -11,11 +11,15 @@ class Property(NamedElement, Renderer):
self.flags = kwargs.pop('flags', [])
self.errors = kwargs.pop('errors', [])
- # Convert True/False to 'true'/'false'
- # because it will be rendered as C++ code
- if (self.defaultValue is not None and
- isinstance(self.defaultValue, bool)):
- self.defaultValue = 'true' if self.defaultValue else 'false'
+ if (self.defaultValue is not None):
+ if (isinstance(self.defaultValue, bool)):
+ # Convert True/False to 'true'/'false'
+ # because it will be rendered as C++ code
+ self.defaultValue = 'true' if self.defaultValue else 'false'
+ elif(isinstance(self.defaultValue, str) and
+ self.typeName.lower() == "string"):
+ # Wrap string type default values with double-quotes
+ self.defaultValue = "\"" + self.defaultValue + "\""
super(Property, self).__init__(**kwargs)
OpenPOWER on IntegriCloud