# HG changeset patch # User Goffi # Date 1317763333 -7200 # Node ID 79fe50fc8edc6580de067c5130a0575feefa61aa # Parent 8f3551ceee17493881143549136287d7f2af22dd memory: multiples params of the same category are now merged diff -r 8f3551ceee17 -r 79fe50fc8edc src/tools/memory.py --- a/src/tools/memory.py Mon Oct 03 18:05:15 2011 +0200 +++ b/src/tools/memory.py Tue Oct 04 23:22:13 2011 +0200 @@ -276,20 +276,38 @@ @return: minidom.Document of the profile xml (cf warning above) """ prof_xml = minidom.parseString('') - + 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