settings
This commit is contained in:
@ -106,7 +106,7 @@ rw_append = set(['frozen', 'disabled', 'validator', 'hidden'])
|
||||
rw_remove = set(['permissive', 'everything_frozen', 'mandatory', 'empty'])
|
||||
|
||||
|
||||
forbidden_set_properties = frozenset(['force_store_value'])
|
||||
FORBIDDEN_SET_PROPERTIES = frozenset(['force_store_value'])
|
||||
forbidden_set_permissives = frozenset(['frozen', 'force_default_on_freeze'])
|
||||
|
||||
|
||||
@ -368,14 +368,13 @@ class Settings(object):
|
||||
path,
|
||||
index,
|
||||
config_bag)
|
||||
requires = self.apply_requires(path,
|
||||
index,
|
||||
False,
|
||||
config_bag)
|
||||
#FIXME devrait etre un frozenset!
|
||||
if requires != set([]):
|
||||
props = copy(props)
|
||||
props |= requires
|
||||
props |= self.apply_requires(path,
|
||||
index,
|
||||
False,
|
||||
config_bag)
|
||||
#if requires != set([]):
|
||||
# props = copy(props)
|
||||
# props |= requires
|
||||
|
||||
props -= self.getpermissive(opt,
|
||||
path)
|
||||
@ -525,16 +524,16 @@ class Settings(object):
|
||||
if operator != 'and':
|
||||
if debug:
|
||||
if isinstance(orig_value, PropertiesOptionError):
|
||||
for msg in orig_value.cfgimpl_get_settings().apply_requires(**orig_value._datas).values():
|
||||
for msg in orig_value._settings.apply_requires(**orig_value._datas).values():
|
||||
calc_properties.setdefault(action, []).extend(msg)
|
||||
else:
|
||||
if not inverse:
|
||||
msg = _('the value of "{0}" is "{1}"')
|
||||
msg = _('the value of "{0}" is {1}')
|
||||
else:
|
||||
msg = _('the value of "{0}" is not "{1}"')
|
||||
msg = _('the value of "{0}" is not {1}')
|
||||
calc_properties.setdefault(action, []).append(
|
||||
msg.format(option.impl_get_display_name(),
|
||||
display_list(expected, 'or')))
|
||||
display_list(expected, 'or', add_quote=True)))
|
||||
else:
|
||||
calc_properties.add(action)
|
||||
breaked = True
|
||||
@ -560,7 +559,8 @@ class Settings(object):
|
||||
def setproperties(self,
|
||||
path,
|
||||
properties,
|
||||
config_bag):
|
||||
config_bag,
|
||||
force=False):
|
||||
"""save properties for specified path
|
||||
(never save properties if same has option properties)
|
||||
"""
|
||||
@ -573,10 +573,11 @@ class Settings(object):
|
||||
if opt and opt.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't assign properties to the SymLinkOption \"{}\""
|
||||
"").format(opt.impl_get_display_name()))
|
||||
forbidden_properties = forbidden_set_properties & properties
|
||||
if forbidden_properties:
|
||||
raise ConfigError(_('cannot add those properties: {0}').format(
|
||||
' '.join(forbidden_properties)))
|
||||
if not force:
|
||||
forbidden_properties = FORBIDDEN_SET_PROPERTIES & properties
|
||||
if forbidden_properties:
|
||||
raise ConfigError(_('cannot add those properties: {0}').format(
|
||||
' '.join(forbidden_properties)))
|
||||
if not isinstance(properties, frozenset):
|
||||
raise TypeError(_('properties must be a frozenset'))
|
||||
self._p_.setproperties(path,
|
||||
@ -585,6 +586,22 @@ class Settings(object):
|
||||
self._getcontext().cfgimpl_reset_cache(opt=opt,
|
||||
path=path)
|
||||
|
||||
def addproperty(self,
|
||||
path,
|
||||
property_,
|
||||
config_bag):
|
||||
if property_ in FORBIDDEN_SET_PROPERTIES:
|
||||
raise ConfigError(_('cannot add this property: "{0}"').format(
|
||||
' '.join(property_)))
|
||||
|
||||
props = self.getproperties(path,
|
||||
None,
|
||||
config_bag)
|
||||
self.setproperties(path,
|
||||
props | {property_},
|
||||
config_bag,
|
||||
force=True)
|
||||
|
||||
def set_context_permissive(self, permissive):
|
||||
self.setpermissive(None, None, permissive)
|
||||
|
||||
@ -665,20 +682,6 @@ class Settings(object):
|
||||
config_bag.properties = self_properties
|
||||
properties = self_properties & config_bag.setting_properties - {'frozen', 'mandatory', 'empty'}
|
||||
if not opt.impl_is_optiondescription():
|
||||
##mandatory
|
||||
#if 'mandatory' in properties or 'empty' in properties:
|
||||
# value = self._getcontext().cfgimpl_get_values().get_cached_value(path,
|
||||
# index,
|
||||
# config_bag)
|
||||
# sconfig_bag = config_bag.copy()
|
||||
# sconfig_bag.properties = properties
|
||||
# if not self.validate_mandatory(index,
|
||||
# value,
|
||||
# sconfig_bag):
|
||||
# properties -= set(['mandatory'])
|
||||
# else:
|
||||
# properties |= set(['mandatory'])
|
||||
# properties -= set(['empty'])
|
||||
opt_type = 'option'
|
||||
else:
|
||||
opt_type = 'optiondescription'
|
||||
@ -764,6 +767,9 @@ class Settings(object):
|
||||
def get_modified_properties(self):
|
||||
return self._p_.get_modified_properties()
|
||||
|
||||
def set_modified_properties(self, props):
|
||||
return self._p_.set_modified_properties(props)
|
||||
|
||||
def get_modified_permissives(self):
|
||||
return self._pp_.get_modified_permissives()
|
||||
|
||||
|
Reference in New Issue
Block a user