optimize option.list() with recursive attribute

This commit is contained in:
Emmanuel Garette 2018-11-17 12:08:15 +01:00
parent 9bc3c7a056
commit 7ae91b0f4e
4 changed files with 25 additions and 28 deletions

View File

@ -141,7 +141,7 @@ def test_slots_config():
'a',
None,
ConfigBag(c._config_bag.context))
sc = c._config_bag.context.get_subconfig('a', option_bag)
sc = c._config_bag.context.get_subconfig(option_bag)
assert isinstance(sc, SubConfig)
raises(AttributeError, "sc.x = 1")
raises(AttributeError, "sc.cfgimpl_x = 1")

View File

@ -500,8 +500,7 @@ class _TiramisuOptionValueOptionDescription:
"""Dict with path as key and value"""
self._get_option()
name = self._option_bag.option.impl_getname()
subconfig = self._subconfig.get_subconfig(name,
self._option_bag)
subconfig = self._subconfig.get_subconfig(self._option_bag)
config_bag = self._option_bag.config_bag
if config_bag.properties and 'warnings' in config_bag.properties:
config_bag = config_bag.copy()
@ -607,8 +606,7 @@ class _TiramisuOptionDescription(_TiramisuOption):
path,
None,
self._config_bag)
subconfig = self._subconfig.get_subconfig(oname,
option_bag)
subconfig = self._subconfig.get_subconfig(option_bag)
for path in subconfig.find(byname=name,
byvalue=value,
bytype=type,
@ -665,8 +663,7 @@ class _TiramisuOptionDescription(_TiramisuOption):
None,
self._config_bag)
if opt.impl_is_optiondescription():
self._subconfig.get_subconfig(name,
option_bag)
self._subconfig.get_subconfig(option_bag)
else:
subconfig.getattr(name,
option_bag)
@ -686,12 +683,11 @@ class _TiramisuOptionDescription(_TiramisuOption):
path,
None,
self._config_bag)
subconfig = self._subconfig.get_subconfig(name,
option_bag)
subconfig = self._subconfig.get_subconfig(option_bag)
for opt in option.get_children(self._config_bag):
try:
subsubconfig = self._filter(opt,
subconfig)
self._filter(opt,
subconfig)
except PropertiesOptionError:
continue
if opt.impl_is_optiondescription():
@ -1006,27 +1002,30 @@ class TiramisuContextOption(TiramisuContext):
return self._find(name, value, type)
def _filter(self,
opt):
opt,
subconfig):
if self._config_bag.properties:
option_bag = OptionBag()
path = opt.impl_getpath()
option_bag.set_option(opt,
path,
opt.impl_getpath(),
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(path,
option_bag)
return subconfig.get_subconfig(option_bag)
subconfig.getattr(opt.impl_getname(),
option_bag)
def _walk(self,
option,
recursive,
type_,
group_type):
group_type,
subconfig):
for opt in option.get_children(self._config_bag):
try:
subsubconfig = self._filter(opt)
subsubconfig = self._filter(opt,
subconfig)
except PropertiesOptionError:
continue
if opt.impl_is_optiondescription():
@ -1034,16 +1033,16 @@ class TiramisuContextOption(TiramisuContext):
for toption in self._walk(opt,
recursive,
type_,
group_type):
group_type,
subsubconfig):
yield toption
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()
path = opt.impl_getpath()
subconfig, name = self._config_bag.context.cfgimpl_get_home_by_path(path,
self._config_bag)
yield TiramisuOption(name,
path,
None,
@ -1062,7 +1061,8 @@ class TiramisuContextOption(TiramisuContext):
for toption in self._walk(option,
recursive,
type,
group_type):
group_type,
self._config_bag.context):
yield toption

View File

@ -210,8 +210,7 @@ class SubConfig(object):
config_bag)
if fromconsistency is not None:
option_bag.fromconsistency = fromconsistency
self = self.get_subconfig(step,
option_bag)
self = self.get_subconfig(option_bag)
assert isinstance(self, SubConfig), _('unknown option {}').format(path[-1])
return self, path[-1]
@ -268,7 +267,6 @@ class SubConfig(object):
return subpath
def get_subconfig(self,
name,
option_bag):
if option_bag.fromconsistency:
fromconsistency = option_bag.fromconsistency.copy()

View File

@ -538,8 +538,7 @@ class Values(object):
path,
None,
od_config_bag)
subsubconfig = subconfig.get_subconfig(name,
option_bag)
subsubconfig = subconfig.get_subconfig(option_bag)
except PropertiesOptionError as err:
pass
else: