# HG changeset patch # User souliane # Date 1400571242 -7200 # Node ID 902c764a0d2bafd8b56d67c72c0ad3c67139b6b4 # Parent d732bb68b3266db2f64637930db814f610b2dd17 memory (params): fix parameters of type "list" to use the default option when no individual value is set diff -r d732bb68b326 -r 902c764a0d2b src/memory/params.py --- a/src/memory/params.py Fri May 16 11:26:46 2014 +0200 +++ b/src/memory/params.py Tue May 20 09:34:02 2014 +0200 @@ -329,6 +329,22 @@ value_to_use = value if value is not None else node.getAttribute(attr) # we use value (user defined) if it exist, else we use node's default value if node.getAttribute('type') == 'bool': return value_to_use.lower() not in ('false', '0', 'no') + elif node.getAttribute('type') == 'list': + options = [option for option in node.childNodes if option.nodeName == 'option'] + values = [option.getAttribute('value') for option in options] + if value_to_use not in values: # value_to_use is probably empty + selected = [option for option in options if option.getAttribute('selected') == 'true'] + cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name') + if len(selected) == 1: + value_to_use = selected[0].getAttribute('value') + log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") % + {'cat': cat, 'param': param, 'value': value_to_use}) + return value_to_use + if len(selected) == 0: + log.error(_('Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) + else: + log.error(_('Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) + raise exceptions.DataError return value_to_use return node.getAttribute(attr)