list is Multi now which enables us to implement item access
This commit is contained in:
parent
736a1c77b6
commit
1ccca60530
12
config.py
12
config.py
|
@ -25,7 +25,7 @@ from error import (HiddenOptionError, ConfigError, NotFoundError,
|
|||
SpecialOwnersError, MandatoryError, MethodCallError,
|
||||
DisabledOptionError, ModeOptionError)
|
||||
from option import (OptionDescription, Option, SymLinkOption, group_types,
|
||||
apply_requires, modes)
|
||||
Multi, apply_requires, modes)
|
||||
import autolib
|
||||
from autolib import special_owners, special_owner_factory
|
||||
# ____________________________________________________________
|
||||
|
@ -65,8 +65,14 @@ class Config(object):
|
|||
self._validate_duplicates(self._cfgimpl_descr._children)
|
||||
for child in self._cfgimpl_descr._children:
|
||||
if isinstance(child, Option):
|
||||
self._cfgimpl_values[child._name] = child.getdefault()
|
||||
self._cfgimpl_previous_values[child._name] = child.getdefault()
|
||||
if child.is_multi():
|
||||
mm = Multi(child.getdefault())
|
||||
self._cfgimpl_values[child._name] = mm
|
||||
self._cfgimpl_previous_values[child._name] = mm
|
||||
else:
|
||||
dd = child.getdefault()
|
||||
self._cfgimpl_values[child._name] = dd
|
||||
self._cfgimpl_previous_values[child._name] = dd
|
||||
if child.getcallback() is not None:
|
||||
if child._is_hidden():
|
||||
self._cfgimpl_value_owners[child._name] = 'auto'
|
||||
|
|
16
option.py
16
option.py
|
@ -30,7 +30,19 @@ reverse_actions = {'hide': 'show', 'show': 'hide',
|
|||
# ____________________________________________________________
|
||||
# OptionDescription authorized group_type values
|
||||
group_types = ['default', 'family', 'group', 'master']
|
||||
# multi types
|
||||
class Multi(list):
|
||||
"wrapper for list (multi) option types"
|
||||
def __getitem__(self, key):
|
||||
# FIXME test if None, etc...
|
||||
return super(Multi, self).__getitem__(key)
|
||||
# return list.__getitem__(self, key)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
# FIXME do some stuff here
|
||||
return super(Multi, self).__setitem__(key, value)
|
||||
# ____________________________________________________________
|
||||
|
||||
class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
||||
#reminder: an Option object is **not** a container for the value
|
||||
_frozen = False
|
||||
|
@ -65,7 +77,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
|||
if self.multi == True:
|
||||
if default == None:
|
||||
default = []
|
||||
if type(default) != list or not self.validate(default):
|
||||
if not isinstance(default, list) or not self.validate(default):
|
||||
raise ConfigError("invalid default value {0} "
|
||||
"for option {1} : not list type".format(str(default), name))
|
||||
else:
|
||||
|
@ -80,7 +92,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
|||
if value != None:
|
||||
return self._validate(value)
|
||||
else:
|
||||
if type(value) != list:
|
||||
if not isinstance(value, list):
|
||||
raise ConfigError("invalid value {0} "
|
||||
"for option {1} which must be a list".format(value,
|
||||
self._name))
|
||||
|
|
2
tool.py
2
tool.py
|
@ -36,7 +36,7 @@ def reverse_from_paths(data):
|
|||
}
|
||||
def option_factory(name, value):
|
||||
"dummy -> Option('dummy')"
|
||||
if type(value) == list:
|
||||
if isinstance(value, list):
|
||||
return _build_map[type(value[0])](name, '', multi=True, default=value)
|
||||
else:
|
||||
return _build_map[type(value)](name, '', default=value)
|
||||
|
|
Loading…
Reference in New Issue