From 242615f68bf78b58cc3274c3745fef144281c23e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 26 Sep 2018 22:29:08 +0200 Subject: [PATCH] values/settings is not useful to KernelGroupConfig --- test/test_metaconfig.py | 2 +- tiramisu/api.py | 8 ++---- tiramisu/config.py | 53 ++++++++++++------------------------ tiramisu/setting.py | 3 ++ tiramisu/storage/__init__.py | 13 +++++---- 5 files changed, 31 insertions(+), 48 deletions(-) diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index f8554a3..42b7e2f 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -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()") diff --git a/tiramisu/api.py b/tiramisu/api.py index 16acb62..3f532e2 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -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) diff --git a/tiramisu/config.py b/tiramisu/config.py index 4e6f9f6..a14a3ef 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -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() diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 71febf8..6121ed4 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -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) diff --git a/tiramisu/storage/__init__.py b/tiramisu/storage/__init__.py index 3ecd8f0..3a7bb86 100644 --- a/tiramisu/storage/__init__.py +++ b/tiramisu/storage/__init__.py @@ -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()