comparison src/tools/memory.py @ 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
parents 20f11097d99b
children cecd22241d56
comparison
equal deleted inserted replaced
394:8f3551ceee17 395:79fe50fc8edc
274 /!\ as noticed in doc, don't forget to unlink the minidom.Document 274 /!\ as noticed in doc, don't forget to unlink the minidom.Document
275 @param profile: profile name (not key !) 275 @param profile: profile name (not key !)
276 @return: minidom.Document of the profile xml (cf warning above) 276 @return: minidom.Document of the profile xml (cf warning above)
277 """ 277 """
278 prof_xml = minidom.parseString('<params/>') 278 prof_xml = minidom.parseString('<params/>')
279 279 cache = {}
280
280 for type_node in self.dom.documentElement.childNodes: 281 for type_node in self.dom.documentElement.childNodes:
281 if type_node.nodeName == 'general' or type_node.nodeName == 'individual': #we use all params, general and individual 282 if type_node.nodeName == 'general' or type_node.nodeName == 'individual': #we use all params, general and individual
282 for cat_node in type_node.childNodes: 283 for cat_node in type_node.childNodes:
283 if cat_node.nodeName == 'category': 284 if cat_node.nodeName == 'category':
284 category = cat_node.getAttribute('name') 285 category = cat_node.getAttribute('name')
285 cat_copy = cat_node.cloneNode(True) #we make a copy for the new xml 286 if not cache.has_key(category):
286 params = cat_copy.getElementsByTagName("param") 287 cache[category] = dest_cat = cat_node.cloneNode(True) #we make a copy for the new xml
288 new_node = True
289 else:
290 dest_cat = cache[category]
291 new_node = False #It's not a new node, we will merge information
292 params = cat_node.getElementsByTagName("param")
293 dest_params = {}
294 for node in dest_cat.childNodes:
295 if node.nodeName != "param":
296 continue
297 dest_params[node.getAttribute('name')] = node
298
287 for param_node in params: 299 for param_node in params:
288 name = param_node.getAttribute('name') 300 name = param_node.getAttribute('name')
301
302 if name not in dest_params:
303 dest_params[name] = param_node.cloneNode(True)
304 dest_cat.appendChild(dest_params[name])
305
289 profile_value = self.__getParam(profile, category, name, type_node.nodeName) 306 profile_value = self.__getParam(profile, category, name, type_node.nodeName)
290 if profile_value: #there is a value for this profile, we must change the default 307 if profile_value: #there is a value for this profile, we must change the default
291 param_node.setAttribute('value', profile_value) 308 dest_params[name].setAttribute('value', profile_value)
292 prof_xml.documentElement.appendChild(cat_copy) 309 if new_node:
310 prof_xml.documentElement.appendChild(dest_cat)
293 return prof_xml 311 return prof_xml
294 312
295 313
296 def getParamsUI(self, profile_key): 314 def getParamsUI(self, profile_key):
297 """Return a SàT XMLUI for parameters, with given profile""" 315 """Return a SàT XMLUI for parameters, with given profile"""