correction in list with recursion

This commit is contained in:
2018-09-10 21:59:54 +02:00
parent 5b518bffea
commit 4e5ffb201d
2 changed files with 52 additions and 37 deletions

View File

@ -643,10 +643,10 @@ class TiramisuOption(CommonTiramisu):
return self._get_option().impl_get_group_type()
def _list(self,
type='all',
type='option',
group_type=None):
"""list options in an optiondescription (only for optiondescription)"""
if type not in ('all', 'optiondescription'):
if type not in ('all', 'option', 'optiondescription'):
raise APIError(_('unknown list type {}').format(type))
if group_type is not None and not isinstance(group_type,
groups.GroupType):
@ -683,12 +683,11 @@ class TiramisuOption(CommonTiramisu):
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':
if type == 'option' or (type == 'optiondescription' and group_type and \
opt.impl_get_group_type() != group_type):
continue
elif type == 'optiondescription':
continue
name = opt.impl_getname()
yield TiramisuOption(name,
subconfig._get_subpath(name),
@ -910,7 +909,7 @@ class TiramisuContextOption(TiramisuContext):
return ret
def list(self,
type='all',
type='option',
group_type=None,
recursive=False):
"""list content of an optiondescription"""
@ -922,44 +921,44 @@ class TiramisuContextOption(TiramisuContext):
name,
None,
self.config_bag)
self.config_bag.context.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 recursive:
if group_type:
raise APIError(_('recursive with group_type is not implemented yet'))
if self.config_bag.properties:
raise APIError(_('not implemented yet'))
for option in self.config_bag.context.cfgimpl_get_description()._cache_paths[1]:
if type == 'optiondescription' and not isinstance(option, OptionDescription):
continue
yield option
else:
option = self.config_bag.context.cfgimpl_get_description()
if opt.impl_is_optiondescription():
self.config_bag.context.cfgimpl_get_settings().validate_properties(option_bag)
else:
self.config_bag.context.getattr(name,
option_bag)
def _walk(option):
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):
if recursive:
for toption in _walk(opt):
yield toption
if type == 'option' or (type == 'optiondescription' and \
group_type and opt.impl_get_group_type() != group_type):
continue
else:
if type == 'optiondescription':
continue
name = opt.impl_getname()
path = opt.impl_getpath()
subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag)
yield TiramisuOption(name,
self.config_bag.context._get_subpath(name),
path,
None,
self.config_bag.context,
subconfig,
self.config_bag)
if type not in ('all', 'option', '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))
option = self.config_bag.context.cfgimpl_get_description()
for toption in _walk(option):
yield toption
class TiramisuContextConfig(TiramisuContext):