reset for pathconfig
This commit is contained in:
@ -451,20 +451,6 @@ class _TiramisuOptionValueMaster:
|
||||
return self._length
|
||||
|
||||
|
||||
class _TiramisuOptionValueMeta:
|
||||
def reset(self,
|
||||
itself: bool=True,
|
||||
children: bool=False):
|
||||
"""Reset value"""
|
||||
if children:
|
||||
config_bag = self._option_bag.config_bag
|
||||
config_bag.context.reset(self._option_bag.path,
|
||||
config_bag)
|
||||
if itself:
|
||||
self._test_slave_index()
|
||||
self._subconfig.delattr(self._option_bag)
|
||||
|
||||
|
||||
class _TiramisuOptionValueGroup:
|
||||
def reset(self):
|
||||
"""Reset value"""
|
||||
@ -537,9 +523,6 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
types.append(_TiramisuOptionValueMaster)
|
||||
elif option.impl_is_master_slaves('slave'):
|
||||
types.append(_TiramisuOptionValueSlave)
|
||||
if option_bag.config_bag.context.impl_type in ('meta', 'path'):
|
||||
# only if not an optiondescription
|
||||
types.insert(0, _TiramisuOptionValueMeta)
|
||||
if option_bag.config_bag.context.impl_type == 'group':
|
||||
types.append(_TiramisuOptionValueGroup)
|
||||
new_type_dict = {'_allow_optiondescription': cls._allow_optiondescription,
|
||||
@ -795,10 +778,18 @@ class TiramisuContextValue(TiramisuContext):
|
||||
if force_dont_change_value is not undefined:
|
||||
kwargs['force_dont_change_value'] = force_dont_change_value
|
||||
return self._config_bag.context.set_value(path,
|
||||
index,
|
||||
value,
|
||||
self._config_bag,
|
||||
**kwargs)
|
||||
index,
|
||||
value,
|
||||
self._config_bag,
|
||||
**kwargs)
|
||||
|
||||
def reset(self,
|
||||
path: str,
|
||||
only_children: bool=False):
|
||||
"""Reset value"""
|
||||
self._config_bag.context.reset(path,
|
||||
only_children,
|
||||
self._config_bag)
|
||||
|
||||
def dict(self,
|
||||
flatten=False,
|
||||
|
@ -244,15 +244,18 @@ class SubConfig(object):
|
||||
_commit)
|
||||
|
||||
def delattr(self,
|
||||
option_bag):
|
||||
option_bag,
|
||||
_commit=True):
|
||||
option = option_bag.option
|
||||
if option.impl_is_symlinkoption():
|
||||
raise TypeError(_("can't delete a SymLinkOption"))
|
||||
values = self.cfgimpl_get_values()
|
||||
if option_bag.index is not None:
|
||||
values.reset_slave(option_bag)
|
||||
values.reset_slave(option_bag,
|
||||
_commit)
|
||||
else:
|
||||
values.reset(option_bag)
|
||||
values.reset(option_bag,
|
||||
_commit)
|
||||
|
||||
def _get_subpath(self, name):
|
||||
if self._impl_path is None:
|
||||
@ -827,9 +830,10 @@ class KernelGroupConfig(_CommonConfig):
|
||||
"""
|
||||
ret = []
|
||||
if self.impl_type == 'group':
|
||||
# No value so cannot commit only one time
|
||||
commit = True
|
||||
else:
|
||||
#Commit only one time
|
||||
# Commit only one time
|
||||
commit = False
|
||||
for child in self._impl_children:
|
||||
cconfig_bag = config_bag.copy()
|
||||
@ -928,7 +932,8 @@ class KernelGroupConfig(_CommonConfig):
|
||||
return self._impl_name
|
||||
|
||||
def reset(self,
|
||||
path):
|
||||
path,
|
||||
_commit=True):
|
||||
for child in self._impl_children:
|
||||
config_bag = ConfigBag(child)
|
||||
config_bag.remove_validation()
|
||||
@ -944,7 +949,7 @@ class KernelGroupConfig(_CommonConfig):
|
||||
config_bag)
|
||||
option_bag.config_bag.context = child
|
||||
child.cfgimpl_get_values().reset(option_bag,
|
||||
_commit=True)
|
||||
_commit=_commit)
|
||||
|
||||
def getconfig(self,
|
||||
name):
|
||||
@ -1015,42 +1020,56 @@ class KernelPathConfig(KernelGroupConfig):
|
||||
only_config=only_config,
|
||||
_commit=_commit)
|
||||
ret = []
|
||||
subconfig, name = self.cfgimpl_get_home_by_path(path,
|
||||
config_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
config_bag,
|
||||
self.cfgimpl_get_path())
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
path,
|
||||
index,
|
||||
config_bag)
|
||||
if force_default or force_default_if_same or force_dont_change_value:
|
||||
if force_default and force_dont_change_value:
|
||||
raise ValueError(_('force_default and force_dont_change_value'
|
||||
' cannot be set together'))
|
||||
#opt = self.cfgimpl_get_description().impl_get_opt_by_path(path,
|
||||
# config_bag)
|
||||
for child in self._impl_children:
|
||||
cconfig_bag = config_bag.copy()
|
||||
cconfig_bag.context = child
|
||||
try:
|
||||
subconfig, name = child.cfgimpl_get_home_by_path(path,
|
||||
cconfig_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
cconfig_bag,
|
||||
child.cfgimpl_get_path())
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
path,
|
||||
index,
|
||||
cconfig_bag)
|
||||
if self.impl_type == 'meta':
|
||||
moption_bag = option_bag
|
||||
del moption_bag.properties
|
||||
del moption_bag.permissives
|
||||
moption_bag.config_bag = cconfig_bag
|
||||
else:
|
||||
subconfig, name = child.cfgimpl_get_home_by_path(path,
|
||||
cconfig_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
cconfig_bag,
|
||||
child.cfgimpl_get_path())
|
||||
moption_bag = OptionBag()
|
||||
moption_bag.set_option(option,
|
||||
path,
|
||||
index,
|
||||
cconfig_bag)
|
||||
if force_default_if_same:
|
||||
if not child.cfgimpl_get_values()._p_.hasvalue(path):
|
||||
child_value = undefined
|
||||
else:
|
||||
child_value = child.getattr(name,
|
||||
option_bag)
|
||||
moption_bag)
|
||||
if force_default or (force_default_if_same and value == child_value):
|
||||
child.cfgimpl_get_values().reset(option_bag,
|
||||
child.cfgimpl_get_values().reset(moption_bag,
|
||||
_commit=False)
|
||||
continue
|
||||
if force_dont_change_value:
|
||||
child_value = child.getattr(name,
|
||||
option_bag)
|
||||
moption_bag)
|
||||
if value != child_value:
|
||||
child.setattr(child_value,
|
||||
option_bag,
|
||||
moption_bag,
|
||||
_commit=False)
|
||||
except PropertiesOptionError as err:
|
||||
ret.append(PropertiesOptionError(err._option_bag,
|
||||
@ -1064,16 +1083,10 @@ class KernelPathConfig(KernelGroupConfig):
|
||||
ret.append(err)
|
||||
|
||||
try:
|
||||
subconfig, name = self.cfgimpl_get_home_by_path(path,
|
||||
config_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
config_bag,
|
||||
self.cfgimpl_get_path())
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
path,
|
||||
index,
|
||||
config_bag)
|
||||
if self.impl_type == 'meta':
|
||||
del option_bag.properties
|
||||
del option_bag.permissives
|
||||
option_bag.config_bag = config_bag
|
||||
self.setattr(value,
|
||||
option_bag,
|
||||
_commit=False)
|
||||
@ -1083,22 +1096,68 @@ class KernelPathConfig(KernelGroupConfig):
|
||||
|
||||
def reset(self,
|
||||
path,
|
||||
config_bag):
|
||||
only_children,
|
||||
config_bag,
|
||||
commit=True):
|
||||
rconfig_bag = config_bag.copy()
|
||||
rconfig_bag.remove_validation()
|
||||
subconfig, name = self.cfgimpl_get_home_by_path(path,
|
||||
config_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
config_bag,
|
||||
subconfig.cfgimpl_get_path())
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
path,
|
||||
option,
|
||||
rconfig_bag)
|
||||
if self.impl_type == 'meta':
|
||||
subconfig, name = self.cfgimpl_get_home_by_path(path,
|
||||
config_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
config_bag,
|
||||
subconfig.cfgimpl_get_path())
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
path,
|
||||
None,
|
||||
rconfig_bag)
|
||||
elif not only_children:
|
||||
try:
|
||||
subconfig, name = self.cfgimpl_get_home_by_path(path,
|
||||
config_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
config_bag,
|
||||
subconfig.cfgimpl_get_path())
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
path,
|
||||
None,
|
||||
rconfig_bag)
|
||||
except AttributeError:
|
||||
only_children = True
|
||||
for child in self._impl_children:
|
||||
option_bag.config_bag.context = child
|
||||
child.cfgimpl_get_values().reset(option_bag)
|
||||
rconfig_bag.context = child
|
||||
try:
|
||||
if self.impl_type == 'meta':
|
||||
moption_bag = option_bag
|
||||
moption_bag.config_bag = rconfig_bag
|
||||
else:
|
||||
subconfig, name = child.cfgimpl_get_home_by_path(path,
|
||||
rconfig_bag)
|
||||
option = subconfig.cfgimpl_get_description().impl_getchild(name,
|
||||
rconfig_bag,
|
||||
child.cfgimpl_get_path())
|
||||
moption_bag = OptionBag()
|
||||
moption_bag.set_option(option,
|
||||
path,
|
||||
None,
|
||||
rconfig_bag)
|
||||
child.cfgimpl_get_values().reset(moption_bag,
|
||||
_commit=False)
|
||||
except AttributeError:
|
||||
pass
|
||||
if isinstance(child, KernelPathConfig):
|
||||
child.reset(path,
|
||||
False,
|
||||
rconfig_bag,
|
||||
commit=False)
|
||||
if not only_children:
|
||||
option_bag.config_bag = config_bag
|
||||
self.cfgimpl_get_values().reset(option_bag,
|
||||
_commit=False)
|
||||
if commit:
|
||||
self.cfgimpl_get_values()._p_.commit()
|
||||
|
||||
|
||||
class KernelMetaConfig(KernelPathConfig):
|
||||
|
@ -169,7 +169,8 @@ class MasterSlaves(OptionDescription):
|
||||
validate_meta=False):
|
||||
if slavelen > index:
|
||||
values._p_.resetvalue_index(slave_path,
|
||||
index)
|
||||
index,
|
||||
True)
|
||||
if slavelen > index + 1:
|
||||
for idx in range(index + 1, slavelen):
|
||||
if values._p_.hasvalue(slave_path, idx):
|
||||
|
@ -156,7 +156,7 @@ class OptionBag:
|
||||
raise KeyError('unknown key {} for OptionBag'.format(key)) # pragma: no cover
|
||||
|
||||
def __delattr__(self, key):
|
||||
if key == 'properties':
|
||||
if key in ['properties', 'permissives']:
|
||||
return
|
||||
raise KeyError('unknown key {} for ConfigBag'.format(key)) # pragma: no cover
|
||||
|
||||
|
@ -131,7 +131,10 @@ class Values(Cache):
|
||||
values[1] = tuple(values_idx)
|
||||
self._values = tuple(values)
|
||||
|
||||
def resetvalue_index(self, path, index):
|
||||
def resetvalue_index(self,
|
||||
path,
|
||||
index,
|
||||
commit):
|
||||
if DEBUG:
|
||||
print('resetvalue_index', path, index, id(self))
|
||||
def _resetvalue(nb):
|
||||
|
@ -445,13 +445,11 @@ class Values(object):
|
||||
else:
|
||||
self._p_.resetvalue(option_bag.path,
|
||||
_commit)
|
||||
if not opt.impl_is_master_slaves('master'):
|
||||
# if master, already reset behind
|
||||
pass
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
def reset_slave(self,
|
||||
option_bag):
|
||||
option_bag,
|
||||
_commit=True):
|
||||
|
||||
if self._p_.hasvalue(option_bag.path, index=option_bag.index):
|
||||
context = option_bag.config_bag.context
|
||||
@ -467,7 +465,9 @@ class Values(object):
|
||||
value = fake_value.getdefaultvalue(soption_bag)
|
||||
fake_value.setvalue_validation(value,
|
||||
soption_bag)
|
||||
self._p_.resetvalue_index(option_bag.path, option_bag.index)
|
||||
self._p_.resetvalue_index(option_bag.path,
|
||||
option_bag.index,
|
||||
_commit)
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
def reset_master(self,
|
||||
|
Reference in New Issue
Block a user