From 2b3435aed15d27e98e71f20bdf141351c8b21f5b Mon Sep 17 00:00:00 2001 From: jfuller Date: Tue, 25 Apr 2023 15:34:26 +0200 Subject: [PATCH 1/2] allow -v at the end of cli invoke --- CHANGELOG.md | 4 +++ griffon/commands/queries.py | 46 +++++++++++++++++++++++++++++--- griffon/output.py | 2 +- griffon/services/core_queries.py | 4 ++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ade46..1d4a487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Changed +- allow -v at the end of CLI invoke +### Added +- added entities component-registry components tree which displays dependency tree ## [0.1.26] - 2023-04-21 ### Changed diff --git a/griffon/commands/queries.py b/griffon/commands/queries.py index e32c334..21ae244 100644 --- a/griffon/commands/queries.py +++ b/griffon/commands/queries.py @@ -8,7 +8,7 @@ from component_registry_bindings.bindings.python_client.api.v1 import v1_components_list from component_registry_bindings.bindings.python_client.models import Component -from griffon import CorgiService, OSIDBService, progress_bar +from griffon import CorgiService, OSIDBService, get_config_option, progress_bar from griffon.autocomplete import ( get_component_names, get_cve_ids, @@ -82,10 +82,19 @@ def queries_grp(ctx): default=False, help="Return all Products.", ) +@click.option( + "-v", + "verbose", + count=True, + default=get_config_option("default", "verbosity", 0), + help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).", +) # noqa @click.pass_context @progress_bar -def get_product_summary(ctx, product_stream_name, strict_name_search, all): +def get_product_summary(ctx, product_stream_name, strict_name_search, all, verbose): """get product stream.""" + if verbose: + ctx.obj["VERBOSE"] = verbose if not product_stream_name and not all and not strict_name_search: click.echo(ctx.get_help()) exit(0) @@ -222,6 +231,13 @@ def retrieve_component_summary(ctx, component_name, strict_name_search): default=False, help="Search for Components by upstream.", ) +@click.option( + "-v", + "verbose", + count=True, + default=get_config_option("default", "verbosity", 0), + help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).", +) # noqa @click.pass_context def get_product_contain_component( ctx, @@ -241,9 +257,12 @@ def get_product_contain_component( search_redhat, search_community, search_upstreams, + verbose, ): with console.status("griffoning", spinner="line") as operation_status: """List products of a latest component.""" + if verbose: + ctx.obj["VERBOSE"] = verbose if not purl and not component_name: click.echo(ctx.get_help()) click.echo("") @@ -261,6 +280,7 @@ def get_product_contain_component( ctx.params["search_latest"] = True params = copy.deepcopy(ctx.params) + params.pop("verbose") params.pop("sfm2_flaw_id") params.pop("flaw_mode") params.pop("affect_mode") @@ -421,6 +441,13 @@ def get_product_contain_component( default=False, help="Strict search, exact match of component name.", ) +@click.option( + "-v", + "verbose", + count=True, + default=get_config_option("default", "verbosity", 0), + help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).", +) # noqa @click.pass_context @progress_bar def get_component_contain_component( @@ -432,8 +459,11 @@ def get_component_contain_component( component_arch, namespace, strict_name_search, + verbose, ): """List components that contain component.""" + if verbose: + ctx.obj["VERBOSE"] = verbose if not component_name and not purl: click.echo(ctx.get_help()) exit(0) @@ -492,9 +522,19 @@ def get_product_manifest_query(ctx, product_stream_name, ofuri, spdx_json_format "include_fields": {"type": click.Choice(CorgiService.get_fields(Component))}, }, ) +@click.option( + "-v", + "verbose", + count=True, + default=get_config_option("default", "verbosity", 0), + help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).", +) # noqa @click.pass_context -def get_product_latest_components_query(ctx, product_stream_name, ofuri, **params): +def get_product_latest_components_query(ctx, product_stream_name, ofuri, verbose, **params): """List components of a specific product version.""" + if verbose: + ctx.obj["VERBOSE"] = verbose + ctx.params.pop("verbose") if not ofuri and not product_stream_name: click.echo(ctx.get_help()) exit(0) diff --git a/griffon/output.py b/griffon/output.py index a08edf0..140ffb6 100644 --- a/griffon/output.py +++ b/griffon/output.py @@ -686,7 +686,7 @@ def text_output_list(ctx, output, format, exclude_components): row["related_url"], purl.qualifiers.get("arch"), ) - if ctx.obj["VERBOSE"] == 1: + if ctx.obj["VERBOSE"] > 0: download_url = "" if "download_url" in row: download_url = row["download_url"] diff --git a/griffon/services/core_queries.py b/griffon/services/core_queries.py index 5ed8a03..20f813b 100644 --- a/griffon/services/core_queries.py +++ b/griffon/services/core_queries.py @@ -27,7 +27,7 @@ class product_stream_summary: name = "product_stream_summary" description = "retrieve product_stream summary" - allowed_params = ["strict_name_search", "all", "product_stream_name", "ofuri"] + allowed_params = ["strict_name_search", "all", "product_stream_name", "ofuri", "verbose"] def __init__(self, params: dict) -> None: self.corgi_session = CorgiService.create_session() @@ -633,6 +633,7 @@ class components_containing_specific_component_query: "component_arch", "namespace", "strict_name_search", + "verbose", ] def __init__(self, params: dict): @@ -672,6 +673,7 @@ class components_containing_component_query: "component_arch", "namespace", "strict_name_search", + "verbose", ] def __init__(self, params: dict) -> None: From 2844cc0cf557c6e44fd1dd8fc8c16b8f17e2c903 Mon Sep 17 00:00:00 2001 From: jfuller Date: Wed, 26 Apr 2023 09:06:10 +0200 Subject: [PATCH 2/2] GRIF-74 - prefer display nvr --- CHANGELOG.md | 1 + griffon/output.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d4a487..ded0b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Changed - allow -v at the end of CLI invoke +- prefer nvr for component name in text output ### Added - added entities component-registry components tree which displays dependency tree diff --git a/griffon/output.py b/griffon/output.py index 140ffb6..1303ac9 100644 --- a/griffon/output.py +++ b/griffon/output.py @@ -243,16 +243,20 @@ def text_output_products_contain_component( for name in names: if not any([match in name for match in exclude_components]): sources = [] + nvr = "" for item in ps_components: if item["name"] == name and "sources" in item: sources.extend(item["sources"]) + if item["nvr"]: + nvr = item["nvr"] root_component = "root component" if sources: source_purl = PackageURL.from_string(sources[0]["purl"]) root_component = source_purl.name - dep_name = name.replace(component_name, f"[b]{component_name}[/b]") - dep = f"[white]({dep_name})[/white]" + + dep_name = nvr.replace(component_name, f"[b]{component_name}[/b]") + dep = f"[white]({dep_name}, {item['type'].lower()})[/white]" console.print( Text(ps, style="magenta b u"), root_component, @@ -275,9 +279,12 @@ def text_output_products_contain_component( for name in names: if not any([match in name for match in exclude_components]): sources = [] + nvr = "" for item in ps_components: if item["name"] == name and "sources" in item: sources.extend(item["sources"]) + if item["nvr"]: + nvr = item["nvr"] root_component = "root component" if sources: @@ -286,7 +293,7 @@ def text_output_products_contain_component( f"{source_purl.name}-{output_version(ctx,source_purl.version)}" ) - dep_name = name.replace(component_name, f"[b]{component_name}[/b]") + dep_name = nvr.replace(component_name, f"[b]{component_name}[/b]") dep = f"[white]({dep_name}, {item['type'].lower()})[/white]" console.print( Text(ps, style="magenta b u"),