OLD | NEW |
---|---|
(Empty) | |
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. | |
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 | |
18 import argparse | |
19 import ntpath | |
20 import os | |
21 import subprocess | |
22 import sys | |
23 | |
24 | |
25 def 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 cp %s %s' % (line, output_file)] | |
luqui
2015/07/15 18:00:51
1. this should be gsutil.py.
2. the arguments sho
luqui
2015/07/15 18:02:07
Oh I see, you have shell=True, so (2) isn't necess
| |
50 try: | |
51 subprocess.check_output(cp_cmd, stderr=subprocess.STDOUT, | |
52 shell=True) | |
53 except subprocess.CalledProcessError, e: | |
54 print e.output | |
55 sys.exit(1) | |
56 | |
57 if __name__ == '__main__': | |
58 main() | |
OLD | NEW |