From 02b3b3ddf1a76ce17fc5c64ac210357e27fcd6a9 Mon Sep 17 00:00:00 2001 From: Joshua Kreuder Date: Fri, 17 May 2024 09:00:04 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`godoo=20shell`=20now=20uses=20DB?= =?UTF-8?q?=20options=20when=20no=20Config=20File=20is=20present?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/godoo_cli/commands/shell.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/godoo_cli/commands/shell.py b/src/godoo_cli/commands/shell.py index 5400247..55030cb 100644 --- a/src/godoo_cli/commands/shell.py +++ b/src/godoo_cli/commands/shell.py @@ -37,11 +37,27 @@ def odoo_shell( pipe_in_command: str = typer.Argument("", help="Python command, that will be piped into odoo-bin shell"), odoo_main_path=CLI.odoo_paths.bin_path, odoo_conf_path=CLI.odoo_paths.conf_path, + db_host=CLI.database.db_host, + db_port=CLI.database.db_port, + db_name=CLI.database.db_name, + db_user=CLI.database.db_user, + db_password=CLI.database.db_password, ): """ Start Odoo session in an Interactive shell. + + Odoo Conf is Preferred, but if not found, Database Options are used. """ - shell_cmd = f"{str(odoo_main_path.absolute())}/odoo-bin shell -c {str(odoo_conf_path.absolute())} --no-http" + shell_cmd = f"{str(odoo_main_path.absolute())}/odoo-bin shell --no-http" + if odoo_conf_path.exists(): + shell_cmd += f" -c {str(odoo_conf_path.absolute())}" + else: + LOGGER.warning("No Odoo Config File found at %s", odoo_conf_path) + if not all([db_host, db_port, db_name, db_user, db_password]): + LOGGER.error("Missing database options and Config File. Aborting.") + return CLI.returner(1) + shell_cmd += f" --db_host={db_host} --db_port={db_port} --database={db_name} --db_user={db_user} --db_password={db_password}" + if pipe_in_command: pipe_in_command = pipe_in_command.replace('"', '\\"') # Escape Double Quotes shell_cmd = f'echo "{pipe_in_command}" |' + shell_cmd