Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Add rhel-X/rhel-br-X deduplication
Browse files Browse the repository at this point in the history
--deduplicate/--no-deduplicate will perform a set of deduplication
heuristics however for the user, only the deduplication as a whole
really matters
  • Loading branch information
JakubFrejlach committed Feb 8, 2024
1 parent 256633d commit 201a8db
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions griffon/commands/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
these operations beyond cli
"""

import copy
import logging
import re
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions griffon/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Gather up all of the messy 'presentation' logic into one place
"""

import enum
import json
import logging
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -460,6 +485,9 @@ def text_output_products_contain_component(
)
result_tree = generate_result_tree(normalised_results)

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
Expand Down
5 changes: 3 additions & 2 deletions griffon/static/default_griffonrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 201a8db

Please sign in to comment.