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

GRIF-218: Fix operation status #277

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
### Fixed
* fixed wrong progress bar usage accross several commands
* fixed error in raw json transform for single entities


## [0.4.0] - 2023-12-22
### Changed
Expand Down
40 changes: 37 additions & 3 deletions griffon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_fields(model, prefix=""):


@contextmanager
def console_status(no_progress_bar):
def console_status(no_progress_bar, initial_status=None):
"""updatable console status progress bar"""

class DisabledStatusObject:
Expand Down Expand Up @@ -389,16 +389,50 @@ def update(self, status, *args, **kwargs):
status=f"[magenta b]griffoning:[/magenta b] [bold]{status}[/bold]", *args, **kwargs
)

def start(self):
self.status.start()

def stop(self):
self.status.stop()

if no_progress_bar:
yield DisabledStatusObject()
else:
status = f": {initial_status}" if initial_status else ""

with console.status(
"[magenta b]griffoning[/magenta b]", spinner="line"
f"[magenta b]griffoning[/magenta b]{status}", spinner="line"
) as operation_status:
yield StatusObject(operation_status)


def progress_bar(
def progress_bar(is_updatable=False, initial_status=None):
"""
progress bar decorator

:param updatable: allows/disallows updatable progress bar status, if set to `True`
decorated function needs to have `operation_status` parameter
"""

def decorator(func=None):
if not func:
return partial(decorator)

@wraps(func)
def wrapper(*args, **kwargs):
obj: dict = args[0].obj
with console_status(obj.get("NO_PROGRESS_BAR"), initial_status) as operation_status:
if is_updatable:
func(*args, operation_status=operation_status, **kwargs)
else:
func(*args, **kwargs)

return wrapper

return decorator


def progress_bar2(
func=None,
):
"""progress bar decorator"""
Expand Down
39 changes: 21 additions & 18 deletions griffon/commands/entities/community_component_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def components(ctx):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def list_components(ctx, strict_name_search, component_name, **params):
is_params_empty = [False for v in params.values() if v]
if not component_name and not is_params_empty:
Expand Down Expand Up @@ -121,7 +121,7 @@ def list_components(ctx, strict_name_search, component_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_component(ctx, component_id, purl, **params):
is_params_empty = [False for v in params.values() if v]
if not component_id and not purl and not is_params_empty:
Expand Down Expand Up @@ -169,7 +169,7 @@ def get_component(ctx, component_id, purl, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_component_summary(ctx, component_name, strict_name_search, **params):
"""Get Component summary."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -231,7 +231,7 @@ def get_component_summary(ctx, component_name, strict_name_search, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_component_provides(ctx, component_uuid, purl, **params):
"""Retrieve all Components provided by a Component."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -271,7 +271,7 @@ def get_component_provides(ctx, component_uuid, purl, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_component_sources(ctx, component_uuid, purl, **params):
"""Retrieve all Components that contain Component."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -310,7 +310,7 @@ def get_component_sources(ctx, component_uuid, purl, **params):
help="Generate spdx manifest (json).",
)
@click.pass_context
@progress_bar
@progress_bar()
def get_component_manifest(ctx, component_uuid, purl, spdx_json_format):
"""Retrieve Component manifest."""
if not component_uuid and not purl:
Expand Down Expand Up @@ -391,7 +391,7 @@ def list_product_streams(ctx, product_stream_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_product_stream(ctx, product_stream_name, inactive, ofuri, **params):
"""Retrieve Product Stream."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -423,7 +423,8 @@ def get_product_stream(ctx, product_stream_name, inactive, ofuri, **params):
},
)
@click.pass_context
def get_product_stream_components(ctx, product_stream_name, ofuri, **params):
@progress_bar(is_updatable=True)
def get_product_stream_components(ctx, product_stream_name, ofuri, operation_status, **params):
"""Retrieve Product Stream latest Components."""
if not ofuri and not product_stream_name:
click.echo(ctx.get_help())
Expand All @@ -439,6 +440,8 @@ def get_product_stream_components(ctx, product_stream_name, ofuri, **params):
params["ofuri"] = ps["ofuri"]
if ofuri:
params["ofuri"] = ofuri

operation_status.stop()
ctx.invoke(list_components, **params)


Expand All @@ -458,7 +461,7 @@ def get_product_stream_components(ctx, product_stream_name, ofuri, **params):
help="Generate spdx manifest (json).",
)
@click.pass_context
@progress_bar
@progress_bar()
def get_product_stream_manifest(ctx, product_stream_name, ofuri, spdx_json_format):
"""Retrieve Product Stream manifest."""
if not ofuri and not product_stream_name:
Expand Down Expand Up @@ -527,7 +530,7 @@ def list_software_builds(ctx, software_build_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_software_build(ctx, software_build_name, **params):
"""Retrieve SoftwareBuild."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -560,7 +563,7 @@ def products(ctx):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def list_products(ctx, product_name, **params):
"""Retrieve a list of Software Builds."""
session = CommunityComponentService.create_session()
Expand All @@ -587,7 +590,7 @@ def list_products(ctx, product_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_product(ctx, product_name, ofuri, **params):
"""Retrieve Product."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -622,7 +625,7 @@ def product_versions(ctx):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def list_product_versions(ctx, product_version_name, **params):
"""Retrieve a list of Product Versions."""
session = CommunityComponentService.create_session()
Expand Down Expand Up @@ -652,7 +655,7 @@ def list_product_versions(ctx, product_version_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_product_version(ctx, product_version_name, ofuri, **params):
"""Retrieve ProductVersion."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -687,7 +690,7 @@ def product_variants(ctx):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def list_product_variants(ctx, product_variant_name, **params):
"""Retrieve a list of Product Variants."""
session = CommunityComponentService.create_session()
Expand Down Expand Up @@ -717,7 +720,7 @@ def list_product_variants(ctx, product_variant_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_product_variant(ctx, product_variant_name, ofuri, **params):
"""Retrieve ProductVariant."""
is_params_empty = [False for v in params.values() if v]
Expand Down Expand Up @@ -750,7 +753,7 @@ def channels(ctx):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def list_channels(ctx, channel_name, **params):
"""Retrieve a list of Channels."""
session = CommunityComponentService.create_session()
Expand All @@ -777,7 +780,7 @@ def list_channels(ctx, channel_name, **params):
},
)
@click.pass_context
@progress_bar
@progress_bar()
def get_channel(ctx, channel_name, ofuri, **params):
"""Retrieve ProductVariant."""
is_params_empty = [False for v in params.values() if v]
Expand Down
Loading