Compare commits

..

3 Commits

Author SHA1 Message Date
Ferdinand Thiessen 74ceb1b1f3 [cli] Added install command to install the database and all plugins
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
2022-07-31 15:48:47 +02:00
Ferdinand Thiessen 6c73a63eb5 [cli] Make sure plugin permissions are installed
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
2022-07-31 15:45:37 +02:00
Ferdinand Thiessen 3d6b37f0a5 [plugins] Add missing IDs and fix initial migration file
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
2022-07-31 13:22:11 +02:00
2 changed files with 16 additions and 19 deletions

View File

@ -18,28 +18,27 @@ def install_plugin_command(ctx, plugin, all):
"""Install one or more plugins""" """Install one or more plugins"""
if not all and len(plugin) == 0: if not all and len(plugin) == 0:
ctx.fail("At least one plugin must be specified, or use `--all` flag.") ctx.fail("At least one plugin must be specified, or use `--all` flag.")
if all: if all:
plugins = current_app.config["FG_PLUGINS"] plugins = current_app.config["FG_PLUGINS"].values()
else: else:
try: try:
plugins = {plugin_name: current_app.config["FG_PLUGINS"][plugin_name] for plugin_name in plugin} plugins = [current_app.config["FG_PLUGINS"][p] for p in plugin]
except KeyError as e: except KeyError as e:
ctx.fail(f"Invalid plugin name, could not find >{e.args[0]}<") ctx.fail(f"Invalid plugin ID, could not find >{e.args[0]}<")
for p in plugins:
for name, plugin in plugins.items(): name = p.id.split(".")[-1]
click.echo(f"Installing {name}{'.'*(20-len(name))}", nl=False) click.echo(f"Installing {name}{'.'*(20-len(name))}", nl=False)
# Install permissions # Install permissions
if plugin.permissions: if p.permissions:
cur_perm = set(x.name for x in Permission.query.filter(Permission.name.in_(plugin.permissions)).all()) cur_perm = set(x.name for x in Permission.query.filter(Permission.name.in_(p.permissions)).all())
all_perm = set(plugin.permissions) all_perm = set(p.permissions)
add = all_perm - cur_perm add = all_perm - cur_perm
if add: if add:
db.session.bulk_save_objects([Permission(name=x) for x in all_perm]) db.session.bulk_save_objects([Permission(name=x) for x in all_perm])
db.session.commit() db.session.commit()
# Custom installation steps # Custom installation steps
plugin.install() p.install()
click.secho(" ok", fg="green") click.secho(" ok", fg="green")
@ -62,16 +61,14 @@ def uninstall(ctx: click.Context, plugin):
if len(plugin) == 0: if len(plugin) == 0:
ctx.fail("At least one plugin must be specified") ctx.fail("At least one plugin must be specified")
try: try:
plugins = {plugin_name: current_app.config["FG_PLUGINS"][plugin_name] for plugin_name in plugin} plugins = [current_app.config["FG_PLUGINS"][p] for p in plugin]
except KeyError as e: except KeyError as e:
ctx.fail(f"Invalid plugin ID, could not find >{e.args[0]}<") ctx.fail(f"Invalid plugin ID, could not find >{e.args[0]}<")
if ( if (
click.prompt( click.prompt(
"You are going to uninstall:\n\n" "You are going to uninstall:\n\n"
f"\t{', '.join([plugin_name for plugin_name in plugins.keys()])}\n\n" f"\t{', '.join([p.id.split('.')[-1] for p in plugins])}\n\n"
"Are you sure?", "Are you sure?",
default="n", default="n",
show_choices=True, show_choices=True,
@ -80,9 +77,10 @@ def uninstall(ctx: click.Context, plugin):
!= "y" != "y"
): ):
ctx.exit() ctx.exit()
for name, plugin in plugins.items(): for p in plugins:
name = p.id.split(".")[-1]
click.echo(f"Uninstalling {name}{'.'*(20-len(name))}", nl=False) click.echo(f"Uninstalling {name}{'.'*(20-len(name))}", nl=False)
plugin.uninstall() p.uninstall()
click.secho(" ok", fg="green") click.secho(" ok", fg="green")
@ -97,7 +95,7 @@ def ls(enabled, no_header):
return p.version return p.version
plugins = entry_points(group="flaschengeist.plugins") plugins = entry_points(group="flaschengeist.plugins")
enabled_plugins = [key for key, value in config.items() if "enabled" in value and value["enabled"]] + [config["FLASCHENGEIST"]["auth"]] enabled_plugins = [key for key, value in config.items() if "enabled" in value] + [config["FLASCHENGEIST"]["auth"]]
loaded_plugins = current_app.config["FG_PLUGINS"].keys() loaded_plugins = current_app.config["FG_PLUGINS"].keys()
if not no_header: if not no_header:

View File

@ -126,8 +126,7 @@ class Plugin:
def install(self): def install(self):
"""Installation routine """Installation routine
Is always called with Flask application context, Is always called with Flask application context
it is called after the plugin permissions are installed.
""" """
pass pass