Implement operations used in the DeviceToDevice protocol.
[chromium-blink-merge.git] / testing / chromoting / download_test_files.py
blob57fb9a19ed7eb6114189001af03a9c0ceeb3fa71
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """A script to download files required for Remoting integration tests from GCS.
7 The script expects 2 parameters:
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.
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 """
18 import argparse
19 import ntpath
20 import os
21 import subprocess
22 import sys
25 def main():
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 .')
34 if len(sys.argv) < 3:
35 parser.print_help()
36 sys.exit(1)
38 args = parser.parse_args()
39 if not args.files or not args.output_folder:
40 parser.print_help()
41 sys.exit(1)
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, e:
53 print e.output
54 sys.exit(1)
56 if __name__ == '__main__':
57 main()