From c6c331eb544ab456e4172ccb7b2da1176df0f4f9 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 11 Nov 2014 11:31:23 +0100 Subject: [PATCH] in find_firsts get option only one time --- test/test_dyn_optiondescription.py | 1 + tiramisu/config.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/test_dyn_optiondescription.py b/test/test_dyn_optiondescription.py index d5db882..5b830e5 100644 --- a/test/test_dyn_optiondescription.py +++ b/test/test_dyn_optiondescription.py @@ -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']""" diff --git a/tiramisu/config.py b/tiramisu/config.py index 167cd19..ac4048d 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -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: