def LoadRemoteManifest(url): manifest = manifest_util.SDKManifest() url_stream = None try: manifest_stream = cStringIO.StringIO() url_stream = download.UrlOpen(url) download.DownloadAndComputeHash(url_stream, manifest_stream) except urllib2.URLError as e: raise Error('Unable to read remote manifest from URL "%s".\n %s' % ( url, e)) finally: if url_stream: url_stream.close() try: manifest.LoadDataFromString(manifest_stream.getvalue()) return manifest except manifest_util.Error as e: raise Error('Parsing remote manifest from URL "%s" failed.\n %s' % ( url, e,))
def DownloadToFile(self, url, dest_filename): dest_path = os.path.join(self.archive_cache, dest_filename) sdk_update_common.MakeDirs(os.path.dirname(dest_path)) out_stream = None url_stream = None try: out_stream = open(dest_path, 'wb') url_stream = download.UrlOpen(url) content_length = int(url_stream.info()[HTTP_CONTENT_LENGTH]) progress = download.MakeProgressFunction(content_length) sha1, size = download.DownloadAndComputeHash(url_stream, out_stream, progress) return sha1, size except urllib2.URLError as e: raise Error('Unable to read from URL "%s".\n %s' % (url, e)) except IOError as e: raise Error('Unable to write to file "%s".\n %s' % (dest_filename, e)) finally: if url_stream: url_stream.close() if out_stream: out_stream.close()