async version of tiramisu
This commit is contained in:
@ -35,14 +35,14 @@ class CacheOptionDescription(BaseOption):
|
||||
def impl_already_build_caches(self) -> bool:
|
||||
return self.impl_is_readonly()
|
||||
|
||||
def _build_cache(self,
|
||||
path='',
|
||||
_consistencies=None,
|
||||
_consistencies_id=0,
|
||||
currpath: List[str]=None,
|
||||
cache_option=None,
|
||||
force_store_values=None,
|
||||
display_name=None) -> None:
|
||||
async def _build_cache(self,
|
||||
path='',
|
||||
_consistencies=None,
|
||||
_consistencies_id=0,
|
||||
currpath: List[str]=None,
|
||||
cache_option=None,
|
||||
force_store_values=None,
|
||||
display_name=None) -> None:
|
||||
"""validate options and set option has readonly option
|
||||
"""
|
||||
# _consistencies is None only when we start to build cache
|
||||
@ -60,20 +60,20 @@ class CacheOptionDescription(BaseOption):
|
||||
# cache already set
|
||||
raise ConfigError(_('option description seems to be part of an other '
|
||||
'config'))
|
||||
for option in self.get_children(config_bag=undefined,
|
||||
dyn=False):
|
||||
for option in await self.get_children(config_bag=undefined,
|
||||
dyn=False):
|
||||
if __debug__:
|
||||
cache_option.append(option)
|
||||
sub_currpath = currpath + [option.impl_getname()]
|
||||
subpath = '.'.join(sub_currpath)
|
||||
if isinstance(option, OptionDescription):
|
||||
option._build_cache(subpath,
|
||||
_consistencies,
|
||||
_consistencies_id,
|
||||
sub_currpath,
|
||||
cache_option,
|
||||
force_store_values,
|
||||
display_name)
|
||||
await option._build_cache(subpath,
|
||||
_consistencies,
|
||||
_consistencies_id,
|
||||
sub_currpath,
|
||||
cache_option,
|
||||
force_store_values,
|
||||
display_name)
|
||||
else:
|
||||
is_multi = option.impl_is_multi()
|
||||
if not option.impl_is_symlinkoption():
|
||||
@ -94,10 +94,6 @@ class CacheOptionDescription(BaseOption):
|
||||
'"force_metaconfig_on_freeze" '
|
||||
'property without "frozen"'
|
||||
'').format(option.impl_get_display_name()))
|
||||
# if context is set to callback, must be reset each time a value change
|
||||
if hasattr(option, '_has_calc_context'):
|
||||
self._add_dependency(option)
|
||||
|
||||
if option.impl_is_readonly():
|
||||
raise ConflictError(_('duplicate option: {0}').format(option))
|
||||
if not self.impl_is_readonly() and display_name:
|
||||
@ -109,17 +105,14 @@ class CacheOptionDescription(BaseOption):
|
||||
self._path = self._name
|
||||
self._set_readonly()
|
||||
|
||||
def impl_build_force_store_values(self,
|
||||
config_bag: ConfigBag) -> None:
|
||||
if not hasattr(self, '_cache_force_store_values'):
|
||||
raise ConfigError(_('option description seems to be part of an other '
|
||||
'config'))
|
||||
async def impl_build_force_store_values(self,
|
||||
config_bag: ConfigBag) -> None:
|
||||
if 'force_store_value' not in config_bag.properties:
|
||||
return
|
||||
commit = False
|
||||
values = config_bag.context.cfgimpl_get_values()
|
||||
for subpath, option in self._cache_force_store_values:
|
||||
if not values._p_.hasvalue(subpath):
|
||||
if not await values._p_.hasvalue(subpath):
|
||||
if option.impl_is_follower():
|
||||
option_bag = OptionBag()
|
||||
leader = option.impl_get_leadership().get_leader()
|
||||
@ -128,7 +121,7 @@ class CacheOptionDescription(BaseOption):
|
||||
None,
|
||||
config_bag)
|
||||
option_bag.properties = frozenset()
|
||||
follower_len = len(values.getvalue(option_bag))
|
||||
follower_len = len(await values.getvalue(option_bag))
|
||||
for index in range(follower_len):
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
@ -136,11 +129,11 @@ class CacheOptionDescription(BaseOption):
|
||||
index,
|
||||
config_bag)
|
||||
option_bag.properties = frozenset()
|
||||
values._p_.setvalue(subpath,
|
||||
values.getvalue(option_bag),
|
||||
owners.forced,
|
||||
index,
|
||||
False)
|
||||
await values._p_.setvalue(subpath,
|
||||
await values.getvalue(option_bag),
|
||||
owners.forced,
|
||||
index,
|
||||
False)
|
||||
else:
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(option,
|
||||
@ -148,24 +141,24 @@ class CacheOptionDescription(BaseOption):
|
||||
None,
|
||||
config_bag)
|
||||
option_bag.properties = frozenset()
|
||||
values._p_.setvalue(subpath,
|
||||
values.getvalue(option_bag),
|
||||
owners.forced,
|
||||
None,
|
||||
False)
|
||||
await values._p_.setvalue(subpath,
|
||||
await values.getvalue(option_bag),
|
||||
owners.forced,
|
||||
None,
|
||||
False)
|
||||
commit = True
|
||||
|
||||
if commit:
|
||||
values._p_.commit()
|
||||
await values._p_.commit()
|
||||
|
||||
|
||||
class OptionDescriptionWalk(CacheOptionDescription):
|
||||
__slots__ = ('_children',)
|
||||
|
||||
def get_child(self,
|
||||
name: str,
|
||||
config_bag: ConfigBag,
|
||||
subpath: str) -> Union[BaseOption, SynDynOptionDescription]:
|
||||
async def get_child(self,
|
||||
name: str,
|
||||
config_bag: ConfigBag,
|
||||
subpath: str) -> Union[BaseOption, SynDynOptionDescription]:
|
||||
# if not dyn
|
||||
if name in self._children[0]:
|
||||
return self._children[1][self._children[0].index(name)]
|
||||
@ -174,7 +167,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
if child.impl_is_dynoptiondescription():
|
||||
cname = child.impl_getname()
|
||||
if name.startswith(cname):
|
||||
for suffix in child.get_suffixes(config_bag):
|
||||
for suffix in await child.get_suffixes(config_bag):
|
||||
if name == cname + child.convert_suffix_to_path(suffix):
|
||||
return child.to_dynoption(subpath,
|
||||
suffix,
|
||||
@ -188,35 +181,37 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
'in optiondescription "{1}"'
|
||||
'').format(name, self.impl_get_display_name()))
|
||||
|
||||
def get_children(self,
|
||||
config_bag: Union[ConfigBag, Undefined],
|
||||
dyn: bool=True) -> Iterator[Union[BaseOption, SynDynOptionDescription]]:
|
||||
async def get_children(self,
|
||||
config_bag: Union[ConfigBag, Undefined],
|
||||
dyn: bool=True) -> Iterator[Union[BaseOption, SynDynOptionDescription]]:
|
||||
if not dyn or config_bag is undefined or \
|
||||
config_bag.context.cfgimpl_get_description() == self:
|
||||
subpath = ''
|
||||
else:
|
||||
subpath = self.impl_getpath()
|
||||
children = []
|
||||
for child in self._children[1]:
|
||||
if dyn and child.impl_is_dynoptiondescription():
|
||||
for suffix in child.get_suffixes(config_bag):
|
||||
yield child.to_dynoption(subpath,
|
||||
suffix,
|
||||
child)
|
||||
for suffix in await child.get_suffixes(config_bag):
|
||||
children.append(child.to_dynoption(subpath,
|
||||
suffix,
|
||||
child))
|
||||
else:
|
||||
yield child
|
||||
children.append(child)
|
||||
return children
|
||||
|
||||
def get_children_recursively(self,
|
||||
bytype: Optional[BaseOption],
|
||||
byname: Optional[str],
|
||||
config_bag: ConfigBag,
|
||||
self_opt: BaseOption=None) -> Iterator[Union[BaseOption, SynDynOptionDescription]]:
|
||||
async def get_children_recursively(self,
|
||||
bytype: Optional[BaseOption],
|
||||
byname: Optional[str],
|
||||
config_bag: ConfigBag,
|
||||
self_opt: BaseOption=None) -> Iterator[Union[BaseOption, SynDynOptionDescription]]:
|
||||
if self_opt is None:
|
||||
self_opt = self
|
||||
for option in self_opt.get_children(config_bag):
|
||||
for option in await self_opt.get_children(config_bag):
|
||||
if option.impl_is_optiondescription():
|
||||
for subopt in option.get_children_recursively(bytype,
|
||||
byname,
|
||||
config_bag):
|
||||
async for subopt in option.get_children_recursively(bytype,
|
||||
byname,
|
||||
config_bag):
|
||||
yield subopt
|
||||
elif (byname is None or option.impl_getname() == byname) and \
|
||||
(bytype is None or isinstance(option, bytype)):
|
||||
|
Reference in New Issue
Block a user