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 ef5558d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 38 deletions.
101 changes: 70 additions & 31 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 All @@ -752,7 +781,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"[red]{source_component_names[0]} and {len(source_component_names) - 1} more[/red]" # 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 @@ -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 All @@ -862,7 +896,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"[red]{source_component_names[0]} and {len(source_component_names) - 1} more[/red]" # 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 @@ -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
15 changes: 8 additions & 7 deletions griffon/services/core_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ def async_retrieve_sources(self, purl):
"limit": 120,
"root_components": "True",
"provides": purl,
"include_fields": "type,arch,nvr,purl,name,version,namespace,download_url,related_url",
"include_fields": "type,arch,nvr,purl,name,version,namespace",
}
try:
return list(self.components.retrieve_list_iterator_async(**params, max_results=5000))
return list(self.components.retrieve_list_iterator_async(**params))
except Exception as e:
logger.warning(f"{type(e).__name__} - problem retrieving {purl} sources.")
return []
Expand All @@ -233,7 +233,7 @@ def async_retrieve_upstreams(self, purl):
"limit": 120,
"root_components": "True",
"upstreams": purl,
"include_fields": "type,arch,nvr,purl,name,version,namespace,download_url,related_url",
"include_fields": "type,arch,nvr,purl,name,version,namespace",
}
try:
return list(self.components.retrieve_list_iterator_async(**params, max_results=5000))
Expand All @@ -246,7 +246,7 @@ def async_retrieve_provides(self, urlparams, purl):
params = {
"limit": 120,
"sources": purl,
"include_fields": "type,arch,nvr,purl,version,name,namespace,download_url,related_url",
"include_fields": "type,arch,nvr,purl,version,name,namespace",
}
if "name" in urlparams:
params["name"] = urlparams["name"]
Expand All @@ -267,8 +267,7 @@ def async_retrieve_provides(self, urlparams, purl):

def process_component(session, urlparams, c):
"""perform any neccessary sub retrievals."""
if c.sources:
c.sources = async_retrieve_sources(session, c.purl)
c.sources = async_retrieve_sources(session, c.purl)
c.upstreams = async_retrieve_upstreams(session, c.purl)
c.provides = async_retrieve_provides(session, urlparams, c.purl)
return c
Expand Down Expand Up @@ -418,6 +417,7 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
latest_components = self.corgi_session.components.retrieve_list_iterator_async(
**search_provides_params, max_results=10000
)

status.update(
f"found {latest_components_cnt} latest provides child component(s)- retrieving children, sources & upstreams." # noqa
)
Expand All @@ -427,7 +427,6 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
latest_components,
):
results.append(processed_component)

if not self.no_community:
status.update("searching latest community provided child component(s).")
community_component_cnt = self.community_session.components.count(
Expand Down Expand Up @@ -696,13 +695,15 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
]

filtered_results = []

for result in results:
is_matched = False
for p in patterns:
if is_matched:
break
if type(result) == Component:
m = p.match(result.name)
logger.debug(f"rh naming filtered {result.name}")
if m:
filtered_results.append(result)
is_matched = True
Expand Down

0 comments on commit ef5558d

Please sign in to comment.