in find_firsts get option only one time

This commit is contained in:
Emmanuel Garette 2014-11-11 11:31:23 +01:00
parent 7c5b6e2db2
commit c6c331eb54
2 changed files with 11 additions and 6 deletions

View file

@ -291,6 +291,7 @@ def test_build_dyndescription_context():
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
od = OptionDescription('od', '', [dod, val1])
cfg = Config(od)
cfg._impl_test = True
assert str(cfg) == """[dodval1]
[dodval2]
val1 = ['val1', 'val2']"""

View file

@ -313,7 +313,8 @@ class SubConfig(object):
def _find(self, bytype, byname, byvalue, first, type_='option',
_subpath=None, check_properties=True, display_error=True,
force_permissive=False, only_path=undefined):
force_permissive=False, only_path=undefined,
only_option=undefined):
"""
convenience method for finding an option that lives only in the subtree
@ -344,8 +345,7 @@ class SubConfig(object):
only_first = first is True and byvalue is None and \
check_properties is None
if only_path is not undefined:
option = self.unwrap_from_path(only_path)
options = [(only_path, option)]
options = [(only_path, only_option)]
else:
options = self.cfgimpl_get_description().impl_get_options_paths(
bytype, byname, _subpath, only_first,
@ -676,8 +676,8 @@ class GroupConfig(_CommonConfig):
except PropertiesOptionError:
pass
def find_firsts(self, byname=None, bypath=undefined, byvalue=undefined,
type_='option', display_error=True):
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
byvalue=undefined, type_='option', display_error=True):
"""Find first not in current GroupConfig, but in each children
"""
ret = []
@ -691,6 +691,8 @@ class GroupConfig(_CommonConfig):
check_properties=False,
display_error=display_error)
byname = None
byoption = self.cfgimpl_get_description(
).impl_get_opt_by_path(bypath)
except AttributeError:
return self._find_return_results([], True)
for child in self._impl_children:
@ -698,6 +700,7 @@ class GroupConfig(_CommonConfig):
if isinstance(child, GroupConfig):
ret.extend(child.find_firsts(byname=byname,
bypath=bypath,
byoption=byoption,
byvalue=byvalue,
type_=type_,
display_error=False))
@ -708,7 +711,8 @@ class GroupConfig(_CommonConfig):
f_type = type_
f_ret = child._find(None, byname, byvalue, first=True,
type_=f_type, display_error=False,
only_path=bypath)
only_path=bypath,
only_option=byoption)
if type_ == 'config':
ret.append(child)
else: