Extract default property value calc into function
Make a function out of the python code that calculates the default value
of a property so that it can be used in multiple places.
An upcoming commit will also use it if it has problems restoring the
property from its backing file.
Change-Id: I22b0f1130e7dce8c4b83e9111ad0d4895637404e
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/settings_manager.mako.hpp b/settings_manager.mako.hpp
index 367c8aa..dbfc536 100644
--- a/settings_manager.mako.hpp
+++ b/settings_manager.mako.hpp
@@ -20,6 +20,21 @@
path = path[1:]
path = path.replace('/', '::')
return path
+
+def get_default_value(object, interface, prop):
+ default_value = None
+ for item in settingsDict[object]:
+ if item['Interface'] == interface:
+ default_value = item['Properties'][prop]['Default']
+ break
+
+ if isinstance(default_value, str) and not \
+ default_value.startswith('"') and '::' in default_value:
+ ns = get_setting_sdbusplus_type(interface)
+ i = ns.rfind('::')
+ default_value = "{}::{}".format(ns[:i], default_value)
+
+ return default_value
%>\
#pragma once
@@ -310,14 +325,7 @@
% for item in settingsDict[path]:
% for propName, metaDict in item['Properties'].items():
<% p = NamedElement(name=propName).camelCase %>\
-<% defaultValue = metaDict['Default'] %>\
-% if isinstance(defaultValue, str) and not \
- defaultValue.startswith('"') and '::' in defaultValue:
-<% ns = get_setting_sdbusplus_type(item['Interface'])
-i = ns.rfind('::')
-defaultValue = "{}::{}".format(ns[:i], defaultValue)
-%>\
-% endif
+<% defaultValue = get_default_value(path, item['Interface'], propName) %>\
std::get<${index}>(settings)->
${get_setting_sdbusplus_type(item['Interface'])}::${p}(${defaultValue});
% endfor