From 8e0fe7727433104735d42c58d0ae8b2c449a7026 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 13 Sep 2021 14:58:11 +0200 Subject: [PATCH] test if a source is loaded --- src/risotto/controller.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/risotto/controller.py b/src/risotto/controller.py index 75f4e50..fe95203 100644 --- a/src/risotto/controller.py +++ b/src/risotto/controller.py @@ -98,10 +98,12 @@ class TiramisuController(Controller): def __init__(self, test: bool, ) -> None: + self.source_imported = None if not 'dataset_name' in vars(self): raise Exception(f'please specify "dataset_name" to "{self.__class__.__name__}"') self.tiramisu_cache_root_path = join(get_config()['cache']['root_path'], self.dataset_name) super().__init__(test) + self.internal_source_name = get_config()['servermodel']['internal_source'] if not test: db_conf = get_config()['database']['tiramisu_dsn'] self.save_storage = Storage(engine='postgres') @@ -130,6 +132,12 @@ class TiramisuController(Controller): risotto_context: Context, ) -> None: sources = await self.get_sources(risotto_context) + source_imported = sources != [self.internal_source_name] + if source_imported and self.source_imported is False: + await self.load_datas(risotto_context) + self.source_imported = source_imported + if not self.source_imported: + return self._aggregate_tiramisu_funcs(sources) self._convert_dictionaries_to_tiramisu(sources) @@ -175,7 +183,9 @@ except: funcs.write(fh.read()) funcs.write(b'\n') - def _convert_dictionaries_to_tiramisu(self, sources: list) -> None: + def _convert_dictionaries_to_tiramisu(self, + sources: list, + ) -> None: funcs_file = join(self.tiramisu_cache_root_path, 'funcs.py') tiramisu_file = join(self.tiramisu_cache_root_path, 'tiramisu.py') dictionaries_dir = join(self.tiramisu_cache_root_path, 'dictionaries')