values/settings is not useful to KernelGroupConfig

This commit is contained in:
Emmanuel Garette 2018-09-26 22:29:08 +02:00
parent 4426cc5111
commit 242615f68b
5 changed files with 31 additions and 48 deletions

View File

@ -283,7 +283,7 @@ def test_not_meta():
conf4 = Config(od2, session_id='conf4')
raises(TypeError, "GroupConfig(conf1)")
#same name
raises(ConflictError, "GroupConfig([conf2, conf4], session_id='conf2')")
#raises(ConflictError, "GroupConfig([conf2, conf4], session_id='conf2')")
raises(ConflictError, "GroupConfig([conf2, conf2], session_id='conf8')")
grp = GroupConfig([conf1, conf2])
raises(ConfigError, "grp.option('od1.i1').value.get()")

View File

@ -1168,17 +1168,13 @@ class MetaConfig(TiramisuAPI):
class GroupConfig(TiramisuAPI):
def __init__(self,
children,
session_id: Union[str, None]=None,
persistent: bool=False,
storage=None) -> None:
session_id: Union[str, None]=None) -> None:
_children = []
for child in children:
_children.append(child._config_bag.context)
config = KernelGroupConfig(_children,
session_id=session_id,
persistent=persistent,
storage=storage)
session_id=session_id)
super().__init__(config)

View File

@ -27,7 +27,7 @@ from .error import PropertiesOptionError, ConfigError, ConflictError, SlaveError
from .option import SynDynOptionDescription, DynOptionDescription, MasterSlaves
from .option.baseoption import BaseOption, valid_name
from .setting import OptionBag, ConfigBag, groups, Settings, undefined
from .storage import get_storages, get_default_values_storages
from .storage import get_storages, gen_storage_id, get_default_values_storages
from .value import Values # , Multi
from .i18n import _
@ -683,8 +683,6 @@ class _CommonConfig(SubConfig):
_duplicate=True,
optiondescription=self._impl_descr,
session_id=session_id,
force_values=force_values,
force_settings=force_settings,
persistent=persistent,
storage=storage)
duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
@ -775,12 +773,7 @@ class KernelGroupConfig(_CommonConfig):
def __init__(self,
children,
session_id=None,
persistent=False,
force_settings=None,
force_values=None,
_descr=None,
_duplicate=False,
storage=None):
_descr=None):
assert isinstance(children, list), _("groupconfig's children must be a list")
names = []
for child in children:
@ -795,27 +788,13 @@ class KernelGroupConfig(_CommonConfig):
raise ConflictError(_('config name must be uniq in '
'groupconfig for "{0}"').format(name))
self._impl_children = children
if force_settings is not None and force_values is not None:
self._impl_settings = Settings(force_settings[0],
force_settings[1])
self._impl_values = Values(force_values)
else:
properties, permissives, values, session_id = get_storages(self,
session_id,
persistent,
storage=storage)
assert valid_name(session_id), _("invalid session ID: {0} for config").format(session_id)
self._impl_settings = Settings(properties,
permissives)
self._impl_values = Values(values)
self._impl_meta = None
session_id = gen_storage_id(session_id, self)
assert valid_name(session_id), _("invalid session ID: {0} for config").format(session_id)
super().__init__(_descr,
weakref.ref(self),
ConfigBag(self),
None)
#undocumented option used only in test script
self._impl_name = session_id
def cfgimpl_get_children(self):
@ -853,7 +832,7 @@ class KernelGroupConfig(_CommonConfig):
value,
cconfig_bag,
only_config=only_config,
_commit=False))
_commit=_commit))
else:
subconfig, name = child.cfgimpl_get_home_by_path(path,
cconfig_bag)
@ -867,7 +846,7 @@ class KernelGroupConfig(_CommonConfig):
cconfig_bag)
child.setattr(value,
option_bag,
_commit=False)
_commit=_commit)
except PropertiesOptionError as err:
ret.append(PropertiesOptionError(err._option_bag,
err.proptype,
@ -878,8 +857,9 @@ class KernelGroupConfig(_CommonConfig):
err._orig_opt))
except (ValueError, SlaveError) as err:
ret.append(err)
if _commit:
self.cfgimpl_get_values()._p_.commit()
#FIXME should commit only here
#if _commit:
# self._impl_children[0].cfgimpl_get_values()._p_.commit()
return ret
@ -956,8 +936,6 @@ class KernelMetaConfig(KernelGroupConfig):
children,
session_id=None,
persistent=False,
force_settings=None,
force_values=None,
optiondescription=None,
storage=None,
_duplicate=False):
@ -991,12 +969,15 @@ class KernelMetaConfig(KernelGroupConfig):
'have the same optiondescription'))
child._impl_meta = weakref.ref(self)
properties, permissives, values, session_id = get_storages(self,
session_id,
persistent,
storage=storage)
self._impl_settings = Settings(properties,
permissives)
self._impl_values = Values(values)
super().__init__(children,
session_id,
persistent,
force_settings=force_settings,
force_values=force_values,
storage=storage,
session_id=session_id,
_descr=descr)
self._impl_build_all_caches()

View File

@ -214,6 +214,9 @@ class ConfigBag:
def copy(self):
kwargs = {}
for key in self.__slots__:
if key in ['properties', 'permissives'] and \
not hasattr(self.context, '_impl_settings'):
continue
kwargs[key] = getattr(self, key)
return ConfigBag(**kwargs)

View File

@ -96,12 +96,15 @@ def set_storage(type_, name): # pragma: optional cover
setting = storage_type.get().setting
def get_storages(context, session_id, persistent, storage):
def gen_id(config):
return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500))
def gen_storage_id(session_id,
config):
if session_id is not None:
return session_id
return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500))
if session_id is None:
session_id = gen_id(context)
def get_storages(context, session_id, persistent, storage):
session_id = gen_storage_id(session_id, context)
if storage is None:
storage = storage_type
imp = storage.get()