multi defaults value addition cinematics
This commit is contained in:
parent
e70054c4d4
commit
f9d6f62a70
|
@ -70,11 +70,16 @@ class Config(object):
|
|||
- settles various default values for options
|
||||
"""
|
||||
self._validate_duplicates(self._cfgimpl_descr._children)
|
||||
#max len for a master/slave group
|
||||
max_len_child = 0
|
||||
for child in self._cfgimpl_descr._children:
|
||||
if isinstance(child, Option):
|
||||
if child.is_multi():
|
||||
#force_append to load values without append value to
|
||||
#child/master
|
||||
childdef = Multi(copy(child.getdefault()), config=self,
|
||||
opt=child)
|
||||
opt=child, force_append=False)
|
||||
max_len_child = max(max_len_child, len(childdef))
|
||||
self._cfgimpl_values[child._name] = childdef
|
||||
self._cfgimpl_previous_values[child._name] = list(childdef)
|
||||
else:
|
||||
|
@ -85,7 +90,25 @@ class Config(object):
|
|||
elif isinstance(child, OptionDescription):
|
||||
self._validate_duplicates(child._children)
|
||||
self._cfgimpl_values[child._name] = Config(child, parent=self)
|
||||
# self.override(overrides)
|
||||
|
||||
try:
|
||||
master = self._cfgimpl_descr.get_master_name()
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
#if master/slave group, add default_multi value if length of valu
|
||||
#if inferior to group length
|
||||
for child in self._cfgimpl_descr._children:
|
||||
value = self._cfgimpl_values[child._name]
|
||||
if value is None:
|
||||
len_child = 0
|
||||
value = Multi([], config=self, opt=child, force_append=False)
|
||||
else:
|
||||
len_child = len(value)
|
||||
if len_child < max_len_child:
|
||||
for num in range(len_child, max_len_child):
|
||||
value._append_default()
|
||||
|
||||
|
||||
def cfgimpl_update(self):
|
||||
"""dynamically adds `Option()` or `OptionDescription()`
|
||||
|
|
|
@ -42,15 +42,17 @@ for act1, act2 in requires_actions:
|
|||
class Multi(list):
|
||||
"""multi options values container
|
||||
that support item notation for the values of multi options"""
|
||||
def __init__(self, lst, config, opt):
|
||||
def __init__(self, lst, config, opt, force_append=True):
|
||||
"""
|
||||
:lst: the Multi wraps a list value
|
||||
:param lst: the Multi wraps a list value
|
||||
:param config: the parent config
|
||||
:param opt: the option object that have this Multi value
|
||||
:param force_append: - True to append child value with master's one
|
||||
- False to force lst value
|
||||
"""
|
||||
self.config = config
|
||||
self.opt = opt
|
||||
if self.opt.is_master(config):
|
||||
if force_append and self.opt.is_master(config):
|
||||
# we pass the list at the list type's init
|
||||
# because a normal init cannot return anything
|
||||
super(Multi, self).__init__(lst)
|
||||
|
@ -61,6 +63,7 @@ class Multi(list):
|
|||
except Exception, err:
|
||||
print err
|
||||
else:
|
||||
if force_append:
|
||||
self.config._valid_len(self.opt._name, lst)
|
||||
super(Multi, self).__init__(lst)
|
||||
|
||||
|
@ -90,10 +93,13 @@ class Multi(list):
|
|||
else:
|
||||
ret = value
|
||||
else:
|
||||
default_value = multi.opt.getdefault_multi()
|
||||
multi._setvalue(default_value)
|
||||
multi._append_default()
|
||||
return ret
|
||||
|
||||
def _append_default(self):
|
||||
default_value = self.opt.getdefault_multi()
|
||||
self._setvalue(default_value)
|
||||
|
||||
def _setvalue(self, value, key=None, who=None):
|
||||
if value != None:
|
||||
if not self.opt._validate(value):
|
||||
|
|
Loading…
Reference in New Issue