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:
|
except AttributeError:
|
||||||
owners.addowner(owner)
|
owners.addowner(owner)
|
||||||
obj_owner = getattr(owners, owner)
|
obj_owner = getattr(owners, owner)
|
||||||
self.values.setowner(self.path,
|
self.values.setowner(self.opt,
|
||||||
|
self.path,
|
||||||
obj_owner,
|
obj_owner,
|
||||||
self.index)
|
self.index)
|
||||||
|
|
||||||
|
@ -268,7 +269,8 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""reset all personalised properties
|
"""reset all personalised properties
|
||||||
"""
|
"""
|
||||||
self.settings.reset(_path=self.path)
|
self.settings.reset(opt=self.opt,
|
||||||
|
path=self.path)
|
||||||
|
|
||||||
|
|
||||||
class TiramisuOptionPermissive(CommonTiramisuOption):
|
class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||||
|
@ -296,7 +298,8 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""get permissive value for a specified path"""
|
"""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):
|
def set(self, permissive):
|
||||||
self.settings.setpermissive(self.opt,
|
self.settings.setpermissive(self.opt,
|
||||||
|
@ -514,6 +517,18 @@ class TiramisuOptionDispatcher(TiramisuContextOption):
|
||||||
index=index)
|
index=index)
|
||||||
if index is not None and not opt.impl_is_master_slaves('slave'):
|
if index is not None and not opt.impl_is_master_slaves('slave'):
|
||||||
raise APIError('index must be set only with a slave option')
|
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,
|
return TiramisuOption(opt,
|
||||||
path,
|
path,
|
||||||
index,
|
index,
|
||||||
|
|
|
@ -327,9 +327,8 @@ class SubConfig(object):
|
||||||
self)
|
self)
|
||||||
if isinstance(child, (OptionDescription, SynDynOptionDescription)):
|
if isinstance(child, (OptionDescription, SynDynOptionDescription)):
|
||||||
raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover
|
raise TypeError(_("can't assign to an OptionDescription")) # pragma: optional cover
|
||||||
elif child.impl_is_symlinkoption() and \
|
elif child.impl_is_symlinkoption():
|
||||||
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
|
raise TypeError(_("can't assign to a SymLinkOption"))
|
||||||
raise TypeError(_("can't assign to a SymlinkOption"))
|
|
||||||
else:
|
else:
|
||||||
self.cfgimpl_get_description().impl_validate_value(child,
|
self.cfgimpl_get_description().impl_validate_value(child,
|
||||||
value,
|
value,
|
||||||
|
@ -360,9 +359,8 @@ class SubConfig(object):
|
||||||
self)
|
self)
|
||||||
if isinstance(child, (OptionDescription, SynDynOptionDescription)):
|
if isinstance(child, (OptionDescription, SynDynOptionDescription)):
|
||||||
raise TypeError(_("can't delete an OptionDescription")) # pragma: optional cover
|
raise TypeError(_("can't delete an OptionDescription")) # pragma: optional cover
|
||||||
elif child.impl_is_symlinkoption() and \
|
elif child.impl_is_symlinkoption():
|
||||||
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
|
raise TypeError(_("can't delete a SymLinkOption"))
|
||||||
raise TypeError(_("can't delete a SymlinkOption"))
|
|
||||||
subpath = self._get_subpath(name)
|
subpath = self._get_subpath(name)
|
||||||
values = self.cfgimpl_get_values()
|
values = self.cfgimpl_get_values()
|
||||||
if index is not None:
|
if index is not None:
|
||||||
|
@ -420,11 +418,7 @@ class SubConfig(object):
|
||||||
option = self.cfgimpl_get_description().impl_getchild(name,
|
option = self.cfgimpl_get_description().impl_getchild(name,
|
||||||
setting_properties,
|
setting_properties,
|
||||||
self)
|
self)
|
||||||
if option.impl_is_symlinkoption() and isinstance(option, DynSymLinkOption):
|
if option.impl_is_symlinkoption():
|
||||||
# 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 returns_option is True:
|
if returns_option is True:
|
||||||
return option
|
return option
|
||||||
path = context.cfgimpl_get_description().impl_get_path_by_opt(option.impl_getopt())
|
path = context.cfgimpl_get_description().impl_get_path_by_opt(option.impl_getopt())
|
||||||
|
@ -843,21 +837,31 @@ class _CommonConfig(SubConfig):
|
||||||
if not validate_properties:
|
if not validate_properties:
|
||||||
return option
|
return option
|
||||||
else:
|
else:
|
||||||
if index is None and option.impl_is_master_slaves('slave'):
|
if option.impl_is_symlinkoption():
|
||||||
subpath = self._get_subpath(path)
|
true_option = option.impl_getopt()
|
||||||
self.cfgimpl_get_settings().validate_properties(option,
|
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,
|
subpath,
|
||||||
setting_properties,
|
setting_properties,
|
||||||
force_permissive=force_permissive)
|
force_permissive=force_permissive)
|
||||||
return option
|
return option
|
||||||
else:
|
self.getattr(path,
|
||||||
return self.getattr(path,
|
validate=validate,
|
||||||
validate=validate,
|
force_permissive=force_permissive,
|
||||||
force_permissive=force_permissive,
|
index=index,
|
||||||
index=index,
|
setting_properties=setting_properties,
|
||||||
setting_properties=setting_properties,
|
validate_properties=validate_properties,
|
||||||
validate_properties=validate_properties,
|
returns_option=True)
|
||||||
returns_option=True)
|
return option
|
||||||
|
|
||||||
def cfgimpl_get_path(self, dyn=True):
|
def cfgimpl_get_path(self, dyn=True):
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -525,7 +525,7 @@ class Option(OnlyOption):
|
||||||
if opt.impl_is_submulti():
|
if opt.impl_is_submulti():
|
||||||
raise ConfigError(_('cannot add consistency with submulti option'))
|
raise ConfigError(_('cannot add consistency with submulti option'))
|
||||||
if not isinstance(opt, 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 opt._is_subdyn():
|
||||||
if dynod is None:
|
if dynod is None:
|
||||||
raise ConfigError(_('almost one option in consistency is '
|
raise ConfigError(_('almost one option in consistency is '
|
||||||
|
|
|
@ -73,9 +73,6 @@ class SynDynOptionDescription(object):
|
||||||
subpath += '.'
|
subpath += '.'
|
||||||
return subpath + self.impl_getname()
|
return subpath + self.impl_getname()
|
||||||
|
|
||||||
def impl_getopt(self):
|
|
||||||
return self._opt
|
|
||||||
|
|
||||||
def getmaster(self):
|
def getmaster(self):
|
||||||
master = self._opt.getmaster()
|
master = self._opt.getmaster()
|
||||||
return DynSymLinkOption(master,
|
return DynSymLinkOption(master,
|
||||||
|
|
|
@ -291,6 +291,9 @@ class Settings(object):
|
||||||
apply_requires=True):
|
apply_requires=True):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
if opt.impl_is_symlinkoption():
|
||||||
|
opt = opt.impl_getopt()
|
||||||
|
path = opt.impl_getpath(self._getcontext())
|
||||||
is_cached = False
|
is_cached = False
|
||||||
|
|
||||||
if apply_requires:
|
if apply_requires:
|
||||||
|
@ -325,7 +328,8 @@ class Settings(object):
|
||||||
props = copy(props)
|
props = copy(props)
|
||||||
props |= requires
|
props |= requires
|
||||||
|
|
||||||
props -= self.getpermissive(path)
|
props -= self.getpermissive(opt,
|
||||||
|
path)
|
||||||
if apply_requires and 'cache' in setting_properties:
|
if apply_requires and 'cache' in setting_properties:
|
||||||
if 'expire' in setting_properties:
|
if 'expire' in setting_properties:
|
||||||
ntime = ntime + expires_time
|
ntime = ntime + expires_time
|
||||||
|
@ -336,14 +340,19 @@ class Settings(object):
|
||||||
return props
|
return props
|
||||||
|
|
||||||
def get_context_permissive(self):
|
def get_context_permissive(self):
|
||||||
return self.getpermissive(None)
|
return self.getpermissive(None, None)
|
||||||
|
|
||||||
def getpermissive(self,
|
def getpermissive(self,
|
||||||
|
opt,
|
||||||
path):
|
path):
|
||||||
|
if opt and opt.impl_is_symlinkoption():
|
||||||
|
opt = opt.impl_getopt()
|
||||||
|
path = opt.impl_getpath(self._getcontext())
|
||||||
meta = self._getcontext().cfgimpl_get_meta()
|
meta = self._getcontext().cfgimpl_get_meta()
|
||||||
if meta is None:
|
if meta is None:
|
||||||
return self._pp_.getpermissive(path)
|
return self._pp_.getpermissive(path)
|
||||||
return meta.cfgimpl_get_settings().getpermissive(path)
|
return meta.cfgimpl_get_settings().getpermissive(opt,
|
||||||
|
path)
|
||||||
|
|
||||||
def apply_requires(self,
|
def apply_requires(self,
|
||||||
opt,
|
opt,
|
||||||
|
@ -503,6 +512,9 @@ class Settings(object):
|
||||||
"""
|
"""
|
||||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||||
raise ConfigError(_('cannot change property with metaconfig'))
|
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
|
forbidden_properties = forbidden_set_properties & properties
|
||||||
if forbidden_properties:
|
if forbidden_properties:
|
||||||
raise ConfigError(_('cannot add those properties: {0}').format(
|
raise ConfigError(_('cannot add those properties: {0}').format(
|
||||||
|
@ -535,6 +547,9 @@ class Settings(object):
|
||||||
raise ConfigError(_('cannot change permissive with metaconfig'))
|
raise ConfigError(_('cannot change permissive with metaconfig'))
|
||||||
if not isinstance(permissives, frozenset):
|
if not isinstance(permissives, frozenset):
|
||||||
raise TypeError(_('permissive must be a 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
|
forbidden_permissives = forbidden_set_permissives & permissives
|
||||||
if forbidden_permissives:
|
if forbidden_permissives:
|
||||||
raise ConfigError(_('cannot add those permissives: {0}').format(
|
raise ConfigError(_('cannot add those permissives: {0}').format(
|
||||||
|
@ -548,21 +563,24 @@ class Settings(object):
|
||||||
|
|
||||||
def reset(self,
|
def reset(self,
|
||||||
opt=None,
|
opt=None,
|
||||||
_path=None,
|
path=None,
|
||||||
all_properties=False):
|
all_properties=False):
|
||||||
if self._getcontext().cfgimpl_get_meta() is not None:
|
if self._getcontext().cfgimpl_get_meta() is not None:
|
||||||
raise ConfigError(_('cannot change property with metaconfig'))
|
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 '
|
raise ValueError(_('opt and all_properties must not be set '
|
||||||
'together in reset'))
|
'together in reset'))
|
||||||
if all_properties:
|
if all_properties:
|
||||||
self._p_.reset_all_properties()
|
self._p_.reset_all_properties()
|
||||||
else:
|
else:
|
||||||
if opt is not None and _path is None:
|
if opt is not None and path is None:
|
||||||
_path = opt.impl_getpath(self._getcontext())
|
path = opt.impl_getpath(self._getcontext())
|
||||||
self._p_.delproperties(_path)
|
self._p_.delproperties(path)
|
||||||
self._getcontext().cfgimpl_reset_cache(opt=opt,
|
self._getcontext().cfgimpl_reset_cache(opt=opt,
|
||||||
path=_path)
|
path=path)
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
# validate properties
|
# validate properties
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from ..util import Cache
|
from ..util import Cache
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
|
#DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
class Properties(Cache):
|
class Properties(Cache):
|
||||||
__slots__ = ('_properties',)
|
__slots__ = ('_properties',)
|
||||||
|
@ -31,15 +34,24 @@ class Properties(Cache):
|
||||||
|
|
||||||
# properties
|
# properties
|
||||||
def setproperties(self, path, properties):
|
def setproperties(self, path, properties):
|
||||||
|
if DEBUG:
|
||||||
|
print('setproperties', path, properties)
|
||||||
self._properties[path] = properties
|
self._properties[path] = properties
|
||||||
|
|
||||||
def getproperties(self, path, default_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):
|
def reset_all_properties(self):
|
||||||
|
if DEBUG:
|
||||||
|
print('reset_all_properties')
|
||||||
self._properties.clear()
|
self._properties.clear()
|
||||||
|
|
||||||
def delproperties(self, path):
|
def delproperties(self, path):
|
||||||
|
if DEBUG:
|
||||||
|
print('delproperties', path)
|
||||||
if path in self._properties:
|
if path in self._properties:
|
||||||
del(self._properties[path])
|
del(self._properties[path])
|
||||||
|
|
||||||
|
@ -62,6 +74,8 @@ class Permissives(Cache):
|
||||||
super(Permissives, self).__init__(storage)
|
super(Permissives, self).__init__(storage)
|
||||||
|
|
||||||
def setpermissive(self, path, permissive):
|
def setpermissive(self, path, permissive):
|
||||||
|
if DEBUG:
|
||||||
|
print('setpermissive', path, permissive)
|
||||||
if not permissive:
|
if not permissive:
|
||||||
if path in self._permissives:
|
if path in self._permissives:
|
||||||
del self._permissives[path]
|
del self._permissives[path]
|
||||||
|
@ -69,7 +83,10 @@ class Permissives(Cache):
|
||||||
self._permissives[path] = permissive
|
self._permissives[path] = permissive
|
||||||
|
|
||||||
def getpermissive(self, path=None):
|
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):
|
def get_modified_permissives(self):
|
||||||
"""return all modified permissives in a dictionary
|
"""return all modified permissives in a dictionary
|
||||||
|
|
|
@ -20,8 +20,8 @@ from ...setting import undefined
|
||||||
from ...i18n import _
|
from ...i18n import _
|
||||||
|
|
||||||
|
|
||||||
DEBUG = True
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
#DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
class Values(Cache):
|
class Values(Cache):
|
||||||
|
|
|
@ -519,9 +519,9 @@ class Values(object):
|
||||||
was present
|
was present
|
||||||
:returns: a `setting.owners.Owner` object
|
:returns: a `setting.owners.Owner` object
|
||||||
"""
|
"""
|
||||||
if opt.impl_is_symlinkoption() and \
|
if opt.impl_is_symlinkoption():
|
||||||
not isinstance(opt, DynSymLinkOption):
|
|
||||||
opt = opt.impl_getopt()
|
opt = opt.impl_getopt()
|
||||||
|
path = opt.impl_getpath(self._getcontext())
|
||||||
return self._getowner(opt,
|
return self._getowner(opt,
|
||||||
path,
|
path,
|
||||||
setting_properties,
|
setting_properties,
|
||||||
|
@ -539,14 +539,11 @@ class Values(object):
|
||||||
index=None):
|
index=None):
|
||||||
"""get owner of an option
|
"""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()
|
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:
|
if self_properties is undefined:
|
||||||
self_properties = context.cfgimpl_get_settings().getproperties(opt,
|
self_properties = context.cfgimpl_get_settings().getproperties(opt,
|
||||||
path,
|
path,
|
||||||
|
@ -576,6 +573,7 @@ class Values(object):
|
||||||
return owner
|
return owner
|
||||||
|
|
||||||
def setowner(self,
|
def setowner(self,
|
||||||
|
opt,
|
||||||
path,
|
path,
|
||||||
owner,
|
owner,
|
||||||
index=None):
|
index=None):
|
||||||
|
@ -585,6 +583,9 @@ class Values(object):
|
||||||
:param opt: the `option.Option` object
|
:param opt: the `option.Option` object
|
||||||
:param owner: a valid owner, that is a `setting.owners.Owner` 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):
|
if not isinstance(owner, owners.Owner):
|
||||||
raise TypeError(_("invalid owner {0}").format(str(owner)))
|
raise TypeError(_("invalid owner {0}").format(str(owner)))
|
||||||
|
|
||||||
|
@ -781,8 +782,7 @@ class Values(object):
|
||||||
for path in _mandatory_warnings(opt, currpath + [name]):
|
for path in _mandatory_warnings(opt, currpath + [name]):
|
||||||
yield path
|
yield path
|
||||||
else:
|
else:
|
||||||
if opt.impl_is_symlinkoption() and \
|
if opt.impl_is_symlinkoption():
|
||||||
not isinstance(opt, DynSymLinkOption):
|
|
||||||
continue
|
continue
|
||||||
self_properties = settings.getproperties(opt,
|
self_properties = settings.getproperties(opt,
|
||||||
path,
|
path,
|
||||||
|
|
Loading…
Reference in a new issue