Mercurial > libervia-backend
changeset 395:79fe50fc8edc
memory: multiples params of the same category are now merged
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Oct 2011 23:22:13 +0200 (2011-10-04) |
parents | 8f3551ceee17 |
children | cecd22241d56 |
files | src/tools/memory.py |
diffstat | 1 files changed, 23 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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('<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