Merge remote-tracking branch 'official/master' into develop

This commit is contained in:
Emmanuel Garette 2020-10-14 22:31:54 +02:00
commit 3e0e7244ef
5 changed files with 50 additions and 6 deletions

View File

@ -59,6 +59,16 @@ async def test_copy():
assert not await list_sessions()
@pytest.mark.asyncio
async def test_copy_information():
od = make_description()
async with await Config(od) as cfg:
await cfg.information.set('key', 'value')
async with await cfg.config.copy() as ncfg:
assert await ncfg.information.get('key') == 'value'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_copy_force_store_value():
od = make_description()

View File

@ -654,6 +654,9 @@ class _CommonConfig(SubConfig):
duplicated_settings = duplicated_config.cfgimpl_get_settings()
await duplicated_values._p_.importation(connection,
await self.cfgimpl_get_values()._p_.exportation(connection))
await duplicated_values._p_.importation_informations(connection,
await self.cfgimpl_get_values()._p_.exportation_informations(connection),
)
properties = await self.cfgimpl_get_settings()._p_.exportation(connection)
await duplicated_settings._p_.importation(connection,
properties)

View File

@ -76,17 +76,18 @@ class ChoiceOption(Option):
if isinstance(self._choice_values, Calculation):
return
values = self._choice_values
if values is not undefined and value not in values:
if len(values) == 1:
raise ValueError(_('only "{0}" is allowed'
'').format(values[0]))
raise ValueError(_('only {0} are allowed'
'').format(display_list(values, add_quote=True)))
self.validate_values(value, values)
async def validate_with_option(self,
value: Any,
option_bag: OptionBag) -> None:
values = await self.impl_get_values(option_bag)
self.validate_values(value, values)
def validate_values(self,
value,
values,
) -> None:
if values is not undefined and value not in values:
if len(values) == 1:
raise ValueError(_('only "{0}" is allowed'

View File

@ -293,6 +293,18 @@ class Values:
connection):
self._storage.set_informations({})
async def exportation_informations(self,
connection,
):
return deepcopy(self._storage.get_informations())
async def importation_informations(self,
connection,
informations,
):
#deepcopy(informations)
return self._storage.set_informations(informations)
async def exportation(self,
connection):
return deepcopy(self._storage.get_values())

View File

@ -231,6 +231,24 @@ class Values:
await connection.execute("DELETE FROM information WHERE session_id = $1",
self._storage.database_id)
async def exportation_informations(self,
connection,
):
informations = {}
for path, key, value in await connection.fetch("SELECT path, key, value FROM information WHERE session_id = $1", self._storage.database_id):
path = self._storage.load_path(path)
informations.setdefault(path, {})[key] = loads(value)
return informations
async def importation_informations(self,
connection,
informations,
):
for path, path_infos in informations.items():
for key, value in path_infos.items():
await connection.execute("INSERT INTO information(key, value, session_id, path) VALUES "
"($1, $2, $3, $4)", key, dumps(value), self._storage.database_id, path)
async def exportation(self,
connection):
# log.debug('exportation')