summaryrefslogtreecommitdiff
path: root/buildstream/_frontend/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildstream/_frontend/cli.py')
-rw-r--r--buildstream/_frontend/cli.py98
1 files changed, 18 insertions, 80 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index b3c4634a9..e3c5059b9 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -1,7 +1,6 @@
import os
import sys
from contextlib import ExitStack
-from fnmatch import fnmatch
from functools import partial
from tempfile import TemporaryDirectory
@@ -901,38 +900,6 @@ def workspace_list(app):
#############################################################
# Artifact Commands #
#############################################################
-def _classify_artifacts(names, cas, project_directory):
- element_targets = []
- artifact_refs = []
- element_globs = []
- artifact_globs = []
-
- for name in names:
- if name.endswith('.bst'):
- if any(c in "*?[" for c in name):
- element_globs.append(name)
- else:
- element_targets.append(name)
- else:
- if any(c in "*?[" for c in name):
- artifact_globs.append(name)
- else:
- artifact_refs.append(name)
-
- if element_globs:
- for dirpath, _, filenames in os.walk(project_directory):
- for filename in filenames:
- element_path = os.path.join(dirpath, filename).lstrip(project_directory).lstrip('/')
- if any(fnmatch(element_path, glob) for glob in element_globs):
- element_targets.append(element_path)
-
- if artifact_globs:
- artifact_refs.extend(ref for ref in cas.list_refs()
- if any(fnmatch(ref, glob) for glob in artifact_globs))
-
- return element_targets, artifact_refs
-
-
@cli.group(short_help="Manipulate cached artifacts")
def artifact():
"""Manipulate cached artifacts"""
@@ -1111,53 +1078,24 @@ def artifact_push(app, elements, deps, remote):
@click.pass_obj
def artifact_log(app, artifacts):
"""Show logs of all artifacts"""
- from .._exceptions import CASError
- from .._message import MessageType
- from .._pipeline import PipelineSelection
- from ..storage._casbaseddirectory import CasBasedDirectory
-
- with ExitStack() as stack:
- stack.enter_context(app.initialized())
- cache = app.context.artifactcache
-
- elements, artifacts = _classify_artifacts(artifacts, cache.cas,
- app.project.directory)
-
- vdirs = []
- extractdirs = []
- if artifacts:
- for ref in artifacts:
- try:
- cache_id = cache.cas.resolve_ref(ref, update_mtime=True)
- vdir = CasBasedDirectory(cache.cas, cache_id)
- vdirs.append(vdir)
- except CASError as e:
- app._message(MessageType.WARN, "Artifact {} is not cached".format(ref), detail=str(e))
- continue
- if elements:
- elements = app.stream.load_selection(elements, selection=PipelineSelection.NONE)
- for element in elements:
- if not element._cached():
- app._message(MessageType.WARN, "Element {} is not cached".format(element))
- continue
- ref = cache.get_artifact_fullname(element, element._get_cache_key())
- cache_id = cache.cas.resolve_ref(ref, update_mtime=True)
- vdir = CasBasedDirectory(cache.cas, cache_id)
- vdirs.append(vdir)
-
- for vdir in vdirs:
- # NOTE: If reading the logs feels unresponsive, here would be a good place to provide progress information.
- logsdir = vdir.descend(["logs"])
- td = stack.enter_context(TemporaryDirectory())
- logsdir.export_files(td, can_link=True)
- extractdirs.append(td)
-
- for extractdir in extractdirs:
- for log in (os.path.join(extractdir, log) for log in os.listdir(extractdir)):
- # NOTE: Should click gain the ability to pass files to the pager this can be optimised.
- with open(log) as f:
- data = f.read()
- click.echo_via_pager(data)
+ with app.initialized():
+ logsdirs = app.stream.artifact_log(artifacts)
+
+ with ExitStack() as stack:
+ extractdirs = []
+ for logsdir in logsdirs:
+ # NOTE: If reading the logs feels unresponsive, here would be a good place
+ # to provide progress information.
+ td = stack.enter_context(TemporaryDirectory())
+ logsdir.export_files(td, can_link=True)
+ extractdirs.append(td)
+
+ for extractdir in extractdirs:
+ for log in (os.path.join(extractdir, log) for log in os.listdir(extractdir)):
+ # NOTE: Should click gain the ability to pass files to the pager this can be optimised.
+ with open(log) as f:
+ data = f.read()
+ click.echo_via_pager(data)
##################################################################