summaryrefslogtreecommitdiff
path: root/buildstream/_stream.py
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-03-05 16:02:19 +0000
committerJürg Billeter <j@bitron.ch>2019-03-13 17:04:04 +0000
commit01abedd6f1102c342f6c205842f9769893a142b1 (patch)
tree45480a2acb6dea6bb61e15f2d95a58c639509ab4 /buildstream/_stream.py
parent8e630cac4ef5559c7ddfdbf4ad951c9dec5caf1d (diff)
downloadbuildstream-01abedd6f1102c342f6c205842f9769893a142b1.tar.gz
cli.py: Add artifact delete command
This command provides a --no-prune option because or a large cache, pruning can be an expensive operation. If a developer wishes to quicky rebuild an artifact, they may consider using this option.
Diffstat (limited to 'buildstream/_stream.py')
-rw-r--r--buildstream/_stream.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index b0fce3817..5c880427c 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -30,11 +30,12 @@ from contextlib import contextmanager, suppress
from fnmatch import fnmatch
from ._artifactelement import verify_artifact_ref
-from ._exceptions import StreamError, ImplError, BstError, ArtifactElementError, set_last_task_error
+from ._exceptions import StreamError, ImplError, BstError, ArtifactElementError, CASCacheError, set_last_task_error
from ._message import Message, MessageType
from ._scheduler import Scheduler, SchedStatus, TrackQueue, FetchQueue, BuildQueue, PullQueue, PushQueue
from ._pipeline import Pipeline, PipelineSelection
from ._profile import Topics, profile_start, profile_end
+from .types import _KeyStrength
from . import utils, _yaml, _site
from . import Scope, Consistency
@@ -520,6 +521,45 @@ class Stream():
return logsdirs
+ # artifact_delete()
+ #
+ # Remove artifacts from the local cache
+ #
+ # Args:
+ # targets (str): Targets to remove
+ # no_prune (bool): Whether to prune the unreachable refs, default False
+ #
+ def artifact_delete(self, targets, no_prune):
+ # Return list of Element and/or ArtifactElement objects
+ target_objects = self.load_selection(targets, selection=PipelineSelection.NONE, load_refs=True)
+
+ # Some of the targets may refer to the same key, so first obtain a
+ # set of the refs to be removed.
+ remove_refs = set()
+ for obj in target_objects:
+ for key_strength in [_KeyStrength.STRONG, _KeyStrength.WEAK]:
+ key = obj._get_cache_key(strength=key_strength)
+ remove_refs.add(obj.get_artifact_name(key=key))
+
+ ref_removed = False
+ for ref in remove_refs:
+ try:
+ self._artifacts.remove(ref, defer_prune=True)
+ except CASCacheError as e:
+ self._message(MessageType.WARN, "{}".format(e))
+ continue
+
+ self._message(MessageType.INFO, "Removed: {}".format(ref))
+ ref_removed = True
+
+ # Prune the artifact cache
+ if ref_removed and not no_prune:
+ with self._context.timed_activity("Pruning artifact cache"):
+ self._artifacts.prune()
+
+ if not ref_removed:
+ self._message(MessageType.INFO, "No artifacts were removed")
+
# source_checkout()
#
# Checkout sources of the target element to the specified location