values/settings is not useful to KernelGroupConfig
This commit is contained in:
parent
4426cc5111
commit
242615f68b
5 changed files with 31 additions and 48 deletions
|
@ -283,7 +283,7 @@ def test_not_meta():
|
||||||
conf4 = Config(od2, session_id='conf4')
|
conf4 = Config(od2, session_id='conf4')
|
||||||
raises(TypeError, "GroupConfig(conf1)")
|
raises(TypeError, "GroupConfig(conf1)")
|
||||||
#same name
|
#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')")
|
raises(ConflictError, "GroupConfig([conf2, conf2], session_id='conf8')")
|
||||||
grp = GroupConfig([conf1, conf2])
|
grp = GroupConfig([conf1, conf2])
|
||||||
raises(ConfigError, "grp.option('od1.i1').value.get()")
|
raises(ConfigError, "grp.option('od1.i1').value.get()")
|
||||||
|
|
|
@ -1168,17 +1168,13 @@ class MetaConfig(TiramisuAPI):
|
||||||
class GroupConfig(TiramisuAPI):
|
class GroupConfig(TiramisuAPI):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
children,
|
children,
|
||||||
session_id: Union[str, None]=None,
|
session_id: Union[str, None]=None) -> None:
|
||||||
persistent: bool=False,
|
|
||||||
storage=None) -> None:
|
|
||||||
_children = []
|
_children = []
|
||||||
for child in children:
|
for child in children:
|
||||||
_children.append(child._config_bag.context)
|
_children.append(child._config_bag.context)
|
||||||
|
|
||||||
config = KernelGroupConfig(_children,
|
config = KernelGroupConfig(_children,
|
||||||
session_id=session_id,
|
session_id=session_id)
|
||||||
persistent=persistent,
|
|
||||||
storage=storage)
|
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ from .error import PropertiesOptionError, ConfigError, ConflictError, SlaveError
|
||||||
from .option import SynDynOptionDescription, DynOptionDescription, MasterSlaves
|
from .option import SynDynOptionDescription, DynOptionDescription, MasterSlaves
|
||||||
from .option.baseoption import BaseOption, valid_name
|
from .option.baseoption import BaseOption, valid_name
|
||||||
from .setting import OptionBag, ConfigBag, groups, Settings, undefined
|
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 .value import Values # , Multi
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
@ -683,8 +683,6 @@ class _CommonConfig(SubConfig):
|
||||||
_duplicate=True,
|
_duplicate=True,
|
||||||
optiondescription=self._impl_descr,
|
optiondescription=self._impl_descr,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
force_values=force_values,
|
|
||||||
force_settings=force_settings,
|
|
||||||
persistent=persistent,
|
persistent=persistent,
|
||||||
storage=storage)
|
storage=storage)
|
||||||
duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
|
duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
|
||||||
|
@ -775,12 +773,7 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
children,
|
children,
|
||||||
session_id=None,
|
session_id=None,
|
||||||
persistent=False,
|
_descr=None):
|
||||||
force_settings=None,
|
|
||||||
force_values=None,
|
|
||||||
_descr=None,
|
|
||||||
_duplicate=False,
|
|
||||||
storage=None):
|
|
||||||
assert isinstance(children, list), _("groupconfig's children must be a list")
|
assert isinstance(children, list), _("groupconfig's children must be a list")
|
||||||
names = []
|
names = []
|
||||||
for child in children:
|
for child in children:
|
||||||
|
@ -795,27 +788,13 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
raise ConflictError(_('config name must be uniq in '
|
raise ConflictError(_('config name must be uniq in '
|
||||||
'groupconfig for "{0}"').format(name))
|
'groupconfig for "{0}"').format(name))
|
||||||
self._impl_children = children
|
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
|
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,
|
super().__init__(_descr,
|
||||||
weakref.ref(self),
|
weakref.ref(self),
|
||||||
ConfigBag(self),
|
ConfigBag(self),
|
||||||
None)
|
None)
|
||||||
#undocumented option used only in test script
|
|
||||||
self._impl_name = session_id
|
self._impl_name = session_id
|
||||||
|
|
||||||
def cfgimpl_get_children(self):
|
def cfgimpl_get_children(self):
|
||||||
|
@ -853,7 +832,7 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
value,
|
value,
|
||||||
cconfig_bag,
|
cconfig_bag,
|
||||||
only_config=only_config,
|
only_config=only_config,
|
||||||
_commit=False))
|
_commit=_commit))
|
||||||
else:
|
else:
|
||||||
subconfig, name = child.cfgimpl_get_home_by_path(path,
|
subconfig, name = child.cfgimpl_get_home_by_path(path,
|
||||||
cconfig_bag)
|
cconfig_bag)
|
||||||
|
@ -867,7 +846,7 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
cconfig_bag)
|
cconfig_bag)
|
||||||
child.setattr(value,
|
child.setattr(value,
|
||||||
option_bag,
|
option_bag,
|
||||||
_commit=False)
|
_commit=_commit)
|
||||||
except PropertiesOptionError as err:
|
except PropertiesOptionError as err:
|
||||||
ret.append(PropertiesOptionError(err._option_bag,
|
ret.append(PropertiesOptionError(err._option_bag,
|
||||||
err.proptype,
|
err.proptype,
|
||||||
|
@ -878,8 +857,9 @@ class KernelGroupConfig(_CommonConfig):
|
||||||
err._orig_opt))
|
err._orig_opt))
|
||||||
except (ValueError, SlaveError) as err:
|
except (ValueError, SlaveError) as err:
|
||||||
ret.append(err)
|
ret.append(err)
|
||||||
if _commit:
|
#FIXME should commit only here
|
||||||
self.cfgimpl_get_values()._p_.commit()
|
#if _commit:
|
||||||
|
# self._impl_children[0].cfgimpl_get_values()._p_.commit()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -956,8 +936,6 @@ class KernelMetaConfig(KernelGroupConfig):
|
||||||
children,
|
children,
|
||||||
session_id=None,
|
session_id=None,
|
||||||
persistent=False,
|
persistent=False,
|
||||||
force_settings=None,
|
|
||||||
force_values=None,
|
|
||||||
optiondescription=None,
|
optiondescription=None,
|
||||||
storage=None,
|
storage=None,
|
||||||
_duplicate=False):
|
_duplicate=False):
|
||||||
|
@ -991,12 +969,15 @@ class KernelMetaConfig(KernelGroupConfig):
|
||||||
'have the same optiondescription'))
|
'have the same optiondescription'))
|
||||||
child._impl_meta = weakref.ref(self)
|
child._impl_meta = weakref.ref(self)
|
||||||
|
|
||||||
super().__init__(children,
|
properties, permissives, values, session_id = get_storages(self,
|
||||||
session_id,
|
session_id,
|
||||||
persistent,
|
persistent,
|
||||||
force_settings=force_settings,
|
storage=storage)
|
||||||
force_values=force_values,
|
self._impl_settings = Settings(properties,
|
||||||
storage=storage,
|
permissives)
|
||||||
|
self._impl_values = Values(values)
|
||||||
|
super().__init__(children,
|
||||||
|
session_id=session_id,
|
||||||
_descr=descr)
|
_descr=descr)
|
||||||
self._impl_build_all_caches()
|
self._impl_build_all_caches()
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,9 @@ class ConfigBag:
|
||||||
def copy(self):
|
def copy(self):
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
for key in self.__slots__:
|
for key in self.__slots__:
|
||||||
|
if key in ['properties', 'permissives'] and \
|
||||||
|
not hasattr(self.context, '_impl_settings'):
|
||||||
|
continue
|
||||||
kwargs[key] = getattr(self, key)
|
kwargs[key] = getattr(self, key)
|
||||||
return ConfigBag(**kwargs)
|
return ConfigBag(**kwargs)
|
||||||
|
|
||||||
|
|
|
@ -96,12 +96,15 @@ def set_storage(type_, name): # pragma: optional cover
|
||||||
setting = storage_type.get().setting
|
setting = storage_type.get().setting
|
||||||
|
|
||||||
|
|
||||||
def get_storages(context, session_id, persistent, storage):
|
def gen_storage_id(session_id,
|
||||||
def gen_id(config):
|
config):
|
||||||
|
if session_id is not None:
|
||||||
|
return session_id
|
||||||
return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500))
|
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:
|
if storage is None:
|
||||||
storage = storage_type
|
storage = storage_type
|
||||||
imp = storage.get()
|
imp = storage.get()
|
||||||
|
|
Loading…
Reference in a new issue