From 8b15a4590295d614b071acdb67a7e6b71fc9afa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 9 May 2023 21:23:47 +0200 Subject: [PATCH] add docker cmd, more debug, add migrations to package --- flaschengeist/cli/__init__.py | 2 + flaschengeist/cli/docker_cmd.py | 54 ++++++++++++++++++++ flaschengeist/controller/pluginController.py | 3 ++ setup.cfg | 4 +- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 flaschengeist/cli/docker_cmd.py diff --git a/flaschengeist/cli/__init__.py b/flaschengeist/cli/__init__.py index 49e3333..13cded8 100644 --- a/flaschengeist/cli/__init__.py +++ b/flaschengeist/cli/__init__.py @@ -89,6 +89,7 @@ def main(*args, **kwargs): from .docs_cmd import docs from .run_cmd import run from .install_cmd import install + from .docker_cmd import docker # Override logging level environ.setdefault("FG_LOGGING", logging.getLevelName(LOGGING_MAX)) @@ -98,4 +99,5 @@ def main(*args, **kwargs): cli.add_command(install) cli.add_command(plugin) cli.add_command(run) + cli.add_command(docker) cli(*args, **kwargs) diff --git a/flaschengeist/cli/docker_cmd.py b/flaschengeist/cli/docker_cmd.py new file mode 100644 index 0000000..5924b9e --- /dev/null +++ b/flaschengeist/cli/docker_cmd.py @@ -0,0 +1,54 @@ +import click +from click.decorators import pass_context +from flask.cli import with_appcontext +from os import environ + +from flaschengeist import logger +from flaschengeist.controller import pluginController +from werkzeug.exceptions import NotFound +import traceback + + +@click.group() +def docker(): + pass + + +@docker.command() +@with_appcontext +@pass_context +def setup(ctx): + """Setup flaschengesit in docker container""" + click.echo("Setup docker") + + plugins = environ.get("FG_ENABLE_PLUGINS") + + if not plugins: + click.secho("no evironment variable is set for 'FG_ENABLE_PLUGINS'", fg="yellow") + click.secho("set 'FG_ENABLE_PLUGINS' to 'auth_ldap', 'mail', 'balance', 'pricelist_old', 'events'") + plugins = ("auth_ldap", "mail", "pricelist_old", "events", "balance") + else: + plugins = plugins.split(" ") + + print(plugins) + + for name in plugins: + click.echo(f"Installing {name}{'.'*(20-len(name))}", nl=False) + try: + pluginController.install_plugin(name) + except Exception as e: + click.secho(" failed", fg="red") + if logger.getEffectiveLevel() > 10: + ctx.fail(f"[{e.__class__.__name__}] {e}") + else: + ctx.fail(traceback.format_exc()) + else: + click.secho(" ok", fg="green") + + for name in plugins: + click.echo(f"Enabling {name}{'.'*(20-len(name))}", nl=False) + try: + pluginController.enable_plugin(name) + click.secho(" ok", fg="green") + except NotFound: + click.secho(" not installed / not found", fg="red") diff --git a/flaschengeist/controller/pluginController.py b/flaschengeist/controller/pluginController.py index 6325f98..6f3bff6 100644 --- a/flaschengeist/controller/pluginController.py +++ b/flaschengeist/controller/pluginController.py @@ -108,9 +108,12 @@ def install_plugin(plugin_name: str): plugin.install() # Check migrations directory = entry_point[0].dist.locate_file("") + logger.debug(f"Checking for migrations in {directory}") for loc in entry_point[0].module.split(".") + ["migrations"]: directory /= loc + logger.debug(f"Checking for migrations with loc in {directory}") if directory.exists(): + logger.debug(f"Found migrations in {directory}") database_upgrade(revision=f"{plugin_name}@head") db.session.commit() return plugin diff --git a/setup.cfg b/setup.cfg index f0a30a9..fe404cd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] license = MIT -version = 2.0.0.dev0 +version = 2.0.0.dev1 name = flaschengeist author = Tim Gröger author_email = flaschengeist@wu5.de @@ -45,7 +45,7 @@ mysql = mysqlclient;platform_system!='Windows' [options.package_data] -* = *.toml, script.py.mako +* = *.toml, script.py.mako, *.ini, */migrations/*, migrations/versions/* [options.entry_points] console_scripts =