diff --git a/GTG/backends/__init__.py b/GTG/backends/__init__.py index d7b740e78f..683a09564f 100644 --- a/GTG/backends/__init__.py +++ b/GTG/backends/__init__.py @@ -138,8 +138,8 @@ def get_saved_backends_list(self): config = CoreConfig() backends = [] - for backend in config.get_all_backends(): - settings = config.get_backend_config(backend) + for backend_id in config.get_all_backends(): + settings = config.get_backend_config(backend_id) module = self.get_backend(settings.get('module')) # Skip this backend if it doesn't have a module @@ -167,7 +167,11 @@ def get_saved_backends_list(self): # Parameter not found in config pass - backend_data['backend'] = module.Backend(backend_data) + backend = backend_data['backend'] = module.Backend(backend_data) + + # Rename configuration sections created by older versions of GTG + config.rename_backend_section(backend.get_name(), backend.get_id()) + backends.append(backend_data) # If no backend available, we create a new using localfile. Dic diff --git a/GTG/core/config.py b/GTG/core/config.py index 70215ca904..ad809eef2c 100644 --- a/GTG/core/config.py +++ b/GTG/core/config.py @@ -228,16 +228,25 @@ def get_task_config(self, task_id): DEFAULTS['task'], self.save_task_config) + def rename_backend_section(self, backend_name, backend_id): + """Rename section `backend_name` to `backend_id` if it exists.""" + if backend_name in self._backends_conf: + assert backend_id not in self._backends_conf + self._backends_conf.add_section(backend_id) + for (k, v) in self._backends_conf[backend_name].items(): + self._backends_conf.set(backend_id, k, v) + self._backends_conf.remove_section(backend_name) + def get_all_backends(self): return self._backends_conf.sections() - def get_backend_config(self, backend): - if backend not in self._backends_conf: - self._backends_conf.add_section(backend) + def get_backend_config(self, backend_id): + if backend_id not in self._backends_conf: + self._backends_conf.add_section(backend_id) return SectionConfig( - f'Backend {backend}', - self._backends_conf[backend], + f'Backend {backend_id}', + self._backends_conf[backend_id], DEFAULTS['backend'], self.save_backends_config) diff --git a/GTG/core/datastore.py b/GTG/core/datastore.py index eb4a7d3643..eb76de65e2 100644 --- a/GTG/core/datastore.py +++ b/GTG/core/datastore.py @@ -621,7 +621,7 @@ def save(self, quit=False): # we save the parameters for b in self.get_all_backends(disabled=True): - config = self.conf.get_backend_config(b.get_name()) + config = self.conf.get_backend_config(b.get_id()) for key, value in b.get_parameters().items():