reorganise .list()
This commit is contained in:
parent
87e2f422b7
commit
1c2bbc59fd
|
@ -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'))
|
|
||||||
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 group_type:
|
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'))
|
raise APIError(_('not implemented yet'))
|
||||||
if recursive:
|
for option in self.config_bag.config.cfgimpl_get_description()._cache_paths[1]:
|
||||||
if not self.config_bag.force_unrestraint:
|
if type == 'optiondescription' and not isinstance(option, OptionDescription):
|
||||||
raise APIError(_('not implemented yet'))
|
continue
|
||||||
else:
|
yield option
|
||||||
return self.config_bag.config.cfgimpl_get_description()._cache_paths[1]
|
|
||||||
else:
|
|
||||||
return self.config_bag.config.cfgimpl_get_children(self.config_bag)
|
|
||||||
else:
|
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):
|
class TiramisuContextConfig(TiramisuContext):
|
||||||
|
|
Loading…
Reference in New Issue