memory: multiples params of the same category are now merged
This commit is contained in:
parent
1225131aec
commit
15016a7510
1 changed files with 23 additions and 5 deletions
|
|
@ -276,20 +276,38 @@ class Param():
|
|||
@return: minidom.Document of the profile xml (cf warning above)
|
||||
"""
|
||||
prof_xml = minidom.parseString('<params/>')
|
||||
|
||||
cache = {}
|
||||
|
||||
for type_node in self.dom.documentElement.childNodes:
|
||||
if type_node.nodeName == 'general' or type_node.nodeName == 'individual': #we use all params, general and individual
|
||||
for cat_node in type_node.childNodes:
|
||||
if cat_node.nodeName == 'category':
|
||||
category = cat_node.getAttribute('name')
|
||||
cat_copy = cat_node.cloneNode(True) #we make a copy for the new xml
|
||||
params = cat_copy.getElementsByTagName("param")
|
||||
if not cache.has_key(category):
|
||||
cache[category] = dest_cat = cat_node.cloneNode(True) #we make a copy for the new xml
|
||||
new_node = True
|
||||
else:
|
||||
dest_cat = cache[category]
|
||||
new_node = False #It's not a new node, we will merge information
|
||||
params = cat_node.getElementsByTagName("param")
|
||||
dest_params = {}
|
||||
for node in dest_cat.childNodes:
|
||||
if node.nodeName != "param":
|
||||
continue
|
||||
dest_params[node.getAttribute('name')] = node
|
||||
|
||||
for param_node in params:
|
||||
name = param_node.getAttribute('name')
|
||||
|
||||
if name not in dest_params:
|
||||
dest_params[name] = param_node.cloneNode(True)
|
||||
dest_cat.appendChild(dest_params[name])
|
||||
|
||||
profile_value = self.__getParam(profile, category, name, type_node.nodeName)
|
||||
if profile_value: #there is a value for this profile, we must change the default
|
||||
param_node.setAttribute('value', profile_value)
|
||||
prof_xml.documentElement.appendChild(cat_copy)
|
||||
dest_params[name].setAttribute('value', profile_value)
|
||||
if new_node:
|
||||
prof_xml.documentElement.appendChild(dest_cat)
|
||||
return prof_xml
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue