From ef5558dcfac8b037c121a96c07df67e841c01235 Mon Sep 17 00:00:00 2001 From: jfuller Date: Sun, 21 Jan 2024 15:30:21 +0100 Subject: [PATCH] minor color, fix lint --- griffon/output.py | 101 +++++++++++++++++++++---------- griffon/services/core_queries.py | 15 ++--- 2 files changed, 78 insertions(+), 38 deletions(-) diff --git a/griffon/output.py b/griffon/output.py index 0a06fd9..1bb74f7 100644 --- a/griffon/output.py +++ b/griffon/output.py @@ -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"), @@ -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" @@ -471,7 +486,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"], ) dep_name = nvr # highlight search term @@ -479,7 +499,7 @@ def text_output_products_contain_component( 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( @@ -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"]: @@ -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"]: @@ -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, ) @@ -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 @@ -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 @@ -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"]: @@ -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, @@ -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 @@ -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 @@ -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"]: @@ -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, @@ -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 @@ -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"] @@ -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"]: @@ -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]", diff --git a/griffon/services/core_queries.py b/griffon/services/core_queries.py index 6a799c7..58a7c4a 100644 --- a/griffon/services/core_queries.py +++ b/griffon/services/core_queries.py @@ -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 [] @@ -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)) @@ -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"] @@ -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 @@ -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 ) @@ -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( @@ -696,6 +695,7 @@ def execute(self, status=None) -> List[Dict[str, Any]]: ] filtered_results = [] + for result in results: is_matched = False for p in patterns: @@ -703,6 +703,7 @@ def execute(self, status=None) -> List[Dict[str, Any]]: 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