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

Commit

Permalink
Fix picking latest NVR
Browse files Browse the repository at this point in the history
To pick the latest NVR we need to sort the list of NVRs naturally
otherwise it might produce incorrect assumption since two almost
identical NVRs which only has the difference that one part of the
version has two digits is considered to be lower than the one
with only one digit on the same place
  • Loading branch information
JakubFrejlach committed Feb 8, 2024
1 parent e54b4a6 commit f4f2e3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions griffon/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
Helpers for direct usage or debbuging
"""

import json
import re
from enum import Enum
from typing import Callable, Optional, Type, Union

Expand Down Expand Up @@ -106,3 +108,9 @@ class Style(Enum):

def __str__(self):
return str(self.value)


def natural_sort_key(string):
"""Key for builtin sorted function to perform natural sort"""
split_by_digit = re.split("([0-9]+)", string)
return [int(part) if part.isdigit() else part.lower() for part in split_by_digit]
22 changes: 17 additions & 5 deletions griffon/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from rich.text import Text
from rich.tree import Tree

from .helpers import natural_sort_key

console = Console(color_system="auto")

logger = logging.getLogger("griffon")
Expand Down Expand Up @@ -511,7 +513,9 @@ def text_output_products_contain_component(
for ps in result_tree[pv].keys():
for cn in sorted(result_tree[pv][ps].keys()):
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
nvr = sorted(
list(result_tree[pv][ps][cn].keys()), key=natural_sort_key
)[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
Expand Down Expand Up @@ -579,7 +583,9 @@ def text_output_products_contain_component(
for ps in result_tree[pv].keys():
for cn in sorted(result_tree[pv][ps].keys()):
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
nvr = sorted(
list(result_tree[pv][ps][cn].keys()), key=natural_sort_key
)[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
Expand Down Expand Up @@ -703,7 +709,9 @@ def text_output_products_contain_component(
for ps in result_tree[pv].keys():
for cn in sorted(result_tree[pv][ps].keys()):
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
nvr = sorted(
list(result_tree[pv][ps][cn].keys()), key=natural_sort_key
)[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
Expand Down Expand Up @@ -856,7 +864,9 @@ def text_output_products_contain_component(
for ps in result_tree[pv].keys():
for cn in sorted(result_tree[pv][ps].keys()):
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
nvr = sorted(
list(result_tree[pv][ps][cn].keys()), key=natural_sort_key
)[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
Expand Down Expand Up @@ -971,7 +981,9 @@ def text_output_products_contain_component(
for ps in result_tree[pv].keys():
for cn in sorted(result_tree[pv][ps].keys()):
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
nvr = sorted(
list(result_tree[pv][ps][cn].keys()), key=natural_sort_key
)[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
Expand Down

0 comments on commit f4f2e3a

Please sign in to comment.