can create a config with a mix_config

This commit is contained in:
Emmanuel Garette 2020-03-04 15:39:47 +01:00
parent ad6ed0a648
commit f1651848d2
4 changed files with 78 additions and 69 deletions

View File

@ -1306,6 +1306,16 @@ async def test_mix_add_config_readd():
await delete_sessions([mix, mix2])
@pytest.mark.asyncio
async def test_mix_new_config_readd():
od = make_description()
mix = await MixConfig(od, [])
assert len(list(await mix.config.list())) == 0
mix2 = await mix.config.new('mix2')
assert len(list(await mix.config.list())) == 1
await delete_sessions([mix, mix2])
@pytest.mark.asyncio
async def test_meta_new_mixconfig():
od = make_description()

View File

@ -1530,6 +1530,23 @@ class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextCon
"""Type a Config"""
return 'mixconfig'
async def new(self,
session_id,
storage=None,
type='config'):
"""Create and add a new config"""
config = self._config_bag.context
if storage is None:
storage = config._storage
storage_obj = await storage.get()
async with storage_obj.Connection() as connection:
new_config = await config.new_config(connection,
session_id=session_id,
storage=storage,
type_=type)
return await self._return_config(new_config,
new_config._storage)
async def pop(self,
session_id=None,
config=None):
@ -1560,24 +1577,6 @@ class _TiramisuContextMetaConfig(_TiramisuContextMixConfig):
"""Type a Config"""
return 'metaconfig'
async def new(self,
session_id,
storage=None,
type='config'):
"""Create and add a new config"""
config = self._config_bag.context
if storage is None:
storage = config._storage
storage_obj = await storage.get()
async with storage_obj.Connection() as connection:
new_config = await config.new_config(connection,
session_id=session_id,
storage=storage,
type_=type)
return await self._return_config(new_config,
new_config._storage)
class TiramisuContextCache(TiramisuConfig):
async def reset(self):

View File

@ -1171,6 +1171,56 @@ class KernelMixConfig(KernelGroupConfig):
option_bag.config_bag = config_bag
await self.cfgimpl_get_values().reset(option_bag)
async def new_config(self,
connection,
session_id,
type_='config',
storage=None):
if session_id in [child.impl_getname() for child in self._impl_children]:
raise ConflictError(_('config name must be uniq in '
'groupconfig for {0}').format(session_id))
assert type_ in ('config', 'metaconfig', 'mixconfig'), _('unknown type {}').format(type_)
new = session_id not in await list_sessions()
if type_ == 'config':
config = await KernelConfig(self._impl_descr,
session_id=session_id,
storage=storage,
connection=connection,
display_name=self._display_name)
elif type_ == 'metaconfig':
config = await KernelMetaConfig([],
optiondescription=self._impl_descr,
session_id=session_id,
storage=storage,
connection=connection,
display_name=self._display_name)
elif type_ == 'mixconfig':
config = await KernelMixConfig(children=[],
optiondescription=self._impl_descr,
session_id=session_id,
storage=storage,
connection=connection,
display_name=self._display_name)
# Copy context properties/permissives
if new:
settings = config.cfgimpl_get_settings()
properties = await self.cfgimpl_get_settings().get_context_properties(connection,
config._impl_properties_cache)
await settings.set_context_properties(connection,
properties,
config)
await settings.set_context_permissives(connection,
await self.cfgimpl_get_settings().get_context_permissives(connection))
settings.ro_append = self.cfgimpl_get_settings().ro_append
settings.rw_append = self.cfgimpl_get_settings().rw_append
settings.ro_remove = self.cfgimpl_get_settings().ro_remove
settings.rw_remove = self.cfgimpl_get_settings().rw_remove
settings.default_properties = self.cfgimpl_get_settings().default_properties
config.parents.append(weakref.ref(self))
self._impl_children.append(config)
return config
async def add_config(self,
apiconfig):
config = apiconfig._config_bag.context
@ -1251,56 +1301,6 @@ class KernelMetaConfig(KernelMixConfig):
storage=storage,
session_id=session_id)
async def new_config(self,
connection,
session_id,
type_='config',
storage=None):
if session_id in [child.impl_getname() for child in self._impl_children]:
raise ConflictError(_('config name must be uniq in '
'groupconfig for {0}').format(session_id))
assert type_ in ('config', 'metaconfig', 'mixconfig'), _('unknown type {}').format(type_)
new = session_id not in await list_sessions()
if type_ == 'config':
config = await KernelConfig(self._impl_descr,
session_id=session_id,
storage=storage,
connection=connection,
display_name=self._display_name)
elif type_ == 'metaconfig':
config = await KernelMetaConfig([],
optiondescription=self._impl_descr,
session_id=session_id,
storage=storage,
connection=connection,
display_name=self._display_name)
elif type_ == 'mixconfig':
config = await KernelMixConfig(children=[],
optiondescription=self._impl_descr,
session_id=session_id,
storage=storage,
connection=connection,
display_name=self._display_name)
# Copy context properties/permissives
if new:
settings = config.cfgimpl_get_settings()
properties = await self.cfgimpl_get_settings().get_context_properties(connection,
config._impl_properties_cache)
await settings.set_context_properties(connection,
properties,
config)
await settings.set_context_permissives(connection,
await self.cfgimpl_get_settings().get_context_permissives(connection))
settings.ro_append = self.cfgimpl_get_settings().ro_append
settings.rw_append = self.cfgimpl_get_settings().rw_append
settings.ro_remove = self.cfgimpl_get_settings().ro_remove
settings.rw_remove = self.cfgimpl_get_settings().rw_remove
settings.default_properties = self.cfgimpl_get_settings().default_properties
config.parents.append(weakref.ref(self))
self._impl_children.append(config)
return config
async def add_config(self,
apiconfig):
if self._impl_descr is not apiconfig._config_bag.context.cfgimpl_get_description():

View File

@ -59,7 +59,7 @@ class SynDynOption:
return self.opt.impl_getname() + self.suffix
def impl_get_display_name(self) -> str:
return self.opt.impl_get_display_name(dyn_name=self.impl_getname())
return self.opt.impl_get_display_name(dyn_name=self.impl_getname()) + self.suffix
def impl_getsuffix(self) -> str:
return self.suffix