You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:53:02 UTC

[buildstream] 05/13: cli: Factor virtual directory loading out of artifact_log

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch richardmaw/artifact-subcommands
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 43242b56fffc2789da269caac782adedf5b1cb5e
Author: Richard Maw <ri...@codethink.co.uk>
AuthorDate: Wed Dec 12 18:27:57 2018 +0000

    cli: Factor virtual directory loading out of artifact_log
---
 buildstream/_frontend/cli.py | 55 +++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 4b3fcba..ee4a912 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -7,6 +7,7 @@ from tempfile import TemporaryDirectory
 import click
 from .. import _yaml
 from .._exceptions import BstError, LoadError, AppError
+from ..storage._casbaseddirectory import CasBasedDirectory
 from .._versions import BST_FORMAT_VERSION
 from .complete import main_bashcomplete, complete_path, CompleteUnhandled
 
@@ -1004,6 +1005,35 @@ def _classify_artifacts(names, cas, project_directory):
     return targets, refs
 
 
+def _load_vdirs(app, elements, artifacts):
+    from .._exceptions import CASError
+    from .._message import MessageType
+    from .._pipeline import PipelineSelection
+    cache = app.context.artifactcache
+    vdirs = []
+
+    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)
+
+    return vdirs
+
 
 @cli.group(short_help="Manipulate cached artifacts")
 def artifact():
@@ -1018,10 +1048,6 @@ def artifact():
 @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())
@@ -1035,27 +1061,8 @@ def artifact_log(app, artifacts):
             if element is not None:
                 elements = [element]
 
-        vdirs = []
+        vdirs = _load_vdirs(app, elements, artifacts)
         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.