simplify set with undefined

This commit is contained in:
Emmanuel Garette 2018-09-29 08:27:00 +02:00
parent 242615f68b
commit 996a6c7303
2 changed files with 19 additions and 34 deletions

View File

@ -427,14 +427,9 @@ class TiramisuOptionValue(CommonTiramisuOption):
if isinstance(value, list): if isinstance(value, list):
while undefined in value: while undefined in value:
idx = value.index(undefined) idx = value.index(undefined)
option_bag = OptionBag() value[idx] = values.getdefaultvalue(self.option_bag,
option_bag.set_option(self.option_bag.option, force_index=idx)
self.option_bag.path, elif value == undefined:
idx,
self.option_bag.config_bag)
value[idx] = values.getdefaultvalue(option_bag)
else:
if value == undefined:
value = values.getdefaultvalue(self.option_bag) value = values.getdefaultvalue(self.option_bag)
self.subconfig.setattr(value, self.subconfig.setattr(value,
self.option_bag) self.option_bag)
@ -956,8 +951,7 @@ class TiramisuContextOption(TiramisuContext):
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
else: elif type == 'optiondescription':
if type == 'optiondescription':
continue continue
path = opt.impl_getpath() path = opt.impl_getpath()
subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path, subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# ____________________________________________________________ # ____________________________________________________________
import weakref import weakref
from typing import Optional
from .error import ConfigError, PropertiesOptionError from .error import ConfigError, PropertiesOptionError
from .setting import owners, expires_time, undefined, forbidden_owners, OptionBag, ConfigBag from .setting import owners, expires_time, undefined, forbidden_owners, OptionBag, ConfigBag
from .autolib import carry_out_calculation from .autolib import carry_out_calculation
@ -124,7 +125,8 @@ class Values(object):
return self.getdefaultvalue(option_bag) return self.getdefaultvalue(option_bag)
def getdefaultvalue(self, def getdefaultvalue(self,
option_bag): option_bag,
force_index: Optional[int]=None):
"""get default value: """get default value:
- get meta config value or - get meta config value or
- get calculated value or - get calculated value or
@ -140,6 +142,8 @@ class Values(object):
context = config_bag.context context = config_bag.context
opt = option_bag.option opt = option_bag.option
index = option_bag.index index = option_bag.index
if force_index is not None:
index = force_index
def _reset_cache(_value): def _reset_cache(_value):
if not 'expire' in option_bag.properties: if not 'expire' in option_bag.properties:
return return
@ -156,24 +160,11 @@ class Values(object):
# calculated value is a new value, so reset cache # calculated value is a new value, so reset cache
context.cfgimpl_reset_cache(option_bag) context.cfgimpl_reset_cache(option_bag)
if opt.impl_is_master_slaves('slave'): if self._is_meta(option_bag):
index_ = index option_bag.properties = frozenset()
else:
index_ = None
if option_bag.index != index_:
moption_bag = OptionBag()
moption_bag.set_option(opt,
option_bag.path,
index_,
config_bag)
moption_bag.fromconsistency = option_bag.fromconsistency.copy()
else:
moption_bag = option_bag
if self._is_meta(moption_bag):
moption_bag.properties = frozenset()
meta = context.cfgimpl_get_meta() meta = context.cfgimpl_get_meta()
# retrieved value from meta config # retrieved value from meta config
return meta.cfgimpl_get_values().get_cached_value(moption_bag) return meta.cfgimpl_get_values().get_cached_value(option_bag)
if opt.impl_has_callback(): if opt.impl_has_callback():
# if value has callback, calculate value # if value has callback, calculate value
@ -390,13 +381,13 @@ class Values(object):
owners.default, owners.default,
index=option_bag.index) index=option_bag.index)
if owner is owners.default and validate_meta is not False and self._is_meta(option_bag): if owner is owners.default and validate_meta is not False and self._is_meta(option_bag):
moption_bag = option_bag.copy() option_bag = option_bag.copy()
moption_bag.properties = frozenset() option_bag.properties = frozenset()
config_bag = moption_bag.config_bag.copy() config_bag = option_bag.config_bag.copy()
meta = context.cfgimpl_get_meta() meta = context.cfgimpl_get_meta()
config_bag.context = meta config_bag.context = meta
moption_bag.config_bag = config_bag option_bag.config_bag = config_bag
owner = meta.cfgimpl_get_values().getowner(moption_bag, owner = meta.cfgimpl_get_values().getowner(option_bag,
only_default=only_default) only_default=only_default)
return owner return owner