reorganise symlinkoption
This commit is contained in:
parent
e40a1e78a2
commit
924ac4e597
9 changed files with 636 additions and 506 deletions
File diff suppressed because it is too large
Load diff
|
@ -224,7 +224,8 @@ class TiramisuOptionOwner(CommonTiramisuOption):
|
|||
except AttributeError:
|
||||
owners.addowner(owner)
|
||||
obj_owner = getattr(owners, owner)
|
||||
self.values.setowner(self.path,
|
||||
self.values.setowner(self.opt,
|
||||
self.path,
|
||||
obj_owner,
|
||||
self.index)
|
||||
|
||||
|
@ -268,7 +269,8 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
|||
def reset(self):
|
||||
"""reset all personalised properties
|
||||
"""
|
||||
self.settings.reset(_path=self.path)
|
||||
self.settings.reset(opt=self.opt,
|
||||
path=self.path)
|
||||
|
||||
|
||||
class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
|
@ -296,7 +298,8 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
|||
|
||||
def get(self):
|
||||
"""get permissive value for a specified path"""
|
||||
return self.settings.getpermissive(self.path)
|
||||
return self.settings.getpermissive(self.opt,
|
||||
self.path)
|
||||
|
||||
def set(self, permissive):
|
||||
self.settings.setpermissive(self.opt,
|
||||
|
@ -514,6 +517,18 @@ class TiramisuOptionDispatcher(TiramisuContextOption):
|
|||
index=index)
|
||||
if index is not None and not opt.impl_is_master_slaves('slave'):
|
||||
raise APIError('index must be set only with a slave option')
|
||||
if opt.impl_is_symlinkoption():
|
||||
true_opt = opt.impl_getopt()
|
||||
true_path = true_opt.impl_getpath(self.config)
|
||||
self.config.unwrap_from_path(true_path,
|
||||
setting_properties=s_properties,
|
||||
validate=validate,
|
||||
validate_properties=validate,
|
||||
force_permissive=self.force_permissive,
|
||||
index=index)
|
||||
else:
|
||||
true_opt = None
|
||||
true_path = None
|
||||
return TiramisuOption(opt,
|
||||
path,
|
||||
index,
|
||||
|
|
|
@ -327,9 +327,8 @@ class SubConfig(object):
|
|||
self)
|
||||
if isinstance(child, (OptionDescription, SynDynOptionDescription)):
|
||||
raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover
|
||||
elif child.impl_is_symlinkoption() and \
|
||||
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
|
||||
raise TypeError(_("can't assign to a SymlinkOption"))
|
||||
elif child.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't assign to a SymLinkOption"))
|
||||
else:
|
||||
self.cfgimpl_get_description().impl_validate_value(child,
|
||||
value,
|
||||
|
@ -360,9 +359,8 @@ class SubConfig(object):
|
|||
self)
|
||||
if isinstance(child, (OptionDescription, SynDynOptionDescription)):
|
||||
raise TypeError(_("can't delete an OptionDescription")) # pragma: optional cover
|
||||
elif child.impl_is_symlinkoption() and \
|
||||
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
|
||||
raise TypeError(_("can't delete a SymlinkOption"))
|
||||
elif child.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't delete a SymLinkOption"))
|
||||
subpath = self._get_subpath(name)
|
||||
values = self.cfgimpl_get_values()
|
||||
if index is not None:
|
||||
|
@ -420,11 +418,7 @@ class SubConfig(object):
|
|||
option = self.cfgimpl_get_description().impl_getchild(name,
|
||||
setting_properties,
|
||||
self)
|
||||
if option.impl_is_symlinkoption() and isinstance(option, DynSymLinkOption):
|
||||
# FIXME peuvent-il vraiment etre le 2 ?
|
||||
# si non supprimer tout ces tests inutiles
|
||||
raise Exception('oui ca existe ...')
|
||||
if option.impl_is_symlinkoption() and not isinstance(option, DynSymLinkOption):
|
||||
if option.impl_is_symlinkoption():
|
||||
if returns_option is True:
|
||||
return option
|
||||
path = context.cfgimpl_get_description().impl_get_path_by_opt(option.impl_getopt())
|
||||
|
@ -843,21 +837,31 @@ class _CommonConfig(SubConfig):
|
|||
if not validate_properties:
|
||||
return option
|
||||
else:
|
||||
if index is None and option.impl_is_master_slaves('slave'):
|
||||
subpath = self._get_subpath(path)
|
||||
self.cfgimpl_get_settings().validate_properties(option,
|
||||
if option.impl_is_symlinkoption():
|
||||
true_option = option.impl_getopt()
|
||||
true_path = true_option.impl_getpath(self._cfgimpl_get_context())
|
||||
self, path = self.cfgimpl_get_context().cfgimpl_get_home_by_path(true_path,
|
||||
force_permissive=force_permissive,
|
||||
validate_properties=validate_properties,
|
||||
setting_properties=setting_properties)
|
||||
else:
|
||||
true_option = option
|
||||
true_path = path
|
||||
if index is None and true_option.impl_is_master_slaves('slave'):
|
||||
subpath = self._get_subpath(true_path)
|
||||
self.cfgimpl_get_settings().validate_properties(true_option,
|
||||
subpath,
|
||||
setting_properties,
|
||||
force_permissive=force_permissive)
|
||||
return option
|
||||
else:
|
||||
return self.getattr(path,
|
||||
validate=validate,
|
||||
force_permissive=force_permissive,
|
||||
index=index,
|
||||
setting_properties=setting_properties,
|
||||
validate_properties=validate_properties,
|
||||
returns_option=True)
|
||||
self.getattr(path,
|
||||
validate=validate,
|
||||
force_permissive=force_permissive,
|
||||
index=index,
|
||||
setting_properties=setting_properties,
|
||||
validate_properties=validate_properties,
|
||||
returns_option=True)
|
||||
return option
|
||||
|
||||
def cfgimpl_get_path(self, dyn=True):
|
||||
return None
|
||||
|
|
|
@ -525,7 +525,7 @@ class Option(OnlyOption):
|
|||
if opt.impl_is_submulti():
|
||||
raise ConfigError(_('cannot add consistency with submulti option'))
|
||||
if not isinstance(opt, Option):
|
||||
raise ConfigError(_('consistency must be set with an option'))
|
||||
raise ConfigError(_('consistency must be set with an option, not {}').format(opt))
|
||||
if opt._is_subdyn():
|
||||
if dynod is None:
|
||||
raise ConfigError(_('almost one option in consistency is '
|
||||
|
|
|
@ -73,9 +73,6 @@ class SynDynOptionDescription(object):
|
|||
subpath += '.'
|
||||
return subpath + self.impl_getname()
|
||||
|
||||
def impl_getopt(self):
|
||||
return self._opt
|
||||
|
||||
def getmaster(self):
|
||||
master = self._opt.getmaster()
|
||||
return DynSymLinkOption(master,
|
||||
|
|
|
@ -291,6 +291,9 @@ class Settings(object):
|
|||
apply_requires=True):
|
||||
"""
|
||||
"""
|
||||
if opt.impl_is_symlinkoption():
|
||||
opt = opt.impl_getopt()
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
is_cached = False
|
||||
|
||||
if apply_requires:
|
||||
|
@ -325,7 +328,8 @@ class Settings(object):
|
|||
props = copy(props)
|
||||
props |= requires
|
||||
|
||||
props -= self.getpermissive(path)
|
||||
props -= self.getpermissive(opt,
|
||||
path)
|
||||
if apply_requires and 'cache' in setting_properties:
|
||||
if 'expire' in setting_properties:
|
||||
ntime = ntime + expires_time
|
||||
|
@ -336,14 +340,19 @@ class Settings(object):
|
|||
return props
|
||||
|
||||
def get_context_permissive(self):
|
||||
return self.getpermissive(None)
|
||||
return self.getpermissive(None, None)
|
||||
|
||||
def getpermissive(self,
|
||||
opt,
|
||||
path):
|
||||
if opt and opt.impl_is_symlinkoption():
|
||||
opt = opt.impl_getopt()
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
meta = self._getcontext().cfgimpl_get_meta()
|
||||
if meta is None:
|
||||
return self._pp_.getpermissive(path)
|
||||
return meta.cfgimpl_get_settings().getpermissive(path)
|
||||
return meta.cfgimpl_get_settings().getpermissive(opt,
|
||||
path)
|
||||
|
||||
def apply_requires(self,
|
||||
opt,
|
||||
|
@ -503,6 +512,9 @@ class Settings(object):
|
|||
"""
|
||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||
raise ConfigError(_('cannot change property with metaconfig'))
|
||||
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(
|
||||
|
@ -535,6 +547,9 @@ class Settings(object):
|
|||
raise ConfigError(_('cannot change permissive with metaconfig'))
|
||||
if not isinstance(permissives, frozenset):
|
||||
raise TypeError(_('permissive must be a frozenset'))
|
||||
if opt and opt.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't assign permissive to the SymLinkOption \"{}\""
|
||||
"").format(opt.impl_get_display_name()))
|
||||
forbidden_permissives = forbidden_set_permissives & permissives
|
||||
if forbidden_permissives:
|
||||
raise ConfigError(_('cannot add those permissives: {0}').format(
|
||||
|
@ -548,21 +563,24 @@ class Settings(object):
|
|||
|
||||
def reset(self,
|
||||
opt=None,
|
||||
_path=None,
|
||||
path=None,
|
||||
all_properties=False):
|
||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||
raise ConfigError(_('cannot change property with metaconfig'))
|
||||
if all_properties and (_path or opt): # pragma: optional cover
|
||||
if opt and opt.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't reset properties to the SymLinkOption \"{}\""
|
||||
"").format(opt.impl_get_display_name()))
|
||||
if all_properties and (path or opt): # pragma: optional cover
|
||||
raise ValueError(_('opt and all_properties must not be set '
|
||||
'together in reset'))
|
||||
if all_properties:
|
||||
self._p_.reset_all_properties()
|
||||
else:
|
||||
if opt is not None and _path is None:
|
||||
_path = opt.impl_getpath(self._getcontext())
|
||||
self._p_.delproperties(_path)
|
||||
if opt is not None and path is None:
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
self._p_.delproperties(path)
|
||||
self._getcontext().cfgimpl_reset_cache(opt=opt,
|
||||
path=_path)
|
||||
path=path)
|
||||
|
||||
#____________________________________________________________
|
||||
# validate properties
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
from copy import copy
|
||||
from ..util import Cache
|
||||
|
||||
DEBUG = False
|
||||
#DEBUG = True
|
||||
|
||||
|
||||
class Properties(Cache):
|
||||
__slots__ = ('_properties',)
|
||||
|
@ -31,15 +34,24 @@ class Properties(Cache):
|
|||
|
||||
# properties
|
||||
def setproperties(self, path, properties):
|
||||
if DEBUG:
|
||||
print('setproperties', path, properties)
|
||||
self._properties[path] = properties
|
||||
|
||||
def getproperties(self, path, default_properties):
|
||||
return self._properties.get(path, frozenset(default_properties))
|
||||
ret = self._properties.get(path, frozenset(default_properties))
|
||||
if DEBUG:
|
||||
print('getproperties', path, ret)
|
||||
return ret
|
||||
|
||||
def reset_all_properties(self):
|
||||
if DEBUG:
|
||||
print('reset_all_properties')
|
||||
self._properties.clear()
|
||||
|
||||
def delproperties(self, path):
|
||||
if DEBUG:
|
||||
print('delproperties', path)
|
||||
if path in self._properties:
|
||||
del(self._properties[path])
|
||||
|
||||
|
@ -62,6 +74,8 @@ class Permissives(Cache):
|
|||
super(Permissives, self).__init__(storage)
|
||||
|
||||
def setpermissive(self, path, permissive):
|
||||
if DEBUG:
|
||||
print('setpermissive', path, permissive)
|
||||
if not permissive:
|
||||
if path in self._permissives:
|
||||
del self._permissives[path]
|
||||
|
@ -69,7 +83,10 @@ class Permissives(Cache):
|
|||
self._permissives[path] = permissive
|
||||
|
||||
def getpermissive(self, path=None):
|
||||
return self._permissives.get(path, frozenset())
|
||||
ret = self._permissives.get(path, frozenset())
|
||||
if DEBUG:
|
||||
print('getpermissive', path, ret)
|
||||
return ret
|
||||
|
||||
def get_modified_permissives(self):
|
||||
"""return all modified permissives in a dictionary
|
||||
|
|
|
@ -20,8 +20,8 @@ from ...setting import undefined
|
|||
from ...i18n import _
|
||||
|
||||
|
||||
DEBUG = True
|
||||
DEBUG = False
|
||||
#DEBUG = True
|
||||
|
||||
|
||||
class Values(Cache):
|
||||
|
|
|
@ -519,9 +519,9 @@ class Values(object):
|
|||
was present
|
||||
:returns: a `setting.owners.Owner` object
|
||||
"""
|
||||
if opt.impl_is_symlinkoption() and \
|
||||
not isinstance(opt, DynSymLinkOption):
|
||||
if opt.impl_is_symlinkoption():
|
||||
opt = opt.impl_getopt()
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
return self._getowner(opt,
|
||||
path,
|
||||
setting_properties,
|
||||
|
@ -539,14 +539,11 @@ class Values(object):
|
|||
index=None):
|
||||
"""get owner of an option
|
||||
"""
|
||||
#FIXME: validate_meta ne marche que si == False ou undefined !
|
||||
if validate_meta is not False and validate_meta is not undefined:
|
||||
raise Exception('poeut')
|
||||
#if not isinstance(opt, Option) and not isinstance(opt,
|
||||
# DynSymLinkOption):
|
||||
# raise ConfigError(_('owner only avalaible for an option'))
|
||||
#FIXME pas defaut fait ??
|
||||
context = self._getcontext()
|
||||
if opt.impl_is_symlinkoption():
|
||||
opt = opt.impl_getopt()
|
||||
path = opt.impl_getpath(context)
|
||||
#FIXME pas deja fait ??
|
||||
if self_properties is undefined:
|
||||
self_properties = context.cfgimpl_get_settings().getproperties(opt,
|
||||
path,
|
||||
|
@ -576,6 +573,7 @@ class Values(object):
|
|||
return owner
|
||||
|
||||
def setowner(self,
|
||||
opt,
|
||||
path,
|
||||
owner,
|
||||
index=None):
|
||||
|
@ -585,6 +583,9 @@ class Values(object):
|
|||
:param opt: the `option.Option` object
|
||||
:param owner: a valid owner, that is a `setting.owners.Owner` object
|
||||
"""
|
||||
if opt.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't set owner for the SymLinkOption \"{}\""
|
||||
"").format(opt.impl_get_display_name()))
|
||||
if not isinstance(owner, owners.Owner):
|
||||
raise TypeError(_("invalid owner {0}").format(str(owner)))
|
||||
|
||||
|
@ -781,8 +782,7 @@ class Values(object):
|
|||
for path in _mandatory_warnings(opt, currpath + [name]):
|
||||
yield path
|
||||
else:
|
||||
if opt.impl_is_symlinkoption() and \
|
||||
not isinstance(opt, DynSymLinkOption):
|
||||
if opt.impl_is_symlinkoption():
|
||||
continue
|
||||
self_properties = settings.getproperties(opt,
|
||||
path,
|
||||
|
|
Loading…
Reference in a new issue