diff options
Diffstat (limited to 'src/buildstream')
-rw-r--r-- | src/buildstream/_frontend/cli.py | 17 | ||||
-rw-r--r-- | src/buildstream/_frontend/widget.py | 35 | ||||
-rw-r--r-- | src/buildstream/_stream.py | 22 |
3 files changed, 74 insertions, 0 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 5b2e60d49..d02dd4258 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -1004,6 +1004,23 @@ def artifact(): # they are not somehow escaped. +############################################################# +# Artifact show Command # +############################################################# +@artifact.command(name='show', short_help="Show the cached state of artifacts") +@click.option('--deps', '-d', default='none', + type=click.Choice(['build', 'run', 'all', 'none']), + help='The dependencies we also want to show (default: none)') +@click.argument('artifacts', type=click.Path(), nargs=-1) +@click.pass_obj +def artifact_show(app, deps, artifacts): + """show the cached state of artifacts""" + with app.initialized(): + targets = app.stream.artifact_show(artifacts, selection=deps) + click.echo(app.logger.show_state_of_artifacts(targets)) + sys.exit(0) + + ##################################################################### # Artifact Checkout Command # ##################################################################### diff --git a/src/buildstream/_frontend/widget.py b/src/buildstream/_frontend/widget.py index 955680f9b..85fb00768 100644 --- a/src/buildstream/_frontend/widget.py +++ b/src/buildstream/_frontend/widget.py @@ -827,3 +827,38 @@ class LogLine(Widget): text += '\n' return text + + # show_state_of_artifacts() + # + # Show the cached status of artifacts + # + # Example output: + # + # "cached foo.bst" <- If cached locally + # "failed foo.bst" <- If cached locally as a failure + # "available foo.bst" <- If available to download from a remote + # "not cached foo.bst" <- If not cached/available remotely. + # + # Note that artifact names may also be displayed here. + # + # Args: + # targets (list [Element]): Elements (or ArtifactElements) we wish to show the + # cached status of + # + def show_state_of_artifacts(self, targets): + report = '' + p = Profile() + for element in targets: + line = '%{state: >12} %{name}' + line = p.fmt_subst(line, 'name', element.name, fg='yellow') + + if element._cached_success(): + line = p.fmt_subst(line, 'state', "cached", fg='magenta') + elif element._cached(): + line = p.fmt_subst(line, 'state', "failed", fg='red') + else: + line = p.fmt_subst(line, 'state', "not cached", fg='bright_red') + + report += line + '\n' + + return report diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 58d4a0ebd..269cbb542 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -613,6 +613,28 @@ class Stream(): with tarfile.open(location, mode=mode) as tf: virdir.export_to_tar(tf, '.') + # artifact_show() + # + # Show cached artifacts + # + # Args: + # targets (str): Targets to show the cached state of + # + def artifact_show(self, targets, *, + selection=PipelineSelection.NONE): + # Obtain list of Element and/or ArtifactElement objects + target_objects = self.load_selection(targets, + selection=selection, + load_refs=True) + + # XXX: We need to set the name of an ArtifactElement to its ref in order + # to display the expected result in the frontend + for obj in target_objects: + if isinstance(obj, ArtifactElement): + obj.name = obj.get_artifact_name() + + return target_objects + # artifact_log() # # Show the full log of an artifact |