reorganise .list()

This commit is contained in:
Emmanuel Garette 2018-08-02 08:38:42 +02:00
parent 87e2f422b7
commit 1c2bbc59fd
1 changed files with 40 additions and 24 deletions

View File

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