list is Multi now which enables us to implement item access

This commit is contained in:
gwen 2012-07-13 09:35:46 +02:00
parent 05f5b0ccbc
commit a5be1b5591
2 changed files with 14 additions and 11 deletions

View File

@ -25,9 +25,11 @@ 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,
default_owner ,Multi, apply_requires, modes) Multi, apply_requires, modes)
import autolib
from autolib import special_owners, special_owner_factory from autolib import special_owners, special_owner_factory
# ______________________________________________________________________
# generic owner. 'default' is the general config owner after init time
default_owner = 'user'
# ____________________________________________________________ # ____________________________________________________________
class Config(object): class Config(object):
_cfgimpl_hidden = True _cfgimpl_hidden = True

View File

@ -28,8 +28,6 @@ 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
@ -49,25 +47,28 @@ class Multi(list):
if value is None: if value is None:
owner = 'default' owner = 'default'
else: else:
owner = default_owner owner = self.config._cfgimpl_owner
self.child.setowner(self.config, owner) oldowner = self.child.getowner(self.config)
oldowner[key] = owner
self.child.setowner(self.config, oldowner)
if value != None and not self.child._validate(value): if value != None and not self.child._validate(value):
raise ConfigError("invalid value {0} " raise ConfigError("invalid value {0} "
"for option {1}".format(str(value), self.child._name)) "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): def append(self, value):
if value is None: if value is None:
owner = 'default' owner = 'default'
else: else:
owner = default_owner owner = self.config._cfgimpl_owner
self.child.setowner(self.config, owner) oldowner = self.child.getowner(self.config)
oldowner.append(owner)
self.child.setowner(self.config, oldowner)
# changer dans la config la valeur par défaut et le owner # changer dans la config la valeur par défaut et le owner
if value != None and not self.child._validate(value): if value != None and not self.child._validate(value):
raise ConfigError("invalid value {0} " raise ConfigError("invalid value {0} "
"for option {1}".format(str(value), self.child._name)) "for option {1}".format(str(value), self.child._name))
self.config._cfgimpl_values[child._name].append(value) super(Multi, self).append(value)
# def pop(self): # def pop(self):
# pass # pass
@ -163,7 +164,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
def getowner(self, config): def getowner(self, config):
# config *must* be only the **parent** config (not the toplevel config) # config *must* be only the **parent** config (not the toplevel config)
return config._cfgimpl_owner[self._name] return config._cfgimpl_value_owners[self._name]
def setoption(self, config, value, who): def setoption(self, config, value, who):
"who is **not necessarily** a owner because it cannot be a list" "who is **not necessarily** a owner because it cannot be a list"