corrections in dynoption/masterslaves

This commit is contained in:
2018-03-24 22:37:48 +01:00
parent d5d826f967
commit 6921e05c0e
17 changed files with 115 additions and 299 deletions

View File

@ -33,7 +33,7 @@ except:
COUNT_TIME = False
COUNT_TIME = {}
#COUNT_TIME = {}
def count(func):
@ -120,9 +120,11 @@ class CommonTiramisuOption(CommonTiramisu):
def _test_slave_index(self):
option = self._get_option()
if not option.impl_is_optiondescription() and self.index is None and \
option.impl_is_master_slaves('slave'):
raise APIError('index must be set with a slave option')
if not option.impl_is_optiondescription():
if self.index is None and option.impl_is_master_slaves('slave'):
raise APIError('index must be set with a slave option')
elif self.index is not None and not option.impl_is_master_slaves('slave'):
raise APIError('index must be set only with a slave option')
def _unrestraint_not_allowed(self, force_unrestraint):
if force_unrestraint:

View File

@ -83,7 +83,7 @@ class SubConfig(object):
self._impl_length = len(value)
def cfgimpl_get_length(self):
return getattr(self, '_impl_length')
return self._impl_length
def reset_one_option_cache(self,
values,
@ -334,9 +334,6 @@ class SubConfig(object):
name,
index,
config_bag):
context = self._cfgimpl_get_context()
if '.' in name: # pragma: optional cover
self, name = self.cfgimpl_get_home_by_path(name,
config_bag)
@ -358,6 +355,12 @@ class SubConfig(object):
index,
config_bag)
elif option.impl_is_master_slaves('slave'):
length = self.cfgimpl_get_length()
if index >= length:
raise SlaveError(_('index "{}" is higher than the master length "{}" '
'for option "{}"').format(index,
length,
option.impl_get_display_name()))
values.reset_slave(subpath,
index,
config_bag)
@ -387,7 +390,6 @@ class SubConfig(object):
otherwise
"""
if '.' in name:
# raise Exception('je suis desole ...')
self, name = self.cfgimpl_get_home_by_path(name,
config_bag)
@ -425,7 +427,7 @@ class SubConfig(object):
if option.impl_is_master_slaves('slave'):
if index is None and not iter_slave:
raise IndexError(_('index is mandatory for the slave "{}"'
raise SlaveError(_('index is mandatory for the slave "{}"'
'').format(subpath))
length = self.cfgimpl_get_length()
if index is not None and index >= length:
@ -441,7 +443,7 @@ class SubConfig(object):
length,
subpath))
elif index:
raise IndexError(_('index is forbidden for the not slave "{}"'
raise SlaveError(_('index is forbidden for the not slave "{}"'
'').format(subpath))
if option.impl_is_master_slaves('slave') and index is None:
value = []
@ -649,8 +651,8 @@ class SubConfig(object):
if withoption is None and withvalue is not undefined: # pragma: optional cover
raise ValueError(_("make_dict can't filtering with value without "
"option"))
context = self._cfgimpl_get_context()
if withoption is not None:
context = self._cfgimpl_get_context()
for path in context._find(bytype=None,
byname=withoption,
byvalue=withvalue,
@ -685,7 +687,7 @@ class SubConfig(object):
fullpath=fullpath)
#withoption can be set to None below !
if withoption is None:
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag):
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag, context):
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt
path = opt.impl_getname()

View File

@ -159,7 +159,7 @@ class ValueWarning(UserWarning): # pragma: optional cover
>>> with warnings.catch_warnings(record=True) as w:
... c.s = 'val'
...
>>> w[0].message.opt == s
>>> w[0].message.opt() == s
True
>>> print(str(w[0].message))
invalid value val for option s: pouet

View File

@ -175,5 +175,5 @@ class MasterSlaves(OptionDescription):
raise SlaveError(_('cannot reduce length of the master "{}"'
'').format(option.impl_get_display_name()))
def impl_is_master_slaves(self):
def impl_is_master_slaves(self, *args, **kwargs):
return True

View File

@ -340,7 +340,7 @@ class Option(OnlyOption):
if check_error:
raise ValueError(msg)
else:
warnings.warn_explicit(ValueWarning(msg, self),
warnings.warn_explicit(ValueWarning(msg, weakref.ref(self)),
ValueWarning,
self.__class__.__name__, 0)
@ -646,7 +646,7 @@ class Option(OnlyOption):
self._display_name,
current_opt.impl_get_display_name(),
err)
warnings.warn_explicit(ValueWarning(msg, self),
warnings.warn_explicit(ValueWarning(msg, weakref.ref(self)),
ValueWarning,
self.__class__.__name__, 0)
else:

View File

@ -381,15 +381,23 @@ class OptionDescriptionWalk(CacheOptionDescription):
def impl_getchildren(self,
config_bag,
context=None,
dyn=True):
cname = None
for child in self._impl_st_getchildren():
cname = child.impl_getname()
if dyn and child.impl_is_dynoptiondescription():
if context is None:
raise ConfigError(_('need context'))
if cname is None:
if context.cfgimpl_get_description() == self:
cname = ''
else:
cname = self.impl_getpath(context)
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = child
for value in child._impl_get_suffixes(sconfig_bag):
yield SynDynOptionDescription(child,
cname + value,
cname,
value)
else:
yield child
@ -478,7 +486,7 @@ class OptionDescription(OptionDescriptionWalk):
# the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default
def impl_is_master_slaves(self):
def impl_is_master_slaves(self, *args, **kwargs):
return False
def impl_getdoc(self):

View File

@ -68,10 +68,11 @@ class SynDynOptionDescription(object):
config_bag,
dyn=True):
children = []
subpath = self.impl_getpath()
for child in self._opt.impl_getchildren(config_bag):
yield(self._opt._impl_get_dynchild(child,
self._suffix,
self._subpath))
subpath))
def impl_getpath(self):
subpath = self._subpath
@ -93,13 +94,8 @@ class SynDynOptionDescription(object):
self._suffix)
def pop(self,
values,
index,
setting_properties,
force_permissive,
slaves=undefined):
self._opt.pop(values,
index,
setting_properties,
force_permissive,
slaves=self.getslaves())
*args,
**kwargs):
self._opt.pop(*args,
slaves=self.getslaves(),
**kwargs)

View File

@ -567,7 +567,6 @@ class Settings(object):
if self._getcontext().cfgimpl_get_meta() is not None:
raise ConfigError(_('cannot change property with metaconfig'))
if path is not None and config_bag.option.impl_getrequires() is not None:
print(properties, getattr(config_bag.option, '_calc_properties', static_set))
not_allowed_props = properties & getattr(config_bag.option, '_calc_properties', static_set)
if not_allowed_props:
if len(not_allowed_props) == 1:
@ -608,7 +607,6 @@ class Settings(object):
raise ConfigError(_('cannot add this property: "{0}"').format(
' '.join(property_)))
print('add', property_)
self_properties = config_bag.properties
if self_properties is None:
index = None

View File

@ -76,7 +76,7 @@ class Values(Cache):
a specified value must be associated to an owner
"""
if DEBUG:
print('setvalue', path, value, index)
print('setvalue', path, value, owner, index, id(self))
values = []
vidx = None
@ -100,7 +100,7 @@ class Values(Cache):
if path.startswith('subod.subodval'):
raise Exception('arf ...')
if DEBUG:
print('hasvalue', path, index, has_path)
print('hasvalue', path, index, has_path, id(self))
if index is None:
return has_path
elif has_path:
@ -114,7 +114,7 @@ class Values(Cache):
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
"""
if DEBUG:
print('reduce_index', path, index)
print('reduce_index', path, index, id(self))
path_idx = self._values[0].index(path)
indexes = self._values[1][path_idx]
if index in indexes:
@ -129,7 +129,7 @@ class Values(Cache):
def resetvalue_index(self, path, index):
if DEBUG:
print('resetvalue_index', path, index)
print('resetvalue_index', path, index, id(self))
def _resetvalue(nb):
values_idx = list(values[nb])
del(values_idx[path_idx])
@ -162,7 +162,7 @@ class Values(Cache):
"""remove value means delete value in storage
"""
if DEBUG:
print('resetvalue', path)
print('resetvalue', path, id(self))
def _resetvalue(nb):
lst = list(self._values[nb])
lst.pop(idx)
@ -232,7 +232,7 @@ class Values(Cache):
if owner is undefined:
owner = default
if DEBUG:
print('getvalue', path, index, value)
print('getvalue', path, index, value, owner, id(self))
if with_value:
return owner, value
else:

View File

@ -15,7 +15,6 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ____________________________________________________________
FIXME = 0
def POUET(obj):
return(obj.__class__.__name__.lower())
@ -35,41 +34,23 @@ class Cache(object):
"""add val in cache for a specified path
if slave, add index
"""
if DEBUG:
global FIXME
FIXME += 1
print('ca set cache', path, val, POUET(self), FIXME, id(self))
#if path is not None and (path.startswith('od.st.') or path.startswith('od.dod.')):
# raise Exception('mais ... mais ... mais')
#if FIXME == 111:
# raise Exception('rah')
if DEBUG and path == 'odmaster.third':
print('ca set cache', path, val, POUET(self), id(self))
self._cache.setdefault(path, {})[index] = (val, time)
def getcache(self, path, exp, index):
value, created = self._cache[path][index]
if created is None or exp <= created:
if DEBUG:
global FIXME
FIXME += 1
print('ca trouve dans le cache', path, value, POUET(self), FIXME, id(self))
#if path is not None and (path.startswith('od.st.') or path.startswith('od.dod.')):
# raise Exception('mais ... mais ... mais')
#if FIXME == 45:
# raise Exception('rah')
if DEBUG and path == 'odmaster.third':
print('ca trouve dans le cache', path, value, POUET(self), id(self), index, exp)
return True, value
return False, None # pragma: no cover
def delcache(self, path):
"""remove cache for a specified path
"""
if DEBUG:
global FIXME
FIXME += 1
print('ca del cache', path, POUET(self), FIXME, id(self))
#if path is not None and (path.startswith('od.st.') or path.startswith('od.dod.')):
# raise Exception('mais ... mais ... mais')
#if FIXME == 23:
# raise Exception('rah')
if DEBUG and path == 'odmaster.third':
print('ca del cache', path, POUET(self), id(self))
if path in self._cache:
del self._cache[path]
@ -78,7 +59,7 @@ class Cache(object):
:param path: the path's option
"""
if DEBUG:
if DEBUG and path == 'odmaster.third':
print('ca cherche dans le cache', path, POUET(self), id(self))
return path in self._cache and index in self._cache[path]

View File

@ -601,23 +601,26 @@ class Values(object):
index,
config_bag):
context = self._getcontext()
if config_bag.validate and 'validator' in config_bag.setting_properties:
fake_context = context._gen_fake_values()
fake_value = fake_context.cfgimpl_get_values()
sconfig_bag = config_bag.copy()
sconfig_bag.validate = False
fake_value.reset_slave(path,
index,
sconfig_bag)
value = fake_value._getdefaultvalue(path,
index,
config_bag)
fake_value.setvalue_validation(path,
index,
value,
config_bag)
self._p_.resetvalue_index(path, index)
if self._p_.hasvalue(path, index=index):
context = self._getcontext()
if config_bag.validate and 'validator' in config_bag.setting_properties:
fake_context = context._gen_fake_values()
fake_value = fake_context.cfgimpl_get_values()
sconfig_bag = config_bag.copy()
sconfig_bag.validate = False
fake_value.reset_slave(path,
index,
sconfig_bag)
value = fake_value._getdefaultvalue(path,
index,
config_bag)
fake_value.setvalue_validation(path,
index,
value,
config_bag)
self._p_.resetvalue_index(path, index)
context.cfgimpl_reset_cache(opt=config_bag.option,
path=path)
def reset_master(self,
subconfig,
@ -628,6 +631,12 @@ class Values(object):
current_value = self.get_cached_value(path,
None,
config_bag)
length = len(current_value)
if index >= length:
raise IndexError(_('index "{}" is higher than the length "{}" '
'for option "{}"').format(index,
length,
config_bag.option.impl_get_display_name()))
current_value.pop(index)
self.setvalue(path,
None,
@ -638,7 +647,6 @@ class Values(object):
index,
config_bag)
def setowner_validation(self,
path,
index,
@ -709,7 +717,7 @@ class Values(object):
lenmaster = None
optmaster = None
pathmaster = None
for option in description.impl_getchildren(config_bag):
for option in description.impl_getchildren(config_bag, context):
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = option
name = option.impl_getname()