Commit 96b03310 authored by Ad Schellevis's avatar Ad Schellevis

(configd) add support for sequenced items in template generation

example:
	filename_[OPNsense.captiveportal.zones.zone.%.zoneid].conf

will result in file per config item, where zone is (optionally) repeating in config
parent a7033f22
......@@ -155,7 +155,10 @@ class Template(object):
if xmlNodeName in config_ptr:
config_ptr = config_ptr[xmlNodeName]
elif xmlNodeName == '%':
target_keys = config_ptr.keys()
if type(config_ptr) in (collections.OrderedDict, dict):
target_keys = config_ptr.keys()
else:
target_keys = map(lambda x: str(x), range(len(config_ptr)))
else:
break
......@@ -177,6 +180,11 @@ class Template(object):
result[tag]['.'.join(filter_target)] = xmlNodeName
config_ptr = config_ptr[xmlNodeName]
elif type(config_ptr[xmlNodeName]) in (list, tuple):
if str_wildcard_loc >= len(filter_target):
filter_target.append(xmlNodeName)
filter_target.append(target_node)
config_ptr = config_ptr[xmlNodeName][int(target_node)]
else:
# fill in node value
result[tag]['.'.join(filter_target)] = config_ptr[xmlNodeName]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment