list is Multi now which enables us to implement item access
This commit is contained in:
parent
1ccca60530
commit
ce56100602
17
config.py
17
config.py
|
@ -25,7 +25,7 @@ from error import (HiddenOptionError, ConfigError, NotFoundError,
|
||||||
SpecialOwnersError, MandatoryError, MethodCallError,
|
SpecialOwnersError, MandatoryError, MethodCallError,
|
||||||
DisabledOptionError, ModeOptionError)
|
DisabledOptionError, ModeOptionError)
|
||||||
from option import (OptionDescription, Option, SymLinkOption, group_types,
|
from option import (OptionDescription, Option, SymLinkOption, group_types,
|
||||||
Multi, apply_requires, modes)
|
default_owner ,Multi, apply_requires, modes)
|
||||||
import autolib
|
import autolib
|
||||||
from autolib import special_owners, special_owner_factory
|
from autolib import special_owners, special_owner_factory
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
@ -34,7 +34,7 @@ class Config(object):
|
||||||
_cfgimpl_disabled = True
|
_cfgimpl_disabled = True
|
||||||
_cfgimpl_mandatory = True
|
_cfgimpl_mandatory = True
|
||||||
_cfgimpl_frozen = False
|
_cfgimpl_frozen = False
|
||||||
_cfgimpl_owner = "user"
|
_cfgimpl_owner = default_owner
|
||||||
_cfgimpl_toplevel = None
|
_cfgimpl_toplevel = None
|
||||||
_cfgimpl_mode = 'normal'
|
_cfgimpl_mode = 'normal'
|
||||||
|
|
||||||
|
@ -66,13 +66,14 @@ class Config(object):
|
||||||
for child in self._cfgimpl_descr._children:
|
for child in self._cfgimpl_descr._children:
|
||||||
if isinstance(child, Option):
|
if isinstance(child, Option):
|
||||||
if child.is_multi():
|
if child.is_multi():
|
||||||
mm = Multi(child.getdefault())
|
childdef = Multi(child.getdefault(), config=self,
|
||||||
self._cfgimpl_values[child._name] = mm
|
child=child)
|
||||||
self._cfgimpl_previous_values[child._name] = mm
|
self._cfgimpl_values[child._name] = childdef
|
||||||
|
self._cfgimpl_previous_values[child._name] = childdef
|
||||||
else:
|
else:
|
||||||
dd = child.getdefault()
|
childdef = child.getdefault()
|
||||||
self._cfgimpl_values[child._name] = dd
|
self._cfgimpl_values[child._name] = childdef
|
||||||
self._cfgimpl_previous_values[child._name] = dd
|
self._cfgimpl_previous_values[child._name] = childdef
|
||||||
if child.getcallback() is not None:
|
if child.getcallback() is not None:
|
||||||
if child._is_hidden():
|
if child._is_hidden():
|
||||||
self._cfgimpl_value_owners[child._name] = 'auto'
|
self._cfgimpl_value_owners[child._name] = 'auto'
|
||||||
|
|
37
option.py
37
option.py
|
@ -28,21 +28,44 @@ available_actions = ['hide', 'show', 'enable', 'disable']
|
||||||
reverse_actions = {'hide': 'show', 'show': 'hide',
|
reverse_actions = {'hide': 'show', 'show': 'hide',
|
||||||
'disable':'enable', 'enable': 'disable'}
|
'disable':'enable', 'enable': 'disable'}
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
# generic owner. 'default' is the general config owner after init time
|
||||||
|
default_owner = 'user'
|
||||||
# OptionDescription authorized group_type values
|
# OptionDescription authorized group_type values
|
||||||
group_types = ['default', 'family', 'group', 'master']
|
group_types = ['default', 'family', 'group', 'master']
|
||||||
# multi types
|
# multi types
|
||||||
class Multi(list):
|
class Multi(list):
|
||||||
"wrapper for list (multi) option types"
|
"container that support items for the values of list (multi) options"
|
||||||
|
def __init__(self, lst, config=None, child=None):
|
||||||
|
self.config = config
|
||||||
|
self.child = child
|
||||||
|
super(Multi, self).__init__(lst)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
# FIXME test if None, etc...
|
value = super(Multi, self).__getitem__(key)
|
||||||
return super(Multi, self).__getitem__(key)
|
if value is None:
|
||||||
# return list.__getitem__(self, key)
|
return self.child.default_multi
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
# FIXME do some stuff here
|
if value != None and not self.child._validate(value):
|
||||||
|
raise ConfigError("invalid value {0} "
|
||||||
|
"for option {1}".format(str(value), self.child._name))
|
||||||
|
# FIXME : and if value is None ???
|
||||||
return super(Multi, self).__setitem__(key, value)
|
return super(Multi, self).__setitem__(key, value)
|
||||||
# ____________________________________________________________
|
|
||||||
|
|
||||||
|
def append(self, value, owner=default_owner):
|
||||||
|
if owner is None:
|
||||||
|
owner = 'default'
|
||||||
|
self.child.setowner(self.config, owner)
|
||||||
|
# changer dans la config la valeur par défaut et le owner
|
||||||
|
if value != None and not self.child._validate(value):
|
||||||
|
raise ConfigError("invalid value {0} "
|
||||||
|
"for option {1}".format(str(value), self.child._name))
|
||||||
|
self.config._cfgimpl_values[child._name].append(value)
|
||||||
|
|
||||||
|
# def pop(self):
|
||||||
|
# pass
|
||||||
|
# ____________________________________________________________
|
||||||
|
#
|
||||||
class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
||||||
#reminder: an Option object is **not** a container for the value
|
#reminder: an Option object is **not** a container for the value
|
||||||
_frozen = False
|
_frozen = False
|
||||||
|
|
Loading…
Reference in New Issue