You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 07:12:40 UTC

[buildstream] 02/06: cli: Factor virtual directory loading out of artifact_log

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

tvb pushed a commit to branch jennis/deprecate_bst_checkout
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit a94ccf0a4beb694ab170afbff19009b5cd9709fc
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
    
    Other artifact subcommands will also need to make use of
    loading virtual directories
---
 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 ae64afa..60a2445 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
 
@@ -1016,6 +1017,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():
@@ -1030,10 +1060,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())
@@ -1042,27 +1068,8 @@ def artifact_log(app, artifacts):
         elements, artifacts = _classify_artifacts(artifacts, cache.cas,
                                                   app.project.directory)
 
-        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.