Exemplo n.º 1
0
def enable_plugin(plugin):
    plugin = get_plugin_from_all(plugin)
    if not plugin.enabled:
        plugin_dir = os.path.join(
            os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "plugins", plugin.identifier
        )

        disabled_file = os.path.join(plugin_dir, "DISABLED")

        try:
            if os.path.exists(disabled_file):
                os.remove(disabled_file)
                flash(_("Plugin is enabled. Please reload your app."), "success")
            else:
                flash(_("Plugin is already enabled. Please reload  your app."), "warning")

        except OSError:
            flash(
                _(
                    "If you are using a host which doesn't support writting "
                    "on the disk, this won't work - than you need to delete "
                    "the 'DISABLED' file by yourself."
                ),
                "danger",
            )

    else:
        flash(_("Couldn't enable Plugin."), "danger")

    return redirect(url_for("management.plugins"))
Exemplo n.º 2
0
def enable_plugin(plugin):
    plugin = get_plugin_from_all(plugin)
    if not plugin.enabled:
        plugin_dir = os.path.join(
            os.path.abspath(os.path.dirname(os.path.dirname(__file__))),
            "plugins", plugin.identifier)

        disabled_file = os.path.join(plugin_dir, "DISABLED")

        try:
            if os.path.exists(disabled_file):
                os.remove(disabled_file)
                flash(_("Plugin is enabled. Please reload your app."),
                      "success")
            else:
                flash(_("Plugin is already enabled. Please reload  your app."),
                      "warning")

        except OSError:
            flash(
                _("If you are using a host which doesn't support writting "
                  "on the disk, this won't work - than you need to delete "
                  "the 'DISABLED' file by yourself."), "danger")

    else:
        flash(_("Couldn't enable Plugin."), "danger")

    return redirect(url_for("management.plugins"))
Exemplo n.º 3
0
def _disable_plugins():
    plugin = request.args.get('disableplugins', 0, type=str)
    pluginsmanager = PluginManager()
    try:
        pluginsmanager.disable_plugins([get_plugin_from_all(plugin)])
    except KeyError:
        pass
    return jsonify(success=True)
Exemplo n.º 4
0
def uninstall_plugin(plugin_identifier):
    """Uninstalls a plugin from FlaskBB."""
    validate_plugin(plugin_identifier)
    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Uninstalling plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin_manager.uninstall_plugins([plugin])
    except AttributeError:
        pass
Exemplo n.º 5
0
def upgrade_plugin(plugin_identifier):
    """Uninstalls a plugin from FlaskBB."""
    validate_plugin(plugin_identifier)
    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Upgrading plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin.upgrade_database()
    except AttributeError:
        pass
Exemplo n.º 6
0
def uninstall_plugin(plugin_identifier):
    """Uninstalls a plugin from FlaskBB."""
    validate_plugin(plugin_identifier)
    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Uninstalling plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin_manager.uninstall_plugins([plugin])
    except AttributeError:
        pass
Exemplo n.º 7
0
def install_plugin(plugin_identifier):
    """Installs a new plugin."""
    validate_plugin(plugin_identifier)
    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Installing plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin_manager.install_plugins([plugin])
    except Exception as e:
        click.secho("[-] Couldn't install plugin because of following "
                    "exception: \n{}".format(e), fg="red")
Exemplo n.º 8
0
def migrate_plugin(plugin_identifier):
    """Installs a new plugin."""
    validate_plugin(plugin_identifier)
    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Updating plugin migrations{}...".format(plugin.name), fg="cyan")
    try:
        plugin.migrate()
    except Exception as e:
        click.secho("[-] Couldn't generate migrations for plugin because of following "
                    "exception: \n{}".format(e), fg="red")
Exemplo n.º 9
0
def install_plugin(plugin_identifier):
    """Installs a new plugin."""
    validate_plugin(plugin_identifier)
    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Installing plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin_manager.install_plugins([plugin])
    except Exception as e:
        click.secho("[-] Couldn't install plugin because of following "
                    "exception: \n{}".format(e), fg="red")
Exemplo n.º 10
0
def install_plugin(plugin):
    plugin = get_plugin_from_all(plugin)
    if plugin.installable and not plugin.uninstallable:
        plugin.install()
        Setting.invalidate_cache()

        flash(_("Plugin has been installed."), "success")
    else:
        flash(_("Cannot install Plugin."), "danger")

    return redirect(url_for("management.plugins"))
Exemplo n.º 11
0
def install_plugin(plugin):
    plugin = get_plugin_from_all(plugin)
    if plugin.installable and not plugin.uninstallable:
        plugin.install()
        Setting.invalidate_cache()

        flash(_("Plugin has been installed."), "success")
    else:
        flash(_("Cannot install Plugin."), "danger")

    return redirect(url_for("management.plugins"))
Exemplo n.º 12
0
    def post(self, plugin):
        plugin = get_plugin_from_all(plugin)
        if not plugin.installed:
            plugin.install()
            Setting.invalidate_cache()

            flash(_("Plugin has been installed."), "success")
        else:
            flash(_("Cannot install plugin."), "danger")

        return redirect(url_for("management.plugins"))
Exemplo n.º 13
0
def enable_plugin(plugin):
    plugin = get_plugin_from_all(plugin)

    if plugin.enabled:
        flash(_("Plugin is already enabled."), "danger")
        return redirect(url_for("management.plugins"))

    try:
        plugin.enable()
        flash(_("Plugin %(plugin)s enabled. Please restart FlaskBB now.",
                plugin=plugin.name), "success")
    except OSError:
        flash(_("It seems that FlaskBB does not have enough filesystem "
                "permissions. Try removing the 'DISABLED' file by "
                "yourself."), "danger")

    return redirect(url_for("management.plugins"))
Exemplo n.º 14
0
def enable_plugin(plugin):
    plugin = get_plugin_from_all(plugin)

    if plugin.enabled:
        flash(_("Plugin %(plugin)s is already enabled.", plugin=plugin.name),
              "info")
        return redirect(url_for("management.plugins"))

    try:
        plugin.enable()
        flash(_("Plugin %(plugin)s enabled. Please restart FlaskBB now.",
                plugin=plugin.name), "success")
    except OSError:
        flash(_("It seems that FlaskBB does not have enough filesystem "
                "permissions. Try removing the 'DISABLED' file by "
                "yourself instead."), "danger")

    return redirect(url_for("management.plugins"))
Exemplo n.º 15
0
def remove_plugin(plugin_identifier, force):
    """Removes a plugin from the filesystem."""
    validate_plugin(plugin_identifier)
    if not force and not \
            click.confirm(click.style("Are you sure?", fg="magenta")):
        sys.exit(0)

    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Uninstalling plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin_manager.uninstall_plugins([plugin])
    except Exception as e:
        click.secho("[-] Couldn't uninstall plugin because of following "
                    "exception: \n{}".format(e), fg="red")
        if not click.confirm(click.style(
            "Do you want to continue anyway?", fg="magenta")
        ):
            sys.exit(0)

    click.secho("[+] Removing plugin from filesystem...", fg="cyan")
    shutil.rmtree(plugin.path, ignore_errors=False, onerror=None)
Exemplo n.º 16
0
def remove_plugin(plugin_identifier, force):
    """Removes a plugin from the filesystem."""
    validate_plugin(plugin_identifier)
    if not force and not \
            click.confirm(click.style("Are you sure?", fg="magenta")):
        sys.exit(0)

    plugin = get_plugin_from_all(plugin_identifier)
    click.secho("[+] Uninstalling plugin {}...".format(plugin.name), fg="cyan")
    try:
        plugin_manager.uninstall_plugins([plugin])
    except Exception as e:
        click.secho("[-] Couldn't uninstall plugin because of following "
                    "exception: \n{}".format(e),
                    fg="red")
        if not click.confirm(
                click.style("Do you want to continue anyway?", fg="magenta")):
            sys.exit(0)

    click.secho("[+] Removing plugin from filesystem...", fg="cyan")
    shutil.rmtree(plugin.path, ignore_errors=False, onerror=None)
Exemplo n.º 17
0
    def test_get_plugin_from_all(self):
        with self.app.test_request_context():
            plugin = get_plugin_from_all("test3")

        self.assertFalse(plugin.enabled)
Exemplo n.º 18
0
def index():
    plugin_obj = get_plugin_from_all("plugin_name")
    return render_template("plugin_name.html", plugin_obj=plugin_obj)
Exemplo n.º 19
0
def enable(plugin):
    plugin = get_plugin_from_all(plugin)
    plugins.enable_plugins([plugin])
    j = {"status": "plugin_action_enabled"}
    return jsonify(j)
Exemplo n.º 20
0
    def test_get_plugin_from_all(self):
        with self.app.test_request_context():
            plugin = get_plugin_from_all("test3")

        self.assertFalse(plugin.enabled)