correction in list with recursion
This commit is contained in:
parent
5b518bffea
commit
4e5ffb201d
2 changed files with 52 additions and 37 deletions
|
@ -110,13 +110,27 @@ def test_iter_on_groups():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
api = Config(descr)
|
api = Config(descr)
|
||||||
api.property.read_write()
|
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]
|
group_names = [res.option.name() for res in result]
|
||||||
assert group_names == ['general', 'interface1']
|
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
|
#test StopIteration
|
||||||
break
|
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():
|
def test_iter_on_groups_force_permissive():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
|
@ -141,7 +155,8 @@ def test_iter_group_on_groups_force_permissive():
|
||||||
api = Config(descr)
|
api = Config(descr)
|
||||||
api.property.read_write()
|
api.property.read_write()
|
||||||
api.permissive.set(frozenset(['hidden']))
|
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]
|
group_names = [res.option.name() for res in result]
|
||||||
assert group_names == ['general', 'interface1', 'new']
|
assert group_names == ['general', 'interface1', 'new']
|
||||||
|
|
||||||
|
@ -151,7 +166,8 @@ def test_iter_on_groups_props():
|
||||||
api = Config(descr)
|
api = Config(descr)
|
||||||
api.property.read_write()
|
api.property.read_write()
|
||||||
api.option('creole.interface1').property.add('disabled')
|
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]
|
group_names = [res.option.name() for res in result]
|
||||||
assert group_names == ['general']
|
assert group_names == ['general']
|
||||||
|
|
||||||
|
|
|
@ -643,10 +643,10 @@ class TiramisuOption(CommonTiramisu):
|
||||||
return self._get_option().impl_get_group_type()
|
return self._get_option().impl_get_group_type()
|
||||||
|
|
||||||
def _list(self,
|
def _list(self,
|
||||||
type='all',
|
type='option',
|
||||||
group_type=None):
|
group_type=None):
|
||||||
"""list options in an optiondescription (only for optiondescription)"""
|
"""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))
|
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):
|
||||||
|
@ -683,11 +683,10 @@ class TiramisuOption(CommonTiramisu):
|
||||||
except PropertiesOptionError:
|
except PropertiesOptionError:
|
||||||
continue
|
continue
|
||||||
if opt.impl_is_optiondescription():
|
if opt.impl_is_optiondescription():
|
||||||
if type == 'optiondescription' and \
|
if type == 'option' or (type == 'optiondescription' and group_type and \
|
||||||
(group_type and opt.impl_get_group_type() != group_type):
|
opt.impl_get_group_type() != group_type):
|
||||||
continue
|
continue
|
||||||
else:
|
elif type == 'optiondescription':
|
||||||
if type == 'optiondescription':
|
|
||||||
continue
|
continue
|
||||||
name = opt.impl_getname()
|
name = opt.impl_getname()
|
||||||
yield TiramisuOption(name,
|
yield TiramisuOption(name,
|
||||||
|
@ -910,7 +909,7 @@ class TiramisuContextOption(TiramisuContext):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def list(self,
|
def list(self,
|
||||||
type='all',
|
type='option',
|
||||||
group_type=None,
|
group_type=None,
|
||||||
recursive=False):
|
recursive=False):
|
||||||
"""list content of an optiondescription"""
|
"""list content of an optiondescription"""
|
||||||
|
@ -922,44 +921,44 @@ class TiramisuContextOption(TiramisuContext):
|
||||||
name,
|
name,
|
||||||
None,
|
None,
|
||||||
self.config_bag)
|
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,
|
self.config_bag.context.getattr(name,
|
||||||
option_bag)
|
option_bag)
|
||||||
if type not in ('all', 'optiondescription'):
|
def _walk(option):
|
||||||
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()
|
|
||||||
for opt in option.impl_getchildren(self.config_bag):
|
for opt in option.impl_getchildren(self.config_bag):
|
||||||
try:
|
try:
|
||||||
subsubconfig = _filter(opt)
|
subsubconfig = _filter(opt)
|
||||||
except PropertiesOptionError:
|
except PropertiesOptionError:
|
||||||
continue
|
continue
|
||||||
if opt.impl_is_optiondescription():
|
if opt.impl_is_optiondescription():
|
||||||
if type == 'optiondescription' and \
|
if recursive:
|
||||||
(group_type and opt.impl_get_group_type() != group_type):
|
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
|
continue
|
||||||
else:
|
else:
|
||||||
if type == 'optiondescription':
|
if type == 'optiondescription':
|
||||||
continue
|
continue
|
||||||
name = opt.impl_getname()
|
path = opt.impl_getpath()
|
||||||
yield TiramisuOption(name,
|
subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
|
||||||
self.config_bag.context._get_subpath(name),
|
|
||||||
None,
|
|
||||||
self.config_bag.context,
|
|
||||||
self.config_bag)
|
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):
|
class TiramisuContextConfig(TiramisuContext):
|
||||||
|
|
Loading…
Reference in a new issue