xref: /aosp_15_r20/external/angle/build/fuchsia/gcs_download.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2022 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6import sys
7import tarfile
8import tempfile
9
10sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
11                                             'test')))
12from gs_util_wrapper import run_gsutil
13
14def DownloadAndUnpackFromCloudStorage(url, output_dir):
15  """Fetches a tarball from GCS and uncompresses it to |output_dir|."""
16
17  tmp_file = 'image.tgz'
18  with tempfile.TemporaryDirectory() as tmp_d:
19    tmp_file_location = os.path.join(tmp_d, tmp_file)
20    run_gsutil(['cp', url, tmp_file_location])
21    tarfile.open(name=tmp_file_location,
22                 mode='r|gz').extractall(path=output_dir)
23