remove _setoption in SymLinkOption

objimpl_ => optimpl_
ConflictConfigError => ConflictError
add read_write/read_only/getowner in Config
This commit is contained in:
2013-04-22 09:19:05 +02:00
parent 682d9fe207
commit e883e5b89e
16 changed files with 355 additions and 419 deletions

View File

@ -51,7 +51,7 @@ def carry_out_calculation(name, config, callback, callback_params):
if check_disabled:
continue
raise PropertiesOptionError(err, err.proptype)
is_multi = opt.is_multi()
is_multi = opt.optimpl_is_multi()
if is_multi:
if opt_value is not None:
len_value = len(opt_value)

View File

@ -62,6 +62,9 @@ class SubConfig(object):
def cfgimpl_get_description(self):
return self._cfgimpl_descr
def cfgimpl_reset_cache(self, only_expired=False, only=('values', 'settings')):
self.cfgimpl_get_context().cfgimpl_reset_cache(only_expired, only)
# ____________________________________________________________
# attribute methods
def __setattr__(self, name, value):
@ -72,19 +75,18 @@ class SubConfig(object):
return
self._setattr(name, value)
def cfgimpl_reset_cache(self, only_expired=False, only=('values', 'settings')):
self.cfgimpl_get_context().cfgimpl_reset_cache(only_expired, only)
def _setattr(self, name, value, force_permissive=False):
if '.' in name:
homeconfig, name = self.cfgimpl_get_home_by_path(name)
return homeconfig.__setattr__(name, value)
child = getattr(self._cfgimpl_descr, name)
if type(child) != SymLinkOption:
if not isinstance(child, SymLinkOption):
self.cfgimpl_get_values().setitem(child, value,
force_permissive=force_permissive)
else:
child._setoption(self.cfgimpl_get_context(), value)
context = self.cfgimpl_get_context()
path = context.cfgimpl_get_description().optimpl_get_path_by_opt(child._opt)
context._setattr(path, value, force_permissive=force_permissive)
def __delattr__(self, name):
child = getattr(self._cfgimpl_descr, name)
@ -117,11 +119,11 @@ class SubConfig(object):
opt_or_descr = getattr(self.cfgimpl_get_description(), name)
# symlink options
if isinstance(opt_or_descr, SymLinkOption):
rootconfig = self.cfgimpl_get_context()
path = rootconfig.cfgimpl_get_description().objimpl_get_path_by_opt(opt_or_descr.opt)
return rootconfig._getattr(path, validate=validate,
force_properties=force_properties,
force_permissive=force_permissive)
context = self.cfgimpl_get_context()
path = context.cfgimpl_get_description().optimpl_get_path_by_opt(opt_or_descr._opt)
return context._getattr(path, validate=validate,
force_properties=force_properties,
force_permissive=force_permissive)
elif isinstance(opt_or_descr, OptionDescription):
self.cfgimpl_get_settings().validate_properties(opt_or_descr,
True, False,
@ -144,14 +146,14 @@ class SubConfig(object):
return self, path[-1]
def __hash__(self):
return hash(self.cfgimpl_get_description().objimpl_getkey(self))
return hash(self.cfgimpl_get_description().optimpl_getkey(self))
def __eq__(self, other):
"Config comparison"
if not isinstance(other, Config):
return False
return self.cfgimpl_get_description().objimpl_getkey(self) == \
other.cfgimpl_get_description().objimpl_getkey(other)
return self.cfgimpl_get_description().optimpl_getkey(self) == \
other.cfgimpl_get_description().optimpl_getkey(other)
def __ne__(self, other):
"Config comparison"
@ -163,7 +165,7 @@ class SubConfig(object):
def __iter__(self):
"""Pythonesque way of parsing group's ordered options.
iteration only on Options (not OptionDescriptions)"""
for child in self.cfgimpl_get_description().objimpl_getchildren():
for child in self.cfgimpl_get_description().optimpl_getchildren():
if not isinstance(child, OptionDescription):
try:
yield child._name, getattr(self, child._name)
@ -175,7 +177,7 @@ class SubConfig(object):
def iter_all(self):
"""A way of parsing options **and** groups.
iteration on Options and OptionDescriptions."""
for child in self.cfgimpl_get_description().objimpl_getchildren():
for child in self.cfgimpl_get_description().optimpl_getchildren():
try:
yield child._name, getattr(self, child._name)
except GeneratorExit:
@ -196,11 +198,11 @@ class SubConfig(object):
if group_type is not None:
if not isinstance(group_type, groups.GroupType):
raise TypeError(_("unknown group_type: {0}").format(group_type))
for child in self.cfgimpl_get_description().objimpl_getchildren():
for child in self.cfgimpl_get_description().optimpl_getchildren():
if isinstance(child, OptionDescription):
try:
if group_type is None or (group_type is not None and
child.objimpl_get_group_type() == group_type):
child.optimpl_get_group_type() == group_type):
yield child._name, getattr(self, child._name)
except GeneratorExit:
raise StopIteration
@ -225,7 +227,7 @@ class SubConfig(object):
def cfgimpl_get_path(self):
descr = self.cfgimpl_get_description()
context_descr = self.cfgimpl_get_context().cfgimpl_get_description()
return context_descr.objimpl_get_path_by_opt(descr)
return context_descr.optimpl_get_path_by_opt(descr)
def find(self, bytype=None, byname=None, byvalue=None, type_='option'):
"""
@ -272,7 +274,7 @@ class SubConfig(object):
type_='path',
_subpath=mypath):
path = '.'.join(path.split('.')[:-1])
opt = self.cfgimpl_get_context().cfgimpl_get_description().objimpl_get_opt_by_path(path)
opt = self.cfgimpl_get_context().cfgimpl_get_description().optimpl_get_opt_by_path(path)
if mypath is not None:
if mypath == path:
withoption = None
@ -287,7 +289,7 @@ class SubConfig(object):
self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
#withoption can be set to None below !
if withoption is None:
for opt in self.cfgimpl_get_description().objimpl_getchildren():
for opt in self.cfgimpl_get_description().optimpl_getchildren():
path = opt._name
self._make_sub_dict(opt, path, pathsvalues, _currpath, flatten)
if _currpath == []:
@ -330,7 +332,17 @@ class Config(SubConfig):
self._cfgimpl_build_all_paths()
def _cfgimpl_build_all_paths(self):
self._cfgimpl_descr.objimpl_build_cache()
self._cfgimpl_descr.optimpl_build_cache()
def read_only(self):
self.cfgimpl_get_settings().read_only()
def read_write(self):
self.cfgimpl_get_settings().read_write()
def getowner(self, path):
opt = self.cfgimpl_get_description().optimpl_get_opt_by_path(path)
return self.cfgimpl_get_values().getowner(opt)
def cfgimpl_reset_cache(self, only_expired=False, only=('values', 'settings')):
if 'values' in only:
@ -446,7 +458,7 @@ def mandatory_warnings(config):
"""
#if value in cache, properties are not calculated
config.cfgimpl_reset_cache(only=('values',))
for path in config.cfgimpl_get_description().objimpl_getpaths(include_groups=True):
for path in config.cfgimpl_get_description().optimpl_getpaths(include_groups=True):
try:
config._getattr(path, force_properties=('mandatory',))
except PropertiesOptionError, err:

View File

@ -22,9 +22,8 @@
#ValueError if function's parameter not correct
# or if not logical
# or if validation falied
# or if validation failled
# or multi must be a list
# or error with multi length
#TypeError if parameter has no good type
#AttributeError if no option or optiondescription in optiondescription (also when specified a path)
@ -44,7 +43,7 @@ class ConfigError(StandardError):
pass
class ConflictConfigError(ConfigError):
class ConflictError(StandardError):
"duplicate config"
pass

View File

@ -25,13 +25,14 @@ from copy import copy
from types import FunctionType
from IPy import IP
from tiramisu.error import ConflictConfigError
from tiramisu.error import ConflictError
from tiramisu.setting import groups, multitypes
from tiramisu.i18n import _
name_regexp = re.compile(r'^\d+')
forbidden_names = ['iter_all', 'iter_group', 'find', 'find_fisrt',
'make_dict', 'unwrap_from_path']
'make_dict', 'unwrap_from_path', 'read_only',
'read_write', 'getowner']
def valid_name(name):
@ -41,7 +42,7 @@ def valid_name(name):
return False
if re.match(name_regexp, name) is None and not name.startswith('_') \
and name not in forbidden_names \
and not name.startswith('objimpl_') and \
and not name.startswith('optimpl_') and \
not name.startswith('cfgimpl_'):
return True
else:
@ -53,7 +54,7 @@ def valid_name(name):
class BaseInformation(object):
__slots__ = ('_informations')
def objimpl_set_information(self, key, value):
def optimpl_set_information(self, key, value):
"""updates the information's attribute
(wich is a dictionnary)
@ -62,7 +63,7 @@ class BaseInformation(object):
"""
self._informations[key] = value
def objimpl_get_information(self, key, default=None):
def optimpl_get_information(self, key, default=None):
"""retrieves one information's item
:param key: the item string (ex: "help")
@ -111,7 +112,7 @@ class Option(BaseInformation):
raise ValueError(_("invalid name: {0} for option").format(name))
self._name = name
self._informations = {}
self.objimpl_set_information('doc', doc)
self.optimpl_set_information('doc', doc)
validate_requires_arg(requires, self._name)
self._requires = requires
self._multi = multi
@ -152,14 +153,14 @@ class Option(BaseInformation):
# raise ValidateError("invalid default value {0} "
# "for option {1} : not list type"
# "".format(str(default), name))
if not self.objimpl_validate(default):
if not self.optimpl_validate(default):
raise ValueError(_("invalid default value {0} "
"for option {1}"
"").format(str(default), name))
self._multitype = multitypes.default
self._default_multi = default_multi
else:
if default is not None and not self.objimpl_validate(default):
if default is not None and not self.optimpl_validate(default):
raise ValueError(_("invalid default value {0} "
"for option {1}").format(str(default), name))
self._default = default
@ -170,7 +171,7 @@ class Option(BaseInformation):
' must be a tuple').format(type(properties), self._name))
self._properties = properties # 'hidden', 'disabled'...
def objimpl_validate(self, value, context=None, validate=True):
def optimpl_validate(self, value, context=None, validate=True):
"""
:param value: the option's value
:param validate: if true enables ``self._validator`` validation
@ -210,48 +211,48 @@ class Option(BaseInformation):
return False
return True
def objimpl_getdefault(self, default_multi=False):
def optimpl_getdefault(self, default_multi=False):
"accessing the default value"
if not default_multi or not self.objimpl_is_multi():
if not default_multi or not self.optimpl_is_multi():
return self._default
else:
return self.getdefault_multi()
def objimpl_getdefault_multi(self):
def optimpl_getdefault_multi(self):
"accessing the default value for a multi"
return self._default_multi
def objimpl_get_multitype(self):
def optimpl_get_multitype(self):
return self._multitype
def objimpl_get_master_slaves(self):
def optimpl_get_master_slaves(self):
return self._master_slaves
def objimpl_is_empty_by_default(self):
def optimpl_is_empty_by_default(self):
"no default value has been set yet"
if ((not self.objimpl_is_multi() and self._default is None) or
(self.objimpl_is_multi() and (self._default == [] or None in self._default))):
if ((not self.optimpl_is_multi() and self._default is None) or
(self.optimpl_is_multi() and (self._default == [] or None in self._default))):
return True
return False
def objimpl_getdoc(self):
def optimpl_getdoc(self):
"accesses the Option's doc"
return self.objimpl_get_information('doc')
return self.optimpl_get_information('doc')
def objimpl_has_callback(self):
def optimpl_has_callback(self):
"to know if a callback has been defined or not"
if self._callback is None:
return False
else:
return True
def objimpl_getkey(self, value):
def optimpl_getkey(self, value):
return value
def objimpl_is_multi(self):
def optimpl_is_multi(self):
return self._multi
def objimpl_add_consistency(self, func, opts):
def optimpl_add_consistency(self, func, opts):
pass
if self._consistencies is None:
self._consistencies = []
@ -266,7 +267,7 @@ class Option(BaseInformation):
descr = context.cfgimpl_get_description()
for opt_ in opts:
if opt_ is not opt:
path = descr.objimpl_get_path_by_opt(opt_)
path = descr.optimpl_get_path_by_opt(opt_)
val = context._getattr(path, validate=False)
if val is not None:
if val in values:
@ -364,12 +365,8 @@ class SymLinkOption(object):
self._name = name
self._opt = opt
def _setoption(self, context, value):
path = context.cfgimpl_get_description().objimpl_get_path_by_opt(self._opt)
setattr(context, path, value)
def __getattr__(self, name):
if name in ('_name', '_opt', '_setoption', '_consistencies'):
if name in ('_name', '_opt', '_consistencies'):
return object.__gettattr__(self, name)
else:
return getattr(self._opt, name)
@ -379,17 +376,25 @@ class IPOption(Option):
__slots__ = ('_opt_type', '_only_private')
_opt_type = 'ip'
def objimpl_set_private(self):
self._only_private = True
def __init__(self, name, doc, default=None, default_multi=None,
requires=None, multi=False, callback=None,
callback_params=None, validator=None, validator_args=None,
properties=None, only_private=False):
super(IPOption, self).__init__(name, doc, default=default,
default_multi=default_multi,
callback=callback,
callback_params=callback_params,
requires=requires,
multi=multi,
validator=validator,
validator_args=validator_args,
properties=properties)
self._only_private = only_private
def _validate(self, value):
try:
only_private = self._only_private
except AttributeError:
only_private = False
try:
ip = IP('{0}/32'.format(value))
if only_private:
if self._only_private:
return ip.iptype() == 'PRIVATE'
return True
except ValueError:
@ -457,17 +462,17 @@ class NetmaskOption(Option):
descr = context.cfgimpl_get_description()
if opt is opt_ipnetwork:
val_ipnetwork = value
path = descr.objimpl_get_path_by_opt(opt_netmask)
path = descr.optimpl_get_path_by_opt(opt_netmask)
val_netmask = context._getattr(path, validate=False)
if opt_netmask.objimpl_is_multi():
if opt_netmask.optimpl_is_multi():
val_netmask = val_netmask[index]
if val_netmask is None:
return True
else:
val_netmask = value
path = descr.objimpl_get_path_by_opt(opt_ipnetwork)
path = descr.optimpl_get_path_by_opt(opt_ipnetwork)
val_ipnetwork = getattr(context, path)
if opt_ipnetwork.objimpl_is_multi():
if opt_ipnetwork.optimpl_is_multi():
val_ipnetwork = val_ipnetwork[index]
if val_ipnetwork is None:
return True
@ -540,7 +545,7 @@ class OptionDescription(BaseInformation):
raise ValueError(_("invalid name: {0} for option descr").format(name))
self._name = name
self._informations = {}
self.objimpl_set_information('doc', doc)
self.optimpl_set_information('doc', doc)
child_names = [child._name for child in children]
#better performance like this
valid_child = copy(child_names)
@ -548,8 +553,8 @@ class OptionDescription(BaseInformation):
old = None
for child in valid_child:
if child == old:
raise ConflictConfigError(_('duplicate option name: '
'{0}').format(child))
raise ConflictError(_('duplicate option name: '
'{0}').format(child))
old = child
self._children = (tuple(child_names), tuple(children))
validate_requires_arg(requires, self._name)
@ -563,8 +568,8 @@ class OptionDescription(BaseInformation):
# the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default
def objimpl_getdoc(self):
return self.objimpl_get_information('doc')
def optimpl_getdoc(self):
return self.optimpl_get_information('doc')
def __getattr__(self, name):
try:
@ -573,32 +578,32 @@ class OptionDescription(BaseInformation):
raise AttributeError(_('unknown Option {} in OptionDescription {}'
'').format(name, self._name))
def objimpl_getkey(self, config):
return tuple([child.objimpl_getkey(getattr(config, child._name))
for child in self.objimpl_getchildren()])
def optimpl_getkey(self, config):
return tuple([child.optimpl_getkey(getattr(config, child._name))
for child in self.optimpl_getchildren()])
def objimpl_getpaths(self, include_groups=False, _currpath=None):
def optimpl_getpaths(self, include_groups=False, _currpath=None):
"""returns a list of all paths in self, recursively
_currpath should not be provided (helps with recursion)
"""
if _currpath is None:
_currpath = []
paths = []
for option in self.objimpl_getchildren():
for option in self.optimpl_getchildren():
attr = option._name
if isinstance(option, OptionDescription):
if include_groups:
paths.append('.'.join(_currpath + [attr]))
paths += option.objimpl_getpaths(include_groups=include_groups,
paths += option.optimpl_getpaths(include_groups=include_groups,
_currpath=_currpath + [attr])
else:
paths.append('.'.join(_currpath + [attr]))
return paths
def objimpl_getchildren(self):
def optimpl_getchildren(self):
return self._children[1]
def objimpl_build_cache(self, cache_path=None, cache_option=None, _currpath=None, _consistencies=None):
def optimpl_build_cache(self, cache_path=None, cache_option=None, _currpath=None, _consistencies=None):
if _currpath is None and self._cache_paths is not None:
return
if _currpath is None:
@ -610,7 +615,7 @@ class OptionDescription(BaseInformation):
if cache_path is None:
cache_path = [self._name]
cache_option = [self]
for option in self.objimpl_getchildren():
for option in self.optimpl_getchildren():
attr = option._name
if attr.startswith('_cfgimpl'):
continue
@ -624,7 +629,7 @@ class OptionDescription(BaseInformation):
_consistencies.setdefault(opt, []).append((func, opts))
else:
_currpath.append(attr)
option.objimpl_build_cache(cache_path, cache_option, _currpath, _consistencies)
option.optimpl_build_cache(cache_path, cache_option, _currpath, _consistencies)
_currpath.pop()
if save:
#valid no duplicated option
@ -633,26 +638,26 @@ class OptionDescription(BaseInformation):
old = None
for child in valid_child:
if child == old:
raise ConflictConfigError(_('duplicate option: '
'{0}').format(child))
raise ConflictError(_('duplicate option: '
'{0}').format(child))
old = child
self._cache_paths = (tuple(cache_option), tuple(cache_path))
self._consistencies = _consistencies
def obgimpl_get_opt_by_path(self, path):
def optimpl_get_opt_by_path(self, path):
try:
return self._cache_paths[0][self._cache_paths[1].index(path)]
except ValueError:
raise AttributeError(_('no option for path {}').format(path))
def objimpl_get_path_by_opt(self, opt):
def optimpl_get_path_by_opt(self, opt):
try:
return self._cache_paths[1][self._cache_paths[0].index(opt)]
except ValueError:
raise AttributeError(_('no option {} found').format(opt))
# ____________________________________________________________
def objimpl_set_group_type(self, group_type):
def optimpl_set_group_type(self, group_type):
"""sets a given group object to an OptionDescription
:param group_type: an instance of `GroupType` or `MasterGroupType`
@ -669,11 +674,11 @@ class OptionDescription(BaseInformation):
#for collect all slaves
slaves = []
master = None
for child in self.objimpl_getchildren():
for child in self.optimpl_getchildren():
if isinstance(child, OptionDescription):
raise ValueError(_("master group {} shall not have "
"a subgroup").format(self._name))
if not child.objimpl_is_multi():
if not child.optimpl_is_multi():
raise ValueError(_("not allowed option {0} in group {1}"
": this option is not a multi"
"").format(child._name, self._name))
@ -687,7 +692,7 @@ class OptionDescription(BaseInformation):
raise ValueError(_('master group with wrong master name for {}'
'').format(self._name))
master._master_slaves = tuple(slaves)
for child in self.objimpl_getchildren():
for child in self.optimpl_getchildren():
if child != master:
child._master_slaves = master
child._multitype = multitypes.slave
@ -697,7 +702,7 @@ class OptionDescription(BaseInformation):
else:
raise ValueError(_('not allowed group_type : {0}').format(group_type))
def objimpl_get_group_type(self):
def optimpl_get_group_type(self):
return self._group_type
def _valid_consistency(self, opt, value, context, index):

View File

@ -166,6 +166,9 @@ class Property(object):
def __contains__(self, propname):
return propname in self._properties
def __repr__(self):
return str(self._properties)
#____________________________________________________________
class Setting(object):
@ -188,6 +191,9 @@ class Setting(object):
def __contains__(self, propname):
return propname in self._get_properties()
def __repr__(self):
return str(self._get_properties())
def __getitem__(self, opt):
return Property(self, self._get_properties(opt), opt)
@ -281,8 +287,8 @@ class Setting(object):
properties.append('mandatory')
if self._validate_frozen(opt_or_descr, value, is_write):
properties.append('frozen')
raise_text = _('cannot change the value to {0} for '
'option {1} this option is frozen')
raise_text = _('cannot change the value for '
'option {0} this option is frozen')
if properties != []:
raise PropertiesOptionError(raise_text.format(opt_or_descr._name,
str(properties)),
@ -353,7 +359,7 @@ def apply_requires(opt, config):
settings = config.cfgimpl_get_settings()
setting = Property(settings, settings._get_properties(opt, False), opt)
trigger_actions = build_actions(opt._requires)
optpath = config.cfgimpl_get_context().cfgimpl_get_description().objimpl_get_path_by_opt(opt)
optpath = config.cfgimpl_get_context().cfgimpl_get_description().optimpl_get_path_by_opt(opt)
for requires in trigger_actions.values():
matches = False
for require in requires:

View File

@ -43,8 +43,8 @@ class Values(object):
"return value or default value if not set"
#if no value
if opt not in self._values:
value = opt.objimpl_getdefault()
if opt.objimpl_is_multi():
value = opt.optimpl_getdefault()
if opt.optimpl_is_multi():
value = Multi(value, self.context, opt)
else:
#if value
@ -62,11 +62,11 @@ class Values(object):
def _is_empty(self, opt, value):
"convenience method to know if an option is empty"
empty = opt._empty
if (not opt.objimpl_is_multi() and (value is None or value == empty)) or \
(opt.objimpl_is_multi() and (value == [] or
if (not opt.optimpl_is_multi() and (value is None or value == empty)) or \
(opt.optimpl_is_multi() and (value == [] or
None in value or empty in value)):
return True
if self.is_default_owner(opt) and opt.objimpl_is_empty_by_default():
if self.is_default_owner(opt) and opt.optimpl_is_empty_by_default():
return True
return False
@ -97,7 +97,7 @@ class Values(object):
setting = self.context.cfgimpl_get_settings()
value = self._get_value(opt)
is_frozen = 'frozen' in setting[opt]
if opt.objimpl_has_callback():
if opt.optimpl_has_callback():
#if value is set and :
# - not frozen
# - frozen and not force_default_on_freeze
@ -107,16 +107,16 @@ class Values(object):
pass
else:
value = self._getcallback_value(opt)
if opt.objimpl_is_multi():
if opt.optimpl_is_multi():
value = Multi(value, self.context, opt)
#suppress value if already set
self._reset(opt)
# frozen and force default
elif is_frozen and 'force_default_on_freeze' in setting[opt]:
value = opt.objimpl_getdefault()
if opt.objimpl_is_multi():
value = opt.optimpl_getdefault()
if opt.optimpl_is_multi():
value = Multi(value, self.context, opt)
if validate and not opt.objimpl_validate(value, self.context, 'validator' in setting):
if validate and not opt.optimpl_validate(value, self.context, 'validator' in setting):
raise ValueError(_('invalid calculated value returned'
' for option {0}: {1}').format(opt._name, value))
if self.is_default_owner(opt) and \
@ -135,11 +135,11 @@ class Values(object):
def _setitem(self, opt, value, force_permissive=False, force_properties=None):
#valid opt
if not opt.objimpl_validate(value, self.context,
if not opt.optimpl_validate(value, self.context,
'validator' in self.context.cfgimpl_get_settings()):
raise ValueError(_('invalid value {}'
' for option {}').format(value, opt._name))
if opt.objimpl_is_multi() and not isinstance(value, Multi):
if opt.optimpl_is_multi() and not isinstance(value, Multi):
value = Multi(value, self.context, opt)
self._setvalue(opt, value, force_permissive=force_permissive,
force_properties=force_properties)
@ -208,16 +208,16 @@ class Multi(list):
self.context = context
if not isinstance(value, list):
value = [value]
if self.opt.objimpl_get_multitype() == multitypes.slave:
if self.opt.optimpl_get_multitype() == multitypes.slave:
value = self._valid_slave(value)
elif self.opt.objimpl_get_multitype() == multitypes.master:
elif self.opt.optimpl_get_multitype() == multitypes.master:
self._valid_master(value)
super(Multi, self).__init__(value)
def _valid_slave(self, value):
#if slave, had values until master's one
masterp = self.context.cfgimpl_get_description().objimpl_get_path_by_opt(
self.opt.objimpl_get_master_slaves())
masterp = self.context.cfgimpl_get_description().optimpl_get_path_by_opt(
self.opt.optimpl_get_master_slaves())
mastervalue = getattr(self.context, masterp)
masterlen = len(mastervalue)
if len(value) > masterlen or (len(value) < masterlen and
@ -227,7 +227,7 @@ class Multi(list):
self.opt._name, masterp))
elif len(value) < masterlen:
for num in range(0, masterlen - len(value)):
value.append(self.opt.objimpl_getdefault_multi())
value.append(self.opt.optimpl_getdefault_multi())
#else: same len so do nothing
return value
@ -244,7 +244,7 @@ class Multi(list):
self.opt._name, slave._name))
elif len(value_slave) < masterlen:
for num in range(0, masterlen - len(value_slave)):
value_slave.append(slave.objimpl_getdefault_multi(), force=True)
value_slave.append(slave.optimpl_getdefault_multi(), force=True)
def __setitem__(self, key, value):
self._validate(value)
@ -257,14 +257,14 @@ class Multi(list):
only if the option is a master
"""
if not force:
if self.opt.objimpl_get_multitype() == multitypes.slave:
if self.opt.optimpl_get_multitype() == multitypes.slave:
raise SlaveError(_("cannot append a value on a multi option {0}"
" which is a slave").format(self.opt._name))
elif self.opt.objimpl_get_multitype() == multitypes.master:
for slave in self.opt.objimpl_get_master_slaves():
elif self.opt.optimpl_get_multitype() == multitypes.master:
for slave in self.opt.optimpl_get_master_slaves():
values = self.context.cfgimpl_get_values()
if not values.is_default_owner(slave):
values[slave].append(slave.objimpl_getdefault_multi(),
values[slave].append(slave.optimpl_getdefault_multi(),
force=True)
self._validate(value)
#assume not checking mandatory property
@ -285,11 +285,11 @@ class Multi(list):
:return: the requested element
"""
if not force:
if self.opt.objimpl_get_multitype() == multitypes.slave:
if self.opt.optimpl_get_multitype() == multitypes.slave:
raise SlaveError(_("cannot pop a value on a multi option {0}"
" which is a slave").format(self.opt._name))
elif self.opt.objimpl_get_multitype() == multitypes.master:
for slave in self.opt.objimpl_get_master_slaves():
elif self.opt.optimpl_get_multitype() == multitypes.master:
for slave in self.opt.optimpl_get_master_slaves():
self.context.cfgimpl_get_values()[slave].pop(key, force=True)
self.context.cfgimpl_get_values()._setvalue(self.opt, self)
return super(Multi, self).pop(key)