add/remove config in mixconfig or metaconfig (fixes #6)
This commit is contained in:
@ -1248,10 +1248,18 @@ class _TiramisuContextGroupConfig(TiramisuContext):
|
||||
|
||||
class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextConfigReset):
|
||||
"""Actions to MixConfig"""
|
||||
pass
|
||||
def pop(self,
|
||||
session_id):
|
||||
"""Remove config from MetaConfig"""
|
||||
return Config(self._config_bag.context.pop_config(session_id=session_id))
|
||||
|
||||
def add(self,
|
||||
config):
|
||||
"""Add config from MetaConfig"""
|
||||
return Config(self._config_bag.context.add_config(config))
|
||||
|
||||
|
||||
class _TiramisuContextMetaConfig(_TiramisuContextGroupConfig, _TiramisuContextConfigReset):
|
||||
class _TiramisuContextMetaConfig(_TiramisuContextMixConfig):
|
||||
"""Actions to MetaConfig"""
|
||||
def new(self,
|
||||
session_id,
|
||||
@ -1262,11 +1270,6 @@ class _TiramisuContextMetaConfig(_TiramisuContextGroupConfig, _TiramisuContextCo
|
||||
persistent=persistent,
|
||||
type_=type))
|
||||
|
||||
def pop(self,
|
||||
session_id):
|
||||
"""Remove config from MetaConfig"""
|
||||
return Config(self._config_bag.context.pop_config(session_id=session_id))
|
||||
|
||||
|
||||
class TiramisuContextCache(TiramisuContext):
|
||||
def reset(self):
|
||||
|
@ -1169,6 +1169,28 @@ class KernelMixConfig(KernelGroupConfig):
|
||||
if commit:
|
||||
self.cfgimpl_get_values()._p_.commit()
|
||||
|
||||
def add_config(self,
|
||||
apiconfig):
|
||||
config = apiconfig._config_bag.context
|
||||
if config._impl_meta is not None:
|
||||
raise ConflictError(_('config is already in a metaconfig'))
|
||||
if config.impl_getname() in [child.impl_getname() for child in self._impl_children]:
|
||||
raise ConflictError(_('config name must be uniq in '
|
||||
'groupconfig for {0}').format(config.impl_getname()))
|
||||
|
||||
config._impl_meta = weakref.ref(self)
|
||||
self._impl_children.append(config)
|
||||
config.cfgimpl_reset_cache(None, None)
|
||||
|
||||
def pop_config(self,
|
||||
session_id):
|
||||
for idx, child in enumerate(self._impl_children):
|
||||
if session_id == child.impl_getname():
|
||||
child._impl_meta = None
|
||||
child.cfgimpl_reset_cache(None, None)
|
||||
return self._impl_children.pop(idx)
|
||||
raise ConfigError(_('cannot find the config {}').format(session_id))
|
||||
|
||||
|
||||
class KernelMetaConfig(KernelMixConfig):
|
||||
__slots__ = tuple()
|
||||
@ -1221,7 +1243,7 @@ class KernelMetaConfig(KernelMixConfig):
|
||||
session_id,
|
||||
type_='config',
|
||||
persistent=False):
|
||||
if session_id in [child._impl_name for child in self._impl_children]:
|
||||
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'), _('unknown type {}').format(type_)
|
||||
@ -1242,9 +1264,9 @@ class KernelMetaConfig(KernelMixConfig):
|
||||
self._impl_children.append(config)
|
||||
return config
|
||||
|
||||
def pop_config(self,
|
||||
session_id):
|
||||
for idx, child in enumerate(self._impl_children):
|
||||
if session_id == child._impl_name:
|
||||
return self._impl_children.pop(idx)
|
||||
raise ConfigError(_('cannot find the config {}').format(session_id))
|
||||
def add_config(self,
|
||||
apiconfig):
|
||||
if self._impl_descr is not apiconfig._config_bag.context.cfgimpl_get_description():
|
||||
raise ValueError(_('metaconfig must '
|
||||
'have the same optiondescription'))
|
||||
super().add_config(apiconfig)
|
||||
|
Reference in New Issue
Block a user