From 1397ae9789f7c3e8057175db5bf7f3660cf2f9ad Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Thu, 8 Feb 2024 15:33:53 +0100 Subject: [PATCH] Add rhel-X/rhel-br-X deduplication --deduplicate/--no-deduplicate will perform a set of deduplication heuristics however for the user, only the deduplication as a whole really matters --- griffon/commands/queries.py | 9 +++++++++ griffon/output.py | 29 +++++++++++++++++++++++++++++ griffon/static/default_griffonrc | 5 +++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/griffon/commands/queries.py b/griffon/commands/queries.py index e075d7d..87de98d 100644 --- a/griffon/commands/queries.py +++ b/griffon/commands/queries.py @@ -5,6 +5,7 @@ these operations beyond cli """ + import copy import logging import re @@ -363,6 +364,12 @@ def retrieve_component_summary(ctx, component_name, strict_name_search): default=get_config_option("default", "exclude_unreleased", False), help="Exclude unreleased components.", ) +@click.option( + "--deduplicate/--no-deduplicate", + "deduplicate", + default=get_config_option("default", "deduplicate", True), + help="Deduplicate / do not deduplicate results based on following rules: rhel/rhel-br redundancy", +) @click.pass_context @progress_bar(is_updatable=True) def get_product_contain_component( @@ -396,6 +403,7 @@ def get_product_contain_component( regex_name_search, include_container_roots, exclude_unreleased, + deduplicate, ): # with console_status(ctx) as operation_status: """List products of a latest component.""" @@ -419,6 +427,7 @@ def get_product_contain_component( params.pop("sfm2_flaw_id") params.pop("flaw_mode") params.pop("affect_mode") + params.pop("deduplicate") if component_name: q = query_service.invoke( core_queries.products_containing_component_query, params, status=operation_status diff --git a/griffon/output.py b/griffon/output.py index 44e82f9..f389cf4 100644 --- a/griffon/output.py +++ b/griffon/output.py @@ -2,6 +2,7 @@ Gather up all of the messy 'presentation' logic into one place """ + import enum import json import logging @@ -426,6 +427,30 @@ def highlight_search_term(search_pattern, text_value): return re.sub(search_pattern, "[b]\\g<0>[/b]", text_value) +def rhel_br_deduplicate(result_tree: dict) -> dict: + """ + if component exists for both rhel-X and rhel-br-X + product version and product stream keep only the rhel-X record + + """ + filtered_result_tree = result_tree + for pv in list(result_tree.keys()): + if pv.startswith("rhel-br"): + for ps in list(result_tree[pv].keys()): + for cn in list(result_tree[pv][ps].keys()): + if cn in result_tree.get(pv.replace("rhel-br", "rhel"), {}).get( + ps.replace("rhel-br", "rhel"), {} + ): + filtered_result_tree[pv][ps].pop(cn) + + if not filtered_result_tree[pv][ps]: + filtered_result_tree[pv].pop(ps) + + if not filtered_result_tree[pv]: + filtered_result_tree.pop(pv) + return filtered_result_tree + + def text_output_products_contain_component( ctx, output, @@ -460,6 +485,10 @@ def text_output_products_contain_component( ) result_tree = generate_result_tree(normalised_results) + # perform deduplication + if ctx.params["deduplicate"]: + result_tree = rhel_br_deduplicate(result_tree) + # TODO - MAVEN component type will require special handling if ctx.params["affect_mode"]: console.no_color = True diff --git a/griffon/static/default_griffonrc b/griffon/static/default_griffonrc index 32f31a3..9203cfd 100644 --- a/griffon/static/default_griffonrc +++ b/griffon/static/default_griffonrc @@ -17,12 +17,13 @@ exclude_components = -container-source -common-debuginfo -doc -devel - -javadoc - -testlib + -javadoc + -testlib -repolib include_container_roots = False exclude_unreleased = False filter_rh_naming = True +deduplicate = True # profile sections (use with --profile {profile} flag) [cloud]