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', 'a',
None, None,
ConfigBag(c._config_bag.context)) 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) assert isinstance(sc, SubConfig)
raises(AttributeError, "sc.x = 1") raises(AttributeError, "sc.x = 1")
raises(AttributeError, "sc.cfgimpl_x = 1") raises(AttributeError, "sc.cfgimpl_x = 1")

View File

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

View File

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

View File

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