settings
This commit is contained in:
@ -171,12 +171,12 @@ class TiramisuOptionOption(CommonTiramisuOption):
|
||||
return self._opt.impl_get_display_name()
|
||||
|
||||
@count
|
||||
def getdefault(self):
|
||||
return self._opt.impl_getdefault()
|
||||
def default(self):
|
||||
return self.config_bag.option.impl_getdefault()
|
||||
|
||||
@count
|
||||
def getdefaultmulti(self):
|
||||
return self._opt.impl_getdefault_multi()
|
||||
def defaultmulti(self):
|
||||
return self.config_bag.option.impl_getdefault_multi()
|
||||
|
||||
@count
|
||||
def has_dependency(self, self_is_dep=True):
|
||||
@ -263,9 +263,9 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
|
||||
@count
|
||||
def add(self, prop):
|
||||
props = self.get()
|
||||
props.add(prop)
|
||||
self.set(props)
|
||||
self.settings.addproperty(self.path,
|
||||
prop,
|
||||
self.config_bag)
|
||||
|
||||
@count
|
||||
def pop(self, prop):
|
||||
@ -277,8 +277,8 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
def reset(self):
|
||||
"""reset all personalised properties
|
||||
"""
|
||||
self.settings.reset(opt=self._opt,
|
||||
path=self._path)
|
||||
self.settings.reset(opt=self.config_bag.option,
|
||||
path=self.path)
|
||||
|
||||
|
||||
class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
@ -485,7 +485,7 @@ class TiramisuContextValue(TiramisuContext):
|
||||
return self.config_bag.config.cfgimpl_get_values().mandatory_warnings(self.config_bag)
|
||||
|
||||
@count
|
||||
def get(self):
|
||||
def get_modified(self):
|
||||
return self.config_bag.config.cfgimpl_get_values().get_modified_values()
|
||||
|
||||
|
||||
@ -538,11 +538,22 @@ class TiramisuContextProperty(TiramisuContext):
|
||||
def get(self):
|
||||
return set(self.config_bag.setting_properties)
|
||||
|
||||
@count
|
||||
def get_modified(self):
|
||||
return self.config_bag.config.cfgimpl_get_settings().get_modified_properties()
|
||||
|
||||
@count
|
||||
def set_modified(self, props):
|
||||
return self.config_bag.config.cfgimpl_get_settings().set_modified_properties(props)
|
||||
|
||||
@count
|
||||
def set(self, props):
|
||||
self.config_bag.config.cfgimpl_get_settings().set_context_properties(frozenset(props))
|
||||
self.config_bag.setting_properties = self.config_bag.config.cfgimpl_get_settings().get_context_properties()
|
||||
|
||||
def reset(self):
|
||||
self.config_bag.config.cfgimpl_get_settings().reset()
|
||||
|
||||
|
||||
class TiramisuContextPermissive(TiramisuContext):
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
from .i18n import _
|
||||
|
||||
|
||||
def display_list(lst, separator='and'):
|
||||
def display_list(lst, separator='and', add_quote=False):
|
||||
if separator == 'and':
|
||||
separator = _('and')
|
||||
elif separator == 'or':
|
||||
@ -29,7 +29,9 @@ def display_list(lst, separator='and'):
|
||||
ret = lst[0]
|
||||
if not isinstance(ret, str):
|
||||
ret = str(ret)
|
||||
return '"{}"'.format(ret)
|
||||
if add_quote:
|
||||
ret = '"{}"'.format(ret)
|
||||
return ret
|
||||
else:
|
||||
if isinstance(lst, tuple):
|
||||
lst = list(lst)
|
||||
@ -38,11 +40,15 @@ def display_list(lst, separator='and'):
|
||||
for l in lst[:-1]:
|
||||
if not isinstance(l, str):
|
||||
l = str(l)
|
||||
lst_.append('"{}"'.join(_(l)))
|
||||
if add_quote:
|
||||
l = '"{}"'.format(l)
|
||||
lst_.append(_(l))
|
||||
last = lst[-1]
|
||||
if not isinstance(last, str):
|
||||
last = str(_(last))
|
||||
return ', '.join(lst_) + _(' {} ').format(separator) + '"{}"'.format(last)
|
||||
if add_quote:
|
||||
last = '"{}"'.format(last)
|
||||
return ', '.join(lst_) + _(' {} ').format(separator) + '{}'.format(last)
|
||||
|
||||
|
||||
# Exceptions for an Option
|
||||
@ -75,7 +81,7 @@ class PropertiesOptionError(AttributeError):
|
||||
only_one = len(req) == 1
|
||||
msg = []
|
||||
for action, msg_ in req.items():
|
||||
msg.append('{0} ({1})'.format(action, display_list(msg_)))
|
||||
msg.append('"{0}" ({1})'.format(action, display_list(msg_)))
|
||||
else:
|
||||
only_one = len(self.proptype) == 1
|
||||
msg = list(self.proptype)
|
||||
|
@ -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