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