From 60ecd0c592cc1e7b19b6f6dded7e0bc6be77679a Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Mon, 30 Oct 2023 11:57:24 +0100 Subject: [PATCH] [ADD] manifestoo: select_addons_categories: allow to filter addons on given categories --- pyproject.toml | 2 +- src/manifestoo/addons_selection.py | 8 ++++++++ src/manifestoo/main.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2f40582..16d2272 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ ] readme = "README.md" dependencies = [ - "manifestoo_core >= 0.8", + "manifestoo_core >= 1.3", "textual >= 0.6", "typer[all] >= 0.3.2", "importlib_metadata ; python_version<'3.8'", diff --git a/src/manifestoo/addons_selection.py b/src/manifestoo/addons_selection.py index 1268ae5..d1c3096 100644 --- a/src/manifestoo/addons_selection.py +++ b/src/manifestoo/addons_selection.py @@ -25,3 +25,11 @@ def remove_addon_names(self, addon_names: str) -> None: self.remove(addon_name) except KeyError: pass + + def filter_categories(self, addons_categories: str, addons_set: AddonsSet) -> None: + categories_list = [category for category in comma_split(addons_categories)] + addons_list = list(self) + for addon_name in addons_list: + addon = addons_set.get(addon_name) + if addon and addon.manifest.category not in categories_list: + self.remove(addon_name) diff --git a/src/manifestoo/main.py b/src/manifestoo/main.py index a5e84e2..2586587 100644 --- a/src/manifestoo/main.py +++ b/src/manifestoo/main.py @@ -84,6 +84,15 @@ def callback( help="Exclude the Odoo core addons (CE and EE) for the given series.", show_default=False, ), + filter_categories: Optional[str] = typer.Option( + None, + metavar="addon1,addon2,...", + help=( + "Comma separated list of addons categories to use as addons filter. " + "Filter out addons from the selected addons that don't belong to one " + "of these categories." + ), + ), addons_path: Optional[str] = typer.Option( None, help="Expand addons path with this comma separated list of directories.", @@ -210,6 +219,10 @@ def callback( main_options.addons_selection.update(core_addons) else: main_options.addons_selection.difference_update(core_addons) + if filter_categories: + main_options.addons_selection.filter_categories( + filter_categories, main_options.addons_set + ) if main_options.addons_selection: echo.info(str(main_options.addons_selection), bold_intro="Addons selection: ") else: