From 668705e1e084a28bea06941b6b936c947a4f903a Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 8 Apr 2023 14:15:08 +0200 Subject: [PATCH] api function to remove oboslete settings parameters --- cbpi/__init__.py | 2 +- cbpi/controller/config_controller.py | 12 ++++++++++++ cbpi/http_endpoints/http_config.py | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 6e25b40..29df26c 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.8.a9" +__version__ = "4.1.8.a10" __codename__ = "Groundhog Day" diff --git a/cbpi/controller/config_controller.py b/cbpi/controller/config_controller.py index bb1b5b0..b0324b2 100644 --- a/cbpi/controller/config_controller.py +++ b/cbpi/controller/config_controller.py @@ -78,3 +78,15 @@ class ConfigController: json.dump(data, file, indent=4, sort_keys=True) self.cache=self.testcache + async def remove_obsolete(self): + result = {} + for key, value in self.cache.items(): + if (value.source not in ('craftbeerpi','steps','hidden')): + test = await self.cbpi.plugin.load_plugin_list(value.source) + if test == []: + update=self.get(str(value.source)+'_update') + if update: + await self.remove(str(value.source)+'_update') + await self.remove(key) + result[key] = value.to_dict() + return result \ No newline at end of file diff --git a/cbpi/http_endpoints/http_config.py b/cbpi/http_endpoints/http_config.py index fc2d643..ace5f17 100644 --- a/cbpi/http_endpoints/http_config.py +++ b/cbpi/http_endpoints/http_config.py @@ -102,4 +102,17 @@ class ConfigHttpEndpoints: name = request.match_info['name'] await self.controller.remove(name=name) - return web.Response(status=200) \ No newline at end of file + return web.Response(status=200) + + @request_mapping(path="/obsolete", auth_required=False) + async def http_remove_obsolete(self, request) -> web.Response: + """ + --- + description: Get all config parameters + tags: + - Config + responses: + "200": + description: successful operation + """ + return web.json_response(await self.controller.remove_obsolete(), dumps=json_dumps) \ No newline at end of file