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

Commit

Permalink
minor color, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JimFuller-RedHat committed Jan 21, 2024
1 parent 9cd90a2 commit 478c69d
Showing 1 changed file with 68 additions and 29 deletions.
97 changes: 68 additions & 29 deletions griffon/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def generate_normalised_results(
"product_version": ps["product_versions"][0]["name"],
"product_stream": ps.get("name"),
"product_stream_active": ps.get("active"),
"product_stream_relations": ps.get("relations"),
"namespace": item.get("namespace"),
"name": item.get("name"),
"nvr": item.get("nvr"),
Expand Down Expand Up @@ -388,18 +389,32 @@ def generate_affects(
return affects


def process_product_color(build_type: str) -> str:
"""return color used for product, currently only based on component build type"""
if build_type == "APP_INTERFACE":
return "blue"
if build_type == "CENTOS":
return "cyan"
if build_type == "PNC":
return "red"
if build_type == "KOJI":
return "yellow"
if build_type == "PYXIS":
return "green"
def process_component_color(namespace: str, build_type: str) -> str:
"""return color used for component, currently only based on component build type"""
if namespace:
if namespace == "UPSTREAM":
return "u"
if build_type:
if build_type == "PYXIS":
return "green"
return "grey93"


def process_product_color(relations: str, build_type: str) -> str:
"""return color used for product, currently only based on relations"""
if relations:
relations_types = [relation["type"] for relation in relations]
if "APP_INTERFACE" in relations_types:
return "blue"
if build_type:
if build_type == "PYXIS":
return "green"
if build_type == "PNC":
return "red"
if build_type == "KOJI":
return "yellow"
if build_type == "CENTOS":
return "yellow"
return "magenta"


Expand Down Expand Up @@ -471,15 +486,20 @@ def text_output_products_contain_component(
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["build_type"]
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
root_component_color = process_component_color(
result_tree[pv][ps][cn][nvr]["namespace"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
dep_name = nvr
# highlight search term
try:
dep_name = highlight_search_term(search_component_name, dep_name)
except re.error:
pass
dep = f"[grey93]{dep_name}[/grey93]" # noqa
dep = f"[{root_component_color}]{dep_name}[/{root_component_color}]" # noqa
if result_tree[pv][ps][cn][nvr]["upstreams"]:
upstream_component_names = sorted(
list(
Expand All @@ -494,7 +514,7 @@ def text_output_products_contain_component(
for upstream_component_name in upstream_component_names:
console.print(
Text(pv, style=f"{product_color} b"),
f"[yellow1]{upstream_component_name}[/yellow1]",
f"[pale_turquoise1]{upstream_component_name}[/pale_turquoise1]", # noqa
no_wrap=no_wrap,
)
if result_tree[pv][ps][cn][nvr]["sources"]:
Expand Down Expand Up @@ -534,16 +554,20 @@ def text_output_products_contain_component(
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["build_type"]
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
root_component_color = process_component_color(
result_tree[pv][ps][cn][nvr]["namespace"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
# highlight search term
# dep_name = nvr
dep_name = nvr
try:
dep_name = highlight_search_term(search_component_name, dep_name)
except re.error:
pass
dep = f"[grey93]{dep_name} ({result_tree[pv][ps][cn][nvr]['type']})[/grey93]" # noqa
dep = f"[{root_component_color}]{dep_name} ({result_tree[pv][ps][cn][nvr]['type']})[/{root_component_color}]" # noqa
related_url = result_tree[pv][ps][cn][nvr].get("related_url")
try:
if result_tree[pv][ps][cn][nvr]["related_url"]:
Expand Down Expand Up @@ -598,7 +622,7 @@ def text_output_products_contain_component(
upstream_component_name = f"{upstream_component_names[0]} and {len(upstream_component_names) - 1} more" # noqa
console.print(
Text(ps, style=f"{product_color} b"),
f"[yellow1]{upstream_component_name}[/yellow1]",
f"[pale_turquoise1]{upstream_component_name}[/pale_turquoise1]", # noqa
f"[{dep}]",
no_wrap=no_wrap,
)
Expand All @@ -618,7 +642,7 @@ def text_output_products_contain_component(
if len(source_component_names) > 0:
source_component_name = source_component_names[0]
if len(source_component_names) > 1:
source_component_name = f"[bright_yellow]{source_component_names[0]} and {len(source_component_names) - 1} more[/bright_yellow]" # noqa
source_component_name = f"{source_component_names[0]} and {len(source_component_names) - 1} more]" # noqa
console.print(
Text(ps, style=f"{product_color} b"),
f"[pale_turquoise1]{source_component_name}[/pale_turquoise1]", # noqa
Expand Down Expand Up @@ -654,7 +678,12 @@ def text_output_products_contain_component(
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["build_type"]
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
root_component_color = process_component_color(
result_tree[pv][ps][cn][nvr]["namespace"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
# highlight search term
dep_name = nvr
Expand All @@ -665,7 +694,7 @@ def text_output_products_contain_component(
)
except re.error:
pass
dep = f"[grey93]{dep_name} ({result_tree[pv][ps][cn][nvr]['type']}:{result_tree[pv][ps][cn][nvr]['arch']})[/grey93]" # noqa
dep = f"[{root_component_color}]{dep_name} ({result_tree[pv][ps][cn][nvr]['type']}:{result_tree[pv][ps][cn][nvr]['arch']})[/{root_component_color}]" # noqa
related_url = result_tree[pv][ps][cn][nvr].get("related_url")
try:
if result_tree[pv][ps][cn][nvr]["related_url"]:
Expand Down Expand Up @@ -731,7 +760,7 @@ def text_output_products_contain_component(
upstream_component_name = f"{upstream_component_names[0]} and {len(upstream_component_names) - 1} more" # noqa
console.print(
Text(ps, style=f"{product_color} b"),
f"[yellow1]{upstream_component_name}[/yellow1]",
f"[pale_turquoise1]{upstream_component_name}[/pale_turquoise1]", # noqa
f"[{dep}]",
f"[grey]{related_url}[/grey]",
no_wrap=no_wrap,
Expand Down Expand Up @@ -792,7 +821,12 @@ def text_output_products_contain_component(
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["build_type"]
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
root_component_color = process_component_color(
result_tree[pv][ps][cn][nvr]["namespace"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
# highlight search term
dep_name = nvr
Expand All @@ -803,7 +837,7 @@ def text_output_products_contain_component(
)
except re.error:
pass
dep = f"[grey93]{dep_name} ({result_tree[pv][ps][cn][nvr]['type']}:{result_tree[pv][ps][cn][nvr]['arch']})[/grey93]" # noqa
dep = f"[{root_component_color}]{dep_name} ({result_tree[pv][ps][cn][nvr]['type']}:{result_tree[pv][ps][cn][nvr]['arch']})[/{root_component_color}]" # noqa
related_url = result_tree[pv][ps][cn][nvr].get("related_url")
try:
if result_tree[pv][ps][cn][nvr]["related_url"]:
Expand Down Expand Up @@ -841,7 +875,7 @@ def text_output_products_contain_component(
upstream_component_name = f"{upstream_component_names[0]} and {len(upstream_component_names) - 1} more" # noqa
console.print(
Text(ps, style=f"{product_color} b"),
f"[yellow1]{upstream_component_name}[/yellow1]",
f"[pale_turquoise1]{upstream_component_name}[/pale_turquoise1]", # noqa
f"[{dep}]",
f"[grey]{related_url}[/grey]",
no_wrap=no_wrap,
Expand Down Expand Up @@ -902,7 +936,12 @@ def text_output_products_contain_component(
# select the latest nvr (from sorted list)
nvr = list(result_tree[pv][ps][cn].keys())[-1]
product_color = process_product_color(
result_tree[pv][ps][cn][nvr]["build_type"]
result_tree[pv][ps][cn][nvr]["product_stream_relations"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
root_component_color = process_component_color(
result_tree[pv][ps][cn][nvr]["namespace"],
result_tree[pv][ps][cn][nvr]["build_type"],
)
# highlight search term
dep_name = result_tree[pv][ps][cn][nvr]["purl"]
Expand All @@ -913,7 +952,7 @@ def text_output_products_contain_component(
)
except re.error:
pass
dep = f"[grey93]{dep_name}[/grey93]" # noqa
dep = f"[{root_component_color}]{dep_name}[/{root_component_color}]" # noqa
related_url = result_tree[pv][ps][cn][nvr].get("related_url")
try:
if result_tree[pv][ps][cn][nvr]["related_url"]:
Expand Down Expand Up @@ -949,7 +988,7 @@ def text_output_products_contain_component(
upstream_component_name = f"{upstream_component_names[0]} and {len(upstream_component_names) - 1} more" # noqa
console.print(
Text(ps, style=f"{product_color} b u"),
f"[yellow1]{upstream_component_name}[/yellow1]",
f"[pale_turquoise1]{upstream_component_name}[/pale_turquoise1]", # noqa
f"[{dep}]",
f"[grey]{related_url}[/grey]",
f"[grey]{build_source_url}[/grey]",
Expand Down

0 comments on commit 478c69d

Please sign in to comment.