list is Multi now which enables us to implement item access

This commit is contained in:
gwen 2012-07-12 11:44:42 +02:00
parent 1ccca60530
commit ce56100602
2 changed files with 39 additions and 15 deletions

View file

@ -25,7 +25,7 @@ from error import (HiddenOptionError, ConfigError, NotFoundError,
SpecialOwnersError, MandatoryError, MethodCallError,
DisabledOptionError, ModeOptionError)
from option import (OptionDescription, Option, SymLinkOption, group_types,
Multi, apply_requires, modes)
default_owner ,Multi, apply_requires, modes)
import autolib
from autolib import special_owners, special_owner_factory
# ____________________________________________________________
@ -34,7 +34,7 @@ class Config(object):
_cfgimpl_disabled = True
_cfgimpl_mandatory = True
_cfgimpl_frozen = False
_cfgimpl_owner = "user"
_cfgimpl_owner = default_owner
_cfgimpl_toplevel = None
_cfgimpl_mode = 'normal'
@ -66,13 +66,14 @@ class Config(object):
for child in self._cfgimpl_descr._children:
if isinstance(child, Option):
if child.is_multi():
mm = Multi(child.getdefault())
self._cfgimpl_values[child._name] = mm
self._cfgimpl_previous_values[child._name] = mm
childdef = Multi(child.getdefault(), config=self,
child=child)
self._cfgimpl_values[child._name] = childdef
self._cfgimpl_previous_values[child._name] = childdef
else:
dd = child.getdefault()
self._cfgimpl_values[child._name] = dd
self._cfgimpl_previous_values[child._name] = dd
childdef = child.getdefault()
self._cfgimpl_values[child._name] = childdef
self._cfgimpl_previous_values[child._name] = childdef
if child.getcallback() is not None:
if child._is_hidden():
self._cfgimpl_value_owners[child._name] = 'auto'

View file

@ -28,21 +28,44 @@ available_actions = ['hide', 'show', 'enable', 'disable']
reverse_actions = {'hide': 'show', 'show': 'hide',
'disable':'enable', 'enable': 'disable'}
# ____________________________________________________________
# generic owner. 'default' is the general config owner after init time
default_owner = 'user'
# OptionDescription authorized group_type values
group_types = ['default', 'family', 'group', 'master']
# multi types
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):
# FIXME test if None, etc...
return super(Multi, self).__getitem__(key)
# return list.__getitem__(self, key)
value = super(Multi, self).__getitem__(key)
if value is None:
return self.child.default_multi
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)
# ____________________________________________________________
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):
#reminder: an Option object is **not** a container for the value
_frozen = False