reorganise .list()

This commit is contained in:
Emmanuel Garette 2018-08-02 08:38:42 +02:00
parent 87e2f422b7
commit 1c2bbc59fd

View File

@ -24,7 +24,7 @@ from .error import APIError, ConfigError, SlaveError, PropertiesOptionError
from .i18n import _
from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, FORBIDDEN_SET_PROPERTIES
from .config import Config, SubConfig, GroupConfig, MetaConfig
from .option import ChoiceOption
from .option import ChoiceOption, OptionDescription
TIRAMISU_VERSION = 3
@ -1013,36 +1013,52 @@ class TiramisuContextOption(TiramisuContext):
group_type=None,
recursive=False):
"""list content of an optiondescription"""
# FIXME should return TiramisuOption !!!
def _filter(opt):
if not self.config_bag.force_unrestraint:
name = opt.impl_getname()
option_bag = OptionBag()
option_bag.set_option(opt,
name,
None,
self.config_bag)
self.config_bag.config.getattr(name,
option_bag)
if type not in ('all', 'optiondescription'):
raise APIError(_('unknown list type {}').format(type))
if group_type is not None and not isinstance(group_type,
groups.GroupType):
raise TypeError(_("unknown group_type: {0}").format(group_type))
if type == 'optiondescription':
if recursive:
raise APIError(_('not implemented yet'))
else:
if not self.config_bag.force_unrestraint:
option = self.config_bag.config.cfgimpl_get_description()
for opt in option.impl_getchildren(self.config_bag):
if type == 'optiondescription' and not opt.impl_is_optiondescription():
continue
yield opt.impl_getname()
else:
# FIXME itergroups !!!
return self.config_bag.config.iter_groups(self.config_bag, group_type)
elif type == 'all':
if recursive:
if group_type:
raise APIError(_('recursive with group_type is not implemented yet'))
if not self.config_bag.force_unrestraint:
raise APIError(_('not implemented yet'))
if recursive:
if not self.config_bag.force_unrestraint:
raise APIError(_('not implemented yet'))
else:
return self.config_bag.config.cfgimpl_get_description()._cache_paths[1]
else:
return self.config_bag.config.cfgimpl_get_children(self.config_bag)
for option in self.config_bag.config.cfgimpl_get_description()._cache_paths[1]:
if type == 'optiondescription' and not isinstance(option, OptionDescription):
continue
yield option
else:
raise APIError(_('unknown list type {}').format(type))
option = self.config_bag.config.cfgimpl_get_description()
for opt in option.impl_getchildren(self.config_bag):
try:
subsubconfig = _filter(opt)
except PropertiesOptionError:
continue
if opt.impl_is_optiondescription():
if type == 'optiondescription' and \
(group_type and opt.impl_get_group_type() != group_type):
continue
else:
if type == 'optiondescription':
continue
name = opt.impl_getname()
yield TiramisuOption(name,
self.config_bag.config._get_subpath(name),
None,
self.config_bag.config,
self.config_bag)
class TiramisuContextConfig(TiramisuContext):