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