diff options
Diffstat (limited to 'buildstream/_artifactcache.py')
-rw-r--r-- | buildstream/_artifactcache.py | 84 |
1 files changed, 35 insertions, 49 deletions
diff --git a/buildstream/_artifactcache.py b/buildstream/_artifactcache.py index 5404dc12e..bc0032bec 100644 --- a/buildstream/_artifactcache.py +++ b/buildstream/_artifactcache.py @@ -19,7 +19,6 @@ import multiprocessing import os -import string from collections.abc import Mapping from .types import _KeyStrength @@ -29,6 +28,7 @@ from . import utils from . import _yaml from ._cas import CASRemote, CASRemoteSpec +from .storage._casbaseddirectory import CasBasedDirectory CACHE_SIZE_FILE = "cache_size" @@ -112,37 +112,6 @@ class ArtifactCache(): self._calculate_cache_quota() - # get_artifact_fullname() - # - # Generate a full name for an artifact, including the - # project namespace, element name and cache key. - # - # This can also be used as a relative path safely, and - # will normalize parts of the element name such that only - # digits, letters and some select characters are allowed. - # - # Args: - # element (Element): The Element object - # key (str): The element's cache key - # - # Returns: - # (str): The relative path for the artifact - # - def get_artifact_fullname(self, element, key): - project = element._get_project() - - # Normalize ostree ref unsupported chars - valid_chars = string.digits + string.ascii_letters + '-._' - element_name = ''.join([ - x if x in valid_chars else '_' - for x in element.normal_name - ]) - - assert key is not None - - # assume project and element names are not allowed to contain slashes - return '{0}/{1}/{2}'.format(project.name, element_name, key) - # setup_remotes(): # # Sets up which remotes to use @@ -241,7 +210,7 @@ class ArtifactCache(): for key in (strong_key, weak_key): if key: try: - ref = self.get_artifact_fullname(element, key) + ref = element.get_artifact_name(key) self.cas.update_mtime(ref) except CASError: @@ -521,7 +490,7 @@ class ArtifactCache(): # Returns: True if the artifact is in the cache, False otherwise # def contains(self, element, key): - ref = self.get_artifact_fullname(element, key) + ref = element.get_artifact_name(key) return self.cas.contains(ref) @@ -538,19 +507,21 @@ class ArtifactCache(): # Returns: True if the subdir exists & is populated in the cache, False otherwise # def contains_subdir_artifact(self, element, key, subdir): - ref = self.get_artifact_fullname(element, key) + ref = element.get_artifact_name(key) return self.cas.contains_subdir_artifact(ref, subdir) # list_artifacts(): # # List artifacts in this cache in LRU order. # + # Args: + # glob (str): An option glob expression to be used to list artifacts satisfying the glob + # # Returns: - # ([str]) - A list of artifact names as generated by - # `ArtifactCache.get_artifact_fullname` in LRU order + # ([str]) - A list of artifact names as generated in LRU order # - def list_artifacts(self): - return self.cas.list_refs() + def list_artifacts(self, *, glob=None): + return self.cas.list_refs(glob=glob) # remove(): # @@ -559,8 +530,7 @@ class ArtifactCache(): # # Args: # ref (artifact_name): The name of the artifact to remove (as - # generated by - # `ArtifactCache.get_artifact_fullname`) + # generated by `Element.get_artifact_name`) # # Returns: # (int): The amount of space recovered in the cache, in bytes @@ -606,7 +576,7 @@ class ArtifactCache(): # Returns: path to extracted artifact # def extract(self, element, key, subdir=None): - ref = self.get_artifact_fullname(element, key) + ref = element.get_artifact_name(key) path = os.path.join(self.extractdir, element._get_project().name, element.normal_name) @@ -622,7 +592,7 @@ class ArtifactCache(): # keys (list): The cache keys to use # def commit(self, element, content, keys): - refs = [self.get_artifact_fullname(element, key) for key in keys] + refs = [element.get_artifact_name(key) for key in keys] self.cas.commit(refs, content) @@ -638,8 +608,8 @@ class ArtifactCache(): # subdir (str): A subdirectory to limit the comparison to # def diff(self, element, key_a, key_b, *, subdir=None): - ref_a = self.get_artifact_fullname(element, key_a) - ref_b = self.get_artifact_fullname(element, key_b) + ref_a = element.get_artifact_name(key_a) + ref_b = element.get_artifact_name(key_b) return self.cas.diff(ref_a, ref_b, subdir=subdir) @@ -700,7 +670,7 @@ class ArtifactCache(): # (ArtifactError): if there was an error # def push(self, element, keys): - refs = [self.get_artifact_fullname(element, key) for key in list(keys)] + refs = [element.get_artifact_name(key) for key in list(keys)] project = element._get_project() @@ -738,7 +708,7 @@ class ArtifactCache(): # (bool): True if pull was successful, False if artifact was not available # def pull(self, element, key, *, progress=None, subdir=None, excluded_subdirs=None): - ref = self.get_artifact_fullname(element, key) + ref = element.get_artifact_name(key) project = element._get_project() @@ -850,11 +820,27 @@ class ArtifactCache(): # newkey (str): A new cache key for the artifact # def link_key(self, element, oldkey, newkey): - oldref = self.get_artifact_fullname(element, oldkey) - newref = self.get_artifact_fullname(element, newkey) + oldref = element.get_artifact_name(oldkey) + newref = element.get_artifact_name(newkey) self.cas.link_ref(oldref, newref) + # get_artifact_logs(): + # + # Get the logs of an existing artifact + # + # Args: + # ref (str): The ref of the artifact + # + # Returns: + # logsdir (CasBasedDirectory): A CasBasedDirectory containing the artifact's logs + # + def get_artifact_logs(self, ref): + descend = ["logs"] + cache_id = self.cas.resolve_ref(ref, update_mtime=True) + vdir = CasBasedDirectory(self.cas, cache_id).descend(descend) + return vdir + ################################################ # Local Private Methods # ################################################ |