From 251648e9a47c50ce54c2cff1d1fafd039a197e0f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 18 Feb 2021 12:41:25 +0100 Subject: [PATCH] [System] plugins can register a post install routine, for e.g. filling the database. --- flaschengeist/app.py | 6 +++++- flaschengeist/plugins/__init__.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/flaschengeist/app.py b/flaschengeist/app.py index 1a80aa0..c460e99 100644 --- a/flaschengeist/app.py +++ b/flaschengeist/app.py @@ -50,7 +50,7 @@ def __load_plugins(app): app.config["FG_AUTH_BACKEND"] = plugin else: del plugin - else: + if plugin: app.config["FG_PLUGINS"][entry_point.name] = plugin if "FG_AUTH_BACKEND" not in app.config: logger.error("No authentication plugin configured or authentication plugin not found") @@ -61,14 +61,18 @@ def install_all(): db.create_all() db.session.commit() + installed = [] for name, plugin in current_app.config["FG_PLUGINS"].items(): if not plugin: logger.debug("Skip disabled plugin {}".format(name)) continue logger.info("Install plugin {}".format(name)) plugin.install() + installed.append(plugin) if plugin.permissions: roleController.create_permissions(plugin.permissions) + for plugin in installed: + plugin.post_install() def create_app(test_config=None): diff --git a/flaschengeist/plugins/__init__.py b/flaschengeist/plugins/__init__.py index 2aa8234..41a019e 100644 --- a/flaschengeist/plugins/__init__.py +++ b/flaschengeist/plugins/__init__.py @@ -44,6 +44,12 @@ class Plugin: """ pass + def post_install(self): + """Fill database or do other stuff + Called after all plugins are installed + """ + pass + def serialize(self): """Serialize a plugin into a dict