From 611641cfb581d4a45dd63cf3b21538cf96973a3b Mon Sep 17 00:00:00 2001 From: Joshua Kreuder Date: Sat, 24 Aug 2024 23:54:13 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`godoo=20bootstrap`=20Add=20Banner?= =?UTF-8?q?=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Banner with Text and color by Env Variables. Useful for Dev instances --- scripts/migrations/development/add_banner.py | 70 -------------------- src/godoo_cli/cli_common.py | 12 +++- src/godoo_cli/commands/bootstrap.py | 8 ++- 3 files changed, 18 insertions(+), 72 deletions(-) delete mode 100644 scripts/migrations/development/add_banner.py diff --git a/scripts/migrations/development/add_banner.py b/scripts/migrations/development/add_banner.py deleted file mode 100644 index affb9ee..0000000 --- a/scripts/migrations/development/add_banner.py +++ /dev/null @@ -1,70 +0,0 @@ -"""Install Web Ribbon addon and set Text and color""" -import logging -import os - -LOGGER = logging.getLogger(__name__) - -env = env # Just to silence pyright # pyright: ignore # NOQA - - -def set_banner(banner_text: str = "Development", banner_background_color: str = ""): - """Set Odoo top left Banner. - - Parameters - ---------- - banner_text : str, optional - Text to display on banner, by default "" - banner_background_color : str, optional - rbg("","","",""), by default "" - """ - if not banner_background_color: - banner_background_color = "rgb(255,0,0)" - - view_env = env["ir.ui.view"] - view_dic = { - "name": "wetech.dev_banner", - "type": "qweb", - "mode": "extension", - "active": True, - "inherit_id": env.ref("web.layout").id, - "arch_db": f""" - - -
- - {banner_text} - -
-
-
- """, - } - if view := view_env.search([("name", "=", view_dic["name"])]): - LOGGER.info("Updating Banner view: %s", view_dic["name"]) - view.update(view_dic) - else: - LOGGER.info("Creating Banner view: %s", view_dic["name"]) - view_env.create(view_dic) - - -def disable_record(ref): - if rec := env.ref(ref, raise_if_not_found=False): - rec.active = False - - -def remove_upgrade_test_ribbon(): - disable_record("__upgrade__.upg_test_banner") - disable_record("__upgrade__.upg_test_ribbon") - disable_record("web.neutralize_banner") - - -set_banner( - os.getenv("ODOO_BANNER_TEXT"), - os.getenv("ODOO_BANNER_BG_COLOR"), -) -remove_upgrade_test_ribbon() -if ribb := env["ir.module.module"].search([("name", "=", "web_environment_ribbon"), ("state", "=", "installed")]): - ribb.button_immediate_uninstall() - - -env.cr.commit() diff --git a/src/godoo_cli/cli_common.py b/src/godoo_cli/cli_common.py index 1721a3b..e29999e 100644 --- a/src/godoo_cli/cli_common.py +++ b/src/godoo_cli/cli_common.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import List, Optional -from typer import Option +from typer import Argument, Option from typer_common_functions import get_type_from_default, typer_retuner, typer_unpacker @@ -42,6 +42,16 @@ class OdooLaunchArgs: rich_help_panel="Odoo", ) log_file_path: Path = Option(None, dir_okay=False, writable=True, help="Logfile Path", rich_help_panel="Odoo") + banner_text: str = Argument( + ..., + help="Banner Text to add to Odoo Log", + envvar="ODOO_BANNER_TEXT", + ) + banner_bg_color: str = Option( + "green", + help="Banner Background Color", + envvar="ODOO_BANNER_BG_COLOR", + ) @dataclass diff --git a/src/godoo_cli/commands/bootstrap.py b/src/godoo_cli/commands/bootstrap.py index 6164978..80df211 100644 --- a/src/godoo_cli/commands/bootstrap.py +++ b/src/godoo_cli/commands/bootstrap.py @@ -12,6 +12,7 @@ from ..helpers.modules_py import _install_py_reqs_by_odoo_cmd from ..helpers.system import run_cmd from .db.connection import DBConnection +from .shell.shell import odoo_shell_run_script CLI = CommonCLI() @@ -142,11 +143,12 @@ def bootstrap_odoo( install_base_modules: Annotated[ bool, typer.Option( - ..., help="Install base and web modules if no other -i or -u is present in Bootstrap", rich_help_panel="Odoo", ), ] = True, + banner_text=CLI.odoo_launch.banner_text, + banner_bg_color=CLI.odoo_launch.banner_bg_color, ): """Bootstrap Odoo.""" @@ -186,4 +188,8 @@ def bootstrap_odoo( ret = run_cmd(cmd_string).returncode if ret != 0: LOGGER.error("Odoo-Bin Returned %d", ret) + if banner_text: + os.environ["ODOO_BANNER_TEXT"] = banner_text + os.environ["ODOO_BANNER_BG_COLOR"] = banner_bg_color + odoo_shell_run_script(script_name="odoo_banner", odoo_main_path=odoo_main_path, odoo_conf_path=odoo_conf_path) return CLI.returner(ret)