todict works with Metaconfig
This commit is contained in:
@@ -712,9 +712,29 @@ class _TiramisuOption(CommonTiramisu):
|
||||
self._option_bag,
|
||||
config)
|
||||
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) # pragma: no cover
|
||||
#__________________________________________________________________________________________________
|
||||
#
|
||||
|
||||
|
||||
class _TiramisuOptionDescription(_TiramisuOption):
|
||||
class TiramisuConfig(TiramisuHelp):
|
||||
def __init__(self,
|
||||
config_bag: Optional[ConfigBag]) -> None:
|
||||
self._config_bag = config_bag
|
||||
|
||||
def _return_config(self,
|
||||
config):
|
||||
if isinstance(config, KernelConfig):
|
||||
return Config(config)
|
||||
if isinstance(config, KernelMetaConfig):
|
||||
return MetaConfig(config)
|
||||
if isinstance(config, KernelMixConfig):
|
||||
return MixConfig([], config)
|
||||
if isinstance(config, KernelGroupConfig):
|
||||
return GroupConfig(config)
|
||||
raise Exception(_('unknown config type {}').format(type(config)))
|
||||
|
||||
|
||||
class _TiramisuOptionDescription(_TiramisuOption, TiramisuConfig):
|
||||
def find(self,
|
||||
name: str,
|
||||
value=undefined,
|
||||
@@ -811,10 +831,10 @@ class _TiramisuOptionDescription(_TiramisuOption):
|
||||
clearable: str="all",
|
||||
remotable: str="minimum"):
|
||||
root = self._get_option().impl_getpath()
|
||||
self._tiramisu_dict = TiramisuDict(Config(self._config_bag.context),
|
||||
root=root,
|
||||
clearable=clearable,
|
||||
remotable=remotable)
|
||||
self._tiramisu_dict = TiramisuDict(self._return_config(self._config_bag.context),
|
||||
root=root,
|
||||
clearable=clearable,
|
||||
remotable=remotable)
|
||||
|
||||
def dict(self,
|
||||
clearable: str="all",
|
||||
@@ -863,29 +883,9 @@ class TiramisuOption(CommonTiramisuOption):
|
||||
config_bag=config_bag)
|
||||
|
||||
|
||||
#__________________________________________________________________________________________________
|
||||
#
|
||||
|
||||
|
||||
class TiramisuContext(TiramisuHelp):
|
||||
def __init__(self,
|
||||
config_bag: Optional[ConfigBag]) -> None:
|
||||
self._config_bag = config_bag
|
||||
|
||||
def _return_config(self,
|
||||
config):
|
||||
if isinstance(config, KernelConfig):
|
||||
return Config(config)
|
||||
if isinstance(config, KernelMetaConfig):
|
||||
return MetaConfig(config)
|
||||
if isinstance(config, KernelMixConfig):
|
||||
return MixConfig([], config)
|
||||
if isinstance(config, KernelGroupConfig):
|
||||
return GroupConfig(config)
|
||||
raise Exception(_('unknown config type {}').format(type(config)))
|
||||
|
||||
|
||||
class TiramisuContextInformation(TiramisuContext):
|
||||
class TiramisuContextInformation(TiramisuConfig):
|
||||
"""Manage config informations"""
|
||||
def get(self, name, default=undefined):
|
||||
"""Get an information"""
|
||||
@@ -904,7 +904,7 @@ class TiramisuContextInformation(TiramisuContext):
|
||||
return self._config_bag.context.impl_list_information()
|
||||
|
||||
|
||||
class TiramisuContextValue(TiramisuContext):
|
||||
class TiramisuContextValue(TiramisuConfig):
|
||||
"""Manage config value"""
|
||||
def mandatory(self):
|
||||
"""Return path of options with mandatory property without any value"""
|
||||
@@ -988,7 +988,7 @@ class TiramisuContextValue(TiramisuContext):
|
||||
True)
|
||||
|
||||
|
||||
class TiramisuContextOwner(TiramisuContext):
|
||||
class TiramisuContextOwner(TiramisuConfig):
|
||||
"""Global owner"""
|
||||
|
||||
def get(self):
|
||||
@@ -1005,7 +1005,7 @@ class TiramisuContextOwner(TiramisuContext):
|
||||
self._config_bag.context.cfgimpl_get_values().set_context_owner(obj_owner)
|
||||
|
||||
|
||||
class TiramisuContextProperty(TiramisuContext):
|
||||
class TiramisuContextProperty(TiramisuConfig):
|
||||
"""Manage config properties"""
|
||||
|
||||
def read_only(self):
|
||||
@@ -1136,7 +1136,7 @@ class TiramisuContextProperty(TiramisuContext):
|
||||
raise ValueError(_('unknown type {}').format(type))
|
||||
|
||||
|
||||
class TiramisuContextPermissive(TiramisuContext):
|
||||
class TiramisuContextPermissive(TiramisuConfig):
|
||||
"""Manage config permissives"""
|
||||
|
||||
def get(self):
|
||||
@@ -1180,7 +1180,7 @@ class TiramisuContextPermissive(TiramisuContext):
|
||||
self.set(frozenset(props))
|
||||
|
||||
|
||||
class TiramisuContextOption(TiramisuContext):
|
||||
class TiramisuContextOption(TiramisuConfig):
|
||||
def __init__(self,
|
||||
*args,
|
||||
**kwargs) -> None:
|
||||
@@ -1286,7 +1286,7 @@ class TiramisuContextOption(TiramisuContext):
|
||||
def _load_dict(self,
|
||||
clearable="all",
|
||||
remotable="minimum"):
|
||||
self._tiramisu_dict = TiramisuDict(Config(self._config_bag.context),
|
||||
self._tiramisu_dict = TiramisuDict(self._return_config(self._config_bag.context),
|
||||
root=None,
|
||||
clearable=clearable,
|
||||
remotable=remotable)
|
||||
@@ -1330,7 +1330,7 @@ class _TiramisuContextConfigReset():
|
||||
self._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
|
||||
|
||||
class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
|
||||
class _TiramisuContextConfig(TiramisuConfig, _TiramisuContextConfigReset):
|
||||
"""Actions to Config"""
|
||||
def name(self):
|
||||
return self._config_bag.context.impl_getname()
|
||||
@@ -1361,7 +1361,7 @@ class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
|
||||
return self._config_bag.context.cfgimpl_get_config_path()
|
||||
|
||||
|
||||
class _TiramisuContextGroupConfig(TiramisuContext):
|
||||
class _TiramisuContextGroupConfig(TiramisuConfig):
|
||||
"""Actions to GroupConfig"""
|
||||
def name(self):
|
||||
"""Get config name"""
|
||||
@@ -1421,9 +1421,12 @@ class _TiramisuContextGroupConfig(TiramisuContext):
|
||||
class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextConfigReset):
|
||||
"""Actions to MixConfig"""
|
||||
def pop(self,
|
||||
session_id):
|
||||
session_id=None,
|
||||
config=None):
|
||||
"""Remove config from MetaConfig"""
|
||||
return self._return_config(self._config_bag.context.pop_config(session_id=session_id))
|
||||
if __debug__ and None not in [session_id, config]:
|
||||
raise APIError(_('cannot set session_id and config together'))
|
||||
return self._return_config(self._config_bag.context.pop_config(session_id=session_id, config=config))
|
||||
|
||||
def add(self,
|
||||
config):
|
||||
@@ -1439,12 +1442,13 @@ class _TiramisuContextMetaConfig(_TiramisuContextMixConfig):
|
||||
type='config'):
|
||||
"""Create and add a new config"""
|
||||
new_config = self._config_bag.context.new_config(session_id=session_id,
|
||||
persistent=persistent,
|
||||
type_=type)
|
||||
persistent=persistent,
|
||||
type_=type)
|
||||
return self._return_config(new_config)
|
||||
|
||||
|
||||
class TiramisuContextCache(TiramisuContext):
|
||||
|
||||
class TiramisuContextCache(TiramisuConfig):
|
||||
def reset(self):
|
||||
self._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
|
||||
@@ -1521,7 +1525,6 @@ class TiramisuDispatcherOption(TiramisuDispatcher, TiramisuContextOption):
|
||||
self._config_bag)
|
||||
|
||||
|
||||
#__________________________________________________________________________________________________
|
||||
class Config(TiramisuAPI):
|
||||
"""Root config object that enables us to handle the configuration options"""
|
||||
def __init__(self,
|
||||
|
Reference in New Issue
Block a user