Example #1
0
    def get_digest(self, cache_dir, element, element_key):

        artifact_ref = element.get_artifact_name(element_key)
        artifact_dir = os.path.join(cache_dir, "artifacts", "refs")
        artifact_proto = artifact_pb2.Artifact()
        with open(os.path.join(artifact_dir, artifact_ref), "rb") as f:
            artifact_proto.ParseFromString(f.read())
        return artifact_proto.files
Example #2
0
    def get_artifact_proto(self, artifact_name):
        artifact_proto = artifact_pb2.Artifact()
        artifact_path = os.path.join(self.artifactdir, artifact_name)

        try:
            with open(artifact_path, "rb") as f:
                artifact_proto.ParseFromString(f.read())
        except FileNotFoundError:
            return None

        return artifact_proto
Example #3
0
 def extract_buildtree(self, cache_dir, tmpdir, ref):
     artifact = artifact_pb2.Artifact()
     try:
         with open(os.path.join(cache_dir, "artifacts", "refs", ref),
                   "rb") as f:
             artifact.ParseFromString(f.read())
     except FileNotFoundError:
         yield None
     else:
         if str(artifact.buildtree):
             with self._extract_subdirectory(tmpdir,
                                             artifact.buildtree) as f:
                 yield f
         else:
             yield None
Example #4
0
    def get_cas_files(self, artifact_proto_digest):

        reachable = set()

        def reachable_dir(digest):
            self.cas._reachable_refs_dir(reachable,
                                         digest,
                                         update_mtime=False,
                                         check_exists=True)

        try:
            artifact_proto_path = self.cas.objpath(artifact_proto_digest)
            if not os.path.exists(artifact_proto_path):
                return None

            artifact_proto = artifact_pb2.Artifact()
            try:
                with open(artifact_proto_path, "rb") as f:
                    artifact_proto.ParseFromString(f.read())
            except FileNotFoundError:
                return None

            if str(artifact_proto.files):
                reachable_dir(artifact_proto.files)

            if str(artifact_proto.buildtree):
                reachable_dir(artifact_proto.buildtree)

            if str(artifact_proto.public_data):
                if not os.path.exists(
                        self.cas.objpath(artifact_proto.public_data)):
                    return None

            for log_file in artifact_proto.logs:
                if not os.path.exists(self.cas.objpath(log_file.digest)):
                    return None

            return artifact_proto.files

        except CASError:
            return None

        except FileNotFoundError:
            return None