xref: /aosp_15_r20/external/cronet/testing/chromoting/download_test_files.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2015 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
5"""A script to download files required for Remoting integration tests from GCS.
6
7  The script expects 2 parameters:
8
9    input_files: a file containing the full path in GCS to each file that is to
10                be downloaded.
11    output_folder: the folder to which the specified files should be downloaded.
12
13  This scripts expects that its execution is done on a machine where the
14  credentials are correctly setup to obtain the required permissions for
15  downloading files from the specified GCS buckets.
16"""
17
18import argparse
19import ntpath
20import os
21import subprocess
22import sys
23
24
25def main():
26
27  parser = argparse.ArgumentParser()
28  parser.add_argument('-f', '--files',
29                      help='File specifying files to be downloaded .')
30  parser.add_argument(
31      '-o', '--output_folder',
32      help='Folder where specified files should be downloaded .')
33
34  if len(sys.argv) < 3:
35    parser.print_help()
36    sys.exit(1)
37
38  args = parser.parse_args()
39  if not args.files or not args.output_folder:
40    parser.print_help()
41    sys.exit(1)
42
43  # Loop through lines in input file specifying source file locations.
44  with open(args.files) as f:
45    for line in f:
46      # Copy the file to the output folder, with same name as source file.
47      output_file = os.path.join(args.output_folder, ntpath.basename(line))
48      # Download specified file from GCS.
49      cp_cmd = ['gsutil.py', 'cp', line, output_file]
50      try:
51        subprocess.check_call(cp_cmd)
52      except subprocess.CalledProcessError as e:
53        print(e.output)
54        sys.exit(1)
55
56if __name__ == '__main__':
57  main()
58