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:04 UTC

[buildstream] 07/13: cli: Add artifact delete subcommand

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 f169bcce8f499e4049bed427900ad615e08ffba8
Author: Richard Maw <ri...@codethink.co.uk>
AuthorDate: Wed Dec 12 18:37:53 2018 +0000

    cli: Add artifact delete subcommand
---
 buildstream/_frontend/cli.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 8ac2078..09d25cc 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -1160,6 +1160,34 @@ def artifact_checkout(app, force, deps, integrate, hardlinks, tar, directory, ar
             vdir.export_files(directory, can_link=hardlinks, can_destroy=force)
 
 
+###################################################################
+#                     Artifact Delete Command                     #
+###################################################################
+@artifact.command(name='delete', short_help="Delete matching artifacts")
+@click.argument('artifacts', type=click.Path(), nargs=-1)
+@click.pass_obj
+def artifact_delete(app, artifacts):
+    '''Delete matching artifacts from the cache'''
+    from .._pipeline import PipelineSelection
+    with app.initialized():
+        cache = app.context.artifactcache
+
+        elements, artifacts = _classify_artifacts(artifacts, cache.cas,
+                                                  app.project.directory)
+
+        if not elements and not artifacts:
+            element = app.context.guess_element()
+            if element is not None:
+                elements = [element]
+
+        if elements:
+            elements = app.stream.load_selection(elements, selection=PipelineSelection.NONE)
+            for element in elements:
+                cache.remove(cache.get_artifact_fullname(element, element._get_cache_key()))
+        for i, ref in enumerate(artifacts, start=1):
+            cache.cas.remove(ref, defer_prune=(i != len(artifacts)))
+
+
 ##################################################################
 #                      DEPRECATED Commands                       #
 ##################################################################