diff options
author | Tom Pollard <tom.pollard@codethink.co.uk> | 2019-02-28 17:40:48 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-03-12 18:11:28 +0000 |
commit | 21c4633481575a96139500f919d8bb54a4b7861c (patch) | |
tree | 5cf460dbbbea0263263fcc32c85eb6013a538d51 | |
parent | 9bba8f45880684408c8eed53ed2050689c06306e (diff) | |
download | buildstream-21c4633481575a96139500f919d8bb54a4b7861c.tar.gz |
_artifact.py: Transition element.py __load*() methods
This includes __load_public_data() & __load_build_result().
-rw-r--r-- | buildstream/_artifact.py | 46 | ||||
-rw-r--r-- | buildstream/element.py | 24 |
2 files changed, 52 insertions, 18 deletions
diff --git a/buildstream/_artifact.py b/buildstream/_artifact.py index cf9529889..9c21d8863 100644 --- a/buildstream/_artifact.py +++ b/buildstream/_artifact.py @@ -227,6 +227,52 @@ class Artifact(): return True + # load_public_data(): + # + # Loads the public data from the cached artifact + # + # Returns: + # (dict): The artifacts cached public data + # + def load_public_data(self): + + element = self._element + assert element._cached() + + # Load the public data from the artifact + artifact_vdir, _ = self._get_directory() + meta_file = artifact_vdir._objpath(['meta', 'public.yaml']) + data = _yaml.load(meta_file, shortname='meta/public.yaml') + + return data + + # load_build_result(): + # + # Load the build result from the cached artifact + # + # Args: + # key (str): The key for the artifact to extract + # + # Returns: + # (bool): Whether the artifact of this element present in the artifact cache is of a success + # (str): Short description of the result + # (str): Detailed description of the result + # + def load_build_result(self, key): + + assert key is not None + artifact_vdir, _ = self._get_directory(key) + + meta_file = artifact_vdir._objpath(['meta', 'build-result.yaml']) + if not os.path.exists(meta_file): + build_result = (True, "succeeded", None) + return build_result + + data = _yaml.load(meta_file, shortname='meta/build-result.yaml') + build_result = (data["success"], data.get("description"), data.get("detail")) + + return build_result + # _get_directory(): # # Get a virtual directory for the artifact contents diff --git a/buildstream/element.py b/buildstream/element.py index c805a844c..ce04f8163 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -2766,32 +2766,20 @@ class Element(Plugin): # Loads the public data from the cached artifact # def __load_public_data(self): - self.__assert_cached() assert self.__dynamic_public is None - # Load the public data from the artifact - artifact_vdir, _ = self.__get_artifact_directory() - meta_file = artifact_vdir._objpath(['meta', 'public.yaml']) - self.__dynamic_public = _yaml.load(meta_file, shortname='meta/public.yaml') + self.__dynamic_public = self.__artifact.load_public_data() def __load_build_result(self, keystrength): self.__assert_cached(keystrength=keystrength) assert self.__build_result is None - if keystrength is _KeyStrength.WEAK: - key = self.__weak_cache_key - else: - key = self.__strict_cache_key - - artifact_vdir, _ = self.__get_artifact_directory(key) - - if not artifact_vdir._exists(['meta', 'build-result.yaml']): - self.__build_result = (True, "succeeded", None) - return + # _get_cache_key with _KeyStrength.STRONG returns self.__cache_key, which can be `None` + # leading to a failed assertion from get_artifact_directory() using get_artifact_name(), + # so explicility pass self.__strict_cache_key + key = self.__weak_cache_key if keystrength is _KeyStrength.WEAK else self.__strict_cache_key - result_path = artifact_vdir._objpath(['meta', 'build-result.yaml']) - data = _yaml.load(result_path) - self.__build_result = (data["success"], data.get("description"), data.get("detail")) + self.__build_result = self.__artifact.load_build_result(key) def __get_build_result(self, keystrength): if keystrength is None: |