option's informations avalaible in config
This commit is contained in:
parent
49ba56b6ec
commit
8658fdd6ca
6 changed files with 49 additions and 29 deletions
|
@ -154,10 +154,10 @@ async def test_information_config():
|
||||||
async with await Config(descr) as cfg:
|
async with await Config(descr) as cfg:
|
||||||
string = 'some informations'
|
string = 'some informations'
|
||||||
#
|
#
|
||||||
assert list(await cfg.information.list()) == []
|
assert list(await cfg.information.list()) == ['doc']
|
||||||
await cfg.information.set('info', string)
|
await cfg.information.set('info', string)
|
||||||
assert await cfg.information.get('info') == string
|
assert await cfg.information.get('info') == string
|
||||||
assert list(await cfg.information.list()) == ['info']
|
assert set(await cfg.information.list()) == {'doc', 'info'}
|
||||||
#
|
#
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
await cfg.information.get('noinfo')
|
await cfg.information.get('noinfo')
|
||||||
|
@ -167,7 +167,7 @@ async def test_information_config():
|
||||||
await cfg.information.get('info')
|
await cfg.information.get('info')
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
await cfg.information.reset('noinfo')
|
await cfg.information.reset('noinfo')
|
||||||
assert list(await cfg.information.list()) == []
|
assert list(await cfg.information.list()) == ['doc']
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,10 +177,10 @@ async def test_information_option():
|
||||||
async with await Config(descr) as cfg:
|
async with await Config(descr) as cfg:
|
||||||
string = 'some informations'
|
string = 'some informations'
|
||||||
#
|
#
|
||||||
list(await cfg.option('gc.name').information.list()) == []
|
assert list(await cfg.option('gc.name').information.list()) == ['doc']
|
||||||
await cfg.option('gc.name').information.set('info', string)
|
await cfg.option('gc.name').information.set('info', string)
|
||||||
assert await cfg.option('gc.name').information.get('info') == string
|
assert await cfg.option('gc.name').information.get('info') == string
|
||||||
list(await cfg.option('gc.name').information.list()) == ['info']
|
assert set(await cfg.option('gc.name').information.list()) == {'doc', 'info'}
|
||||||
#
|
#
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
await cfg.option('gc.name').information.get('noinfo')
|
await cfg.option('gc.name').information.get('noinfo')
|
||||||
|
@ -190,7 +190,7 @@ async def test_information_option():
|
||||||
await cfg.option('gc.name').information.get('info')
|
await cfg.option('gc.name').information.get('info')
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
await cfg.option('gc.name').information.reset('noinfo')
|
await cfg.option('gc.name').information.reset('noinfo')
|
||||||
list(await cfg.option('gc.name').information.list()) == []
|
assert list(await cfg.option('gc.name').information.list()) == ['doc']
|
||||||
#
|
#
|
||||||
assert await cfg.option('wantref').information.get('info') == 'default value'
|
assert await cfg.option('wantref').information.get('info') == 'default value'
|
||||||
await cfg.option('wantref').information.set('info', 'default value')
|
await cfg.option('wantref').information.set('info', 'default value')
|
||||||
|
|
|
@ -92,7 +92,8 @@ class CommonTiramisu(TiramisuHelp):
|
||||||
try:
|
try:
|
||||||
subconfig, name = await config_bag.context.cfgimpl_get_home_by_path(self._option_bag.path,
|
subconfig, name = await config_bag.context.cfgimpl_get_home_by_path(self._option_bag.path,
|
||||||
config_bag,
|
config_bag,
|
||||||
validate_properties=self._validate_properties)
|
validate_properties=self._validate_properties,
|
||||||
|
)
|
||||||
except AssertionError as err:
|
except AssertionError as err:
|
||||||
raise APIError(str(err))
|
raise APIError(str(err))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -465,11 +466,14 @@ class TiramisuOptionInformation(CommonTiramisuOption):
|
||||||
async def get(self, key, default=undefined):
|
async def get(self, key, default=undefined):
|
||||||
"""Get information"""
|
"""Get information"""
|
||||||
values = self._option_bag.config_bag.context.cfgimpl_get_values()
|
values = self._option_bag.config_bag.context.cfgimpl_get_values()
|
||||||
return await values.get_information(self._option_bag.config_bag,
|
try:
|
||||||
self._option_bag,
|
return await values.get_information(self._option_bag.config_bag,
|
||||||
key,
|
self._option_bag,
|
||||||
default,
|
key,
|
||||||
)
|
undefined,
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
return self._option_bag.option.impl_get_information(key, default)
|
||||||
|
|
||||||
@option_and_connection
|
@option_and_connection
|
||||||
async def set(self, key, value):
|
async def set(self, key, value):
|
||||||
|
@ -498,8 +502,11 @@ class TiramisuOptionInformation(CommonTiramisuOption):
|
||||||
"""List information's keys"""
|
"""List information's keys"""
|
||||||
path = self._option_bag.path
|
path = self._option_bag.path
|
||||||
values = self._option_bag.config_bag.context.cfgimpl_get_values()
|
values = self._option_bag.config_bag.context.cfgimpl_get_values()
|
||||||
return await values.list_information(self._option_bag.config_bag.connection,
|
lst1 = set(self._option_bag.option.impl_list_information())
|
||||||
path)
|
lst2 = set(await values.list_information(self._option_bag.config_bag.connection,
|
||||||
|
path,
|
||||||
|
))
|
||||||
|
return lst1 | lst2
|
||||||
#
|
#
|
||||||
# async def len(self):
|
# async def len(self):
|
||||||
# """Length of leadership"""
|
# """Length of leadership"""
|
||||||
|
@ -588,7 +595,8 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||||
if self._option_bag.option.impl_is_follower() and self._option_bag.index is None:
|
if self._option_bag.option.impl_is_follower() and self._option_bag.index is None:
|
||||||
raise APIError('index must be set with a follower option')
|
raise APIError('index must be set with a follower option')
|
||||||
return await self._subconfig.getattr(self._name,
|
return await self._subconfig.getattr(self._name,
|
||||||
self._option_bag)
|
self._option_bag,
|
||||||
|
)
|
||||||
|
|
||||||
@option_type('option')
|
@option_type('option')
|
||||||
async def set(self, value):
|
async def set(self, value):
|
||||||
|
@ -891,11 +899,14 @@ class TiramisuContextInformation(TiramisuConfig):
|
||||||
):
|
):
|
||||||
"""Get an information"""
|
"""Get an information"""
|
||||||
values = self._config_bag.context.cfgimpl_get_values()
|
values = self._config_bag.context.cfgimpl_get_values()
|
||||||
return await values.get_information(self._config_bag,
|
try:
|
||||||
None,
|
return await values.get_information(self._config_bag,
|
||||||
name,
|
None,
|
||||||
default,
|
name,
|
||||||
)
|
undefined,
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
return self._config_bag.context.cfgimpl_get_description().impl_get_information(name, default)
|
||||||
|
|
||||||
@connection
|
@connection
|
||||||
async def set(self,
|
async def set(self,
|
||||||
|
@ -920,7 +931,9 @@ class TiramisuContextInformation(TiramisuConfig):
|
||||||
@connection
|
@connection
|
||||||
async def list(self):
|
async def list(self):
|
||||||
"""List information's keys"""
|
"""List information's keys"""
|
||||||
return await self._config_bag.context.impl_list_information(self._config_bag.connection)
|
lst1 = set(self._config_bag.context.cfgimpl_get_description().impl_list_information())
|
||||||
|
lst2 = set(await self._config_bag.context.impl_list_information(self._config_bag.connection))
|
||||||
|
return lst1 | lst2
|
||||||
|
|
||||||
@connection
|
@connection
|
||||||
async def exportation(self):
|
async def exportation(self):
|
||||||
|
|
|
@ -193,7 +193,6 @@ class ValueWarning(_CommonError, UserWarning):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if len(args) == 1 and not kwargs:
|
if len(args) == 1 and not kwargs:
|
||||||
self.msg = args[0]
|
self.msg = args[0]
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.msg = None
|
self.msg = None
|
||||||
|
|
|
@ -203,7 +203,8 @@ class Base:
|
||||||
# information
|
# information
|
||||||
def impl_get_information(self,
|
def impl_get_information(self,
|
||||||
key: str,
|
key: str,
|
||||||
default: Any=undefined) -> Any:
|
default: Any=undefined,
|
||||||
|
) -> Any:
|
||||||
"""retrieves one information's item
|
"""retrieves one information's item
|
||||||
|
|
||||||
:param key: the item string (ex: "help")
|
:param key: the item string (ex: "help")
|
||||||
|
@ -225,7 +226,8 @@ class Base:
|
||||||
|
|
||||||
def impl_set_information(self,
|
def impl_set_information(self,
|
||||||
key: str,
|
key: str,
|
||||||
value: Any) -> None:
|
value: Any,
|
||||||
|
) -> None:
|
||||||
"""updates the information's attribute
|
"""updates the information's attribute
|
||||||
(which is a dictionary)
|
(which is a dictionary)
|
||||||
|
|
||||||
|
@ -239,6 +241,15 @@ class Base:
|
||||||
key))
|
key))
|
||||||
self._informations[key] = value
|
self._informations[key] = value
|
||||||
|
|
||||||
|
def impl_list_information(self) -> Any:
|
||||||
|
dico = self._informations
|
||||||
|
if isinstance(dico, tuple):
|
||||||
|
return list(dico[0])
|
||||||
|
elif isinstance(dico, str):
|
||||||
|
return ['doc']
|
||||||
|
# it's a dict
|
||||||
|
return list(dico.keys())
|
||||||
|
|
||||||
|
|
||||||
class BaseOption(Base):
|
class BaseOption(Base):
|
||||||
"""This abstract base class stands for attribute access
|
"""This abstract base class stands for attribute access
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Cache(DictCache):
|
||||||
# so value is self_props
|
# so value is self_props
|
||||||
self_props = value
|
self_props = value
|
||||||
# recheck "cache" value
|
# recheck "cache" value
|
||||||
if 'cache' in props or 'cache' in props:
|
if 'cache' in props:
|
||||||
if expiration_time and timestamp and \
|
if expiration_time and timestamp and \
|
||||||
('expire' in props or \
|
('expire' in props or \
|
||||||
'expire' in self_props):
|
'expire' in self_props):
|
||||||
|
@ -69,8 +69,6 @@ class Cache(DictCache):
|
||||||
# else:
|
# else:
|
||||||
# log.debug('getcache expired value for path %s < %s',
|
# log.debug('getcache expired value for path %s < %s',
|
||||||
# timestamp + expiration_time, ntime)
|
# timestamp + expiration_time, ntime)
|
||||||
# if expired, remove from cache
|
|
||||||
# self.delcache(path)
|
|
||||||
else:
|
else:
|
||||||
# log.debug('getcache in cache (2) %s %s %s %s %s', path, value, _display_classname(self),
|
# log.debug('getcache in cache (2) %s %s %s %s %s', path, value, _display_classname(self),
|
||||||
# id(self), index)
|
# id(self), index)
|
||||||
|
|
|
@ -77,7 +77,6 @@ class Values:
|
||||||
a specified value must be associated to an owner
|
a specified value must be associated to an owner
|
||||||
"""
|
"""
|
||||||
log.debug('setvalue %s %s %s %s %s', path, value, owner, index, id(self))
|
log.debug('setvalue %s %s %s %s %s', path, value, owner, index, id(self))
|
||||||
|
|
||||||
#if isinstance(value, list):
|
#if isinstance(value, list):
|
||||||
# value = value
|
# value = value
|
||||||
values = self._storage.get_values()
|
values = self._storage.get_values()
|
||||||
|
@ -281,7 +280,7 @@ class Values:
|
||||||
path):
|
path):
|
||||||
informations = self._storage.get_informations()
|
informations = self._storage.get_informations()
|
||||||
if path in informations:
|
if path in informations:
|
||||||
return informations[path].keys()
|
return list(informations[path].keys())
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue