Compare commits
3 Commits
e9fbce0da7
...
74ceb1b1f3
Author | SHA1 | Date |
---|---|---|
|
74ceb1b1f3 | |
|
6c73a63eb5 | |
|
3d6b37f0a5 |
flaschengeist
|
@ -18,28 +18,27 @@ def install_plugin_command(ctx, plugin, all):
|
|||
"""Install one or more plugins"""
|
||||
if not all and len(plugin) == 0:
|
||||
ctx.fail("At least one plugin must be specified, or use `--all` flag.")
|
||||
|
||||
if all:
|
||||
plugins = current_app.config["FG_PLUGINS"]
|
||||
plugins = current_app.config["FG_PLUGINS"].values()
|
||||
else:
|
||||
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:
|
||||
ctx.fail(f"Invalid plugin name, could not find >{e.args[0]}<")
|
||||
|
||||
for name, plugin in plugins.items():
|
||||
ctx.fail(f"Invalid plugin ID, could not find >{e.args[0]}<")
|
||||
for p in plugins:
|
||||
name = p.id.split(".")[-1]
|
||||
click.echo(f"Installing {name}{'.'*(20-len(name))}", nl=False)
|
||||
# Install permissions
|
||||
if plugin.permissions:
|
||||
cur_perm = set(x.name for x in Permission.query.filter(Permission.name.in_(plugin.permissions)).all())
|
||||
all_perm = set(plugin.permissions)
|
||||
if p.permissions:
|
||||
cur_perm = set(x.name for x in Permission.query.filter(Permission.name.in_(p.permissions)).all())
|
||||
all_perm = set(p.permissions)
|
||||
|
||||
add = all_perm - cur_perm
|
||||
if add:
|
||||
db.session.bulk_save_objects([Permission(name=x) for x in all_perm])
|
||||
db.session.commit()
|
||||
# Custom installation steps
|
||||
plugin.install()
|
||||
p.install()
|
||||
click.secho(" ok", fg="green")
|
||||
|
||||
|
||||
|
@ -62,16 +61,14 @@ def uninstall(ctx: click.Context, plugin):
|
|||
|
||||
if len(plugin) == 0:
|
||||
ctx.fail("At least one plugin must be specified")
|
||||
|
||||
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:
|
||||
ctx.fail(f"Invalid plugin ID, could not find >{e.args[0]}<")
|
||||
|
||||
if (
|
||||
click.prompt(
|
||||
"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?",
|
||||
default="n",
|
||||
show_choices=True,
|
||||
|
@ -80,9 +77,10 @@ def uninstall(ctx: click.Context, plugin):
|
|||
!= "y"
|
||||
):
|
||||
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)
|
||||
plugin.uninstall()
|
||||
p.uninstall()
|
||||
click.secho(" ok", fg="green")
|
||||
|
||||
|
||||
|
@ -97,7 +95,7 @@ def ls(enabled, no_header):
|
|||
return p.version
|
||||
|
||||
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()
|
||||
|
||||
if not no_header:
|
||||
|
|
|
@ -126,8 +126,7 @@ class Plugin:
|
|||
def install(self):
|
||||
"""Installation routine
|
||||
|
||||
Is always called with Flask application context,
|
||||
it is called after the plugin permissions are installed.
|
||||
Is always called with Flask application context
|
||||
"""
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue