summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-08-16 11:05:52 +0100
committerJames Ennis <james.ennis@codethink.co.uk>2019-08-27 15:21:34 +0100
commitabbcc263563d6c3bd7b76f815576bf6f2da96707 (patch)
tree47b4a4ca62287a0439db13e0710a3446e0ebc887
parent84fc72e064c2eebf6e0e2179cb482ceecac6ea9b (diff)
downloadbuildstream-abbcc263563d6c3bd7b76f815576bf6f2da96707.tar.gz
cli.py: Introduce bst artifact show
bst artifact show can be used to determine which element names, artifact refs (also by glob expression) are present within the artifact cache.
-rw-r--r--src/buildstream/_frontend/cli.py17
-rw-r--r--src/buildstream/_frontend/widget.py35
-rw-r--r--src/buildstream/_stream.py22
-rw-r--r--tests/frontend/completions.py1
4 files changed, 75 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
diff --git a/tests/frontend/completions.py b/tests/frontend/completions.py
index e9fa25b73..a254d9082 100644
--- a/tests/frontend/completions.py
+++ b/tests/frontend/completions.py
@@ -66,6 +66,7 @@ ARTIFACT_COMMANDS = [
'pull ',
'log ',
'list-contents ',
+ 'show ',
]
WORKSPACE_COMMANDS = [