def use_cached_files(self, cache_key):
    # This implementation fetches the appropriate tarball and extracts it.
    remote_path = self._remote_path_for_key(cache_key)
    try:
      # Send an HTTP request for the tarball.
      response = self._request('GET', remote_path)
      if response is None:
        return None

      done = False
      with temporary_file() as outfile:
        total_bytes = 0
        # Read the data in a loop.
        while not done:
          data = response.read(self.READ_SIZE)
          outfile.write(data)
          if len(data) < self.READ_SIZE:
            done = True
          total_bytes += len(data)
        outfile.close()
        self.log.debug('Read %d bytes from artifact cache at %s' %
                       (total_bytes,self._url_string(remote_path)))

        # Extract the tarfile.
        artifact = TarballArtifact(self.artifact_root, outfile.name, self.compress)
        artifact.extract()
        return artifact
    except Exception as e:
      self.log.warn('Error while reading from remote artifact cache: %s' % e)
      return None
Exemple #2
0
  def use_cached_files(self, cache_key):
    # This implementation fetches the appropriate tarball and extracts it.
    remote_path = self._remote_path_for_key(cache_key)
    try:
      # Send an HTTP request for the tarball.
      response = self._request('GET', remote_path)
      if response is None:
        return None

      done = False
      with temporary_file() as outfile:
        total_bytes = 0
        # Read the data in a loop.
        while not done:
          data = response.read(self.READ_SIZE)
          outfile.write(data)
          if len(data) < self.READ_SIZE:
            done = True
          total_bytes += len(data)
        outfile.close()
        self.log.debug('Read %d bytes from artifact cache at %s' %
                       (total_bytes,self._url_string(remote_path)))

        # Extract the tarfile.
        artifact = TarballArtifact(self.artifact_root, outfile.name, self.compress)
        artifact.extract()
        return artifact
    except Exception as e:
      self.log.warn('Error while reading from remote artifact cache: %s' % e)
      return None
 def use_cached_files(self, cache_key):
   try:
     tarfile = self._cache_file_for_key(cache_key)
     if os.path.exists(tarfile):
       artifact = TarballArtifact(self.artifact_root, tarfile, self._compress)
       artifact.extract()
       return artifact
     else:
       return None
   except Exception as e:
     self.log.warn('Error while reading from local artifact cache: %s' % e)
     return None
 def use_cached_files(self, cache_key):
     try:
         tarfile = self._cache_file_for_key(cache_key)
         if os.path.exists(tarfile):
             artifact = TarballArtifact(self.artifact_root, tarfile,
                                        self._compress)
             artifact.extract()
             return artifact
         else:
             return None
     except Exception as e:
         self.log.warn('Error while reading from local artifact cache: %s' %
                       e)
         return None