in builder/core/util.py [0:0]
def replace_variables(value, variables):
""" Replaces all variables in all strings that can be found in the supplied value """
key_type = type(value)
if key_type == str:
# If the whole string is a variable, just replace it
if value and value.rfind('{') == 0 and value.find('}') == len(value) - 1:
return variables.get(value[1:-1], value)
# Strings just do a format
return _formatter.format(value, **variables)
elif key_type == list:
# Update each element
return [replace_variables(e, variables) for e in value]
elif key_type == dict:
# Iterate each element and recursively apply the variables in place
for key, val in value.items():
value[key] = replace_variables(val, variables)
return value
else:
# Unsupported, just return it
return value