From 64017d5cd4a42f1cffb83501371e15c72b061534 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 18 May 2021 18:53:14 +0200 Subject: [PATCH] import/export informations --- tiramisu/api.py | 13 ++++++++++++- tiramisu/autolib.py | 7 ++++--- tiramisu/storage/postgres/value.py | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tiramisu/api.py b/tiramisu/api.py index c1dd4e8..1448baa 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -484,7 +484,8 @@ class TiramisuOptionInformation(CommonTiramisuOption): @option_and_connection async def reset(self, - key): + key: str, + ) -> None: """Remove information""" path = self._option_bag.path values = self._option_bag.config_bag.context.cfgimpl_get_values() @@ -921,6 +922,16 @@ class TiramisuContextInformation(TiramisuConfig): """List information's keys""" return await self._config_bag.context.impl_list_information(self._config_bag.connection) + @connection + async def exportation(self): + """Export all informations""" + return await self._config_bag.context.cfgimpl_get_values()._p_.exportation_informations(self._config_bag.connection) + + @connection + async def importation(self, informations): + """Import informations""" + return await self._config_bag.context.cfgimpl_get_values()._p_.importation_informations(self._config_bag.connection, informations) + class TiramisuContextValue(TiramisuConfig): """Manage config value""" diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index 18f589a..9e4ac0c 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -358,10 +358,11 @@ async def manager_callback(callbk: Param, suffix = callbk.suffix else: if not option.impl_is_dynsymlinkoption(): - msg = 'option "{}" is not dynamic in callback of the option "{}"' - raise ConfigError(_(msg).format(callbk_option.impl_get_display_name(), - option.impl_get_display_name(), + msg = 'option "{}" is not dynamic but is an argument of the dynamic option "{}" in a callback' + raise ConfigError(_(msg).format(option.impl_get_display_name(), + callbk_option.impl_get_display_name(), )) + #FIXME in same dynamic option? rootpath = option.rootpath suffix = option.impl_getsuffix() subdyn = callbk_option.getsubdyn() diff --git a/tiramisu/storage/postgres/value.py b/tiramisu/storage/postgres/value.py index 2f3f5c5..7f18177 100644 --- a/tiramisu/storage/postgres/value.py +++ b/tiramisu/storage/postgres/value.py @@ -240,7 +240,9 @@ class Values: connection, informations, ): + await self.del_informations(connection) for path, path_infos in informations.items(): + path = self._storage.convert_path(path) 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)