correction in list with recursion

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

View file

@ -110,13 +110,27 @@ def test_iter_on_groups():
descr = make_description()
api = Config(descr)
api.property.read_write()
result = api.option('creole').list('optiondescription', group_type=groups.family)
result = api.option('creole').list('optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
for i in api.option('creole').list('optiondescription', group_type=groups.family):
for i in api.option('creole').list('optiondescription',
group_type=groups.family):
#test StopIteration
break
def test_list_recursive():
descr = make_description()
api = Config(descr)
api.property.read_write()
result = api.option('creole').list('all')
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
#
result = list(api.option.list(recursive=True))
group_names = [res.option.name() for res in result]
assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces', 'activer_proxy_client', 'mode_conteneur_actif', 'serveur_ntp', 'time_zone', 'ip_admin_eth0', 'netmask_admin_eth0']
def test_iter_on_groups_force_permissive():
descr = make_description()
@ -141,7 +155,8 @@ def test_iter_group_on_groups_force_permissive():
api = Config(descr)
api.property.read_write()
api.permissive.set(frozenset(['hidden']))
result = api.forcepermissive.option('creole').list(type='optiondescription', group_type=groups.family)
result = api.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new']
@ -151,7 +166,8 @@ def test_iter_on_groups_props():
api = Config(descr)
api.property.read_write()
api.option('creole.interface1').property.add('disabled')
result = api.option('creole').list(type='optiondescription', group_type=groups.family)
result = api.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general']

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,11 +683,10 @@ 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):
if type == 'option' or (type == 'optiondescription' and group_type and \
opt.impl_get_group_type() != group_type):
continue
else:
if type == 'optiondescription':
elif type == 'optiondescription':
continue
name = opt.impl_getname()
yield TiramisuOption(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)
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)
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()
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()
yield TiramisuOption(name,
self.config_bag.context._get_subpath(name),
None,
self.config_bag.context,
path = opt.impl_getpath()
subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag)
yield TiramisuOption(name,
path,
None,
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):