Index: testing/chromoting/download_test_files.py |
diff --git a/testing/chromoting/download_test_files.py b/testing/chromoting/download_test_files.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..653dcdf45837092f8f31b1398c1d268f8e6101ed |
--- /dev/null |
+++ b/testing/chromoting/download_test_files.py |
@@ -0,0 +1,69 @@ |
+#!/usr/bin/python |
+# |
+"""A script to download files required for Remoting integration tests from GCS. |
+ |
+ The script expects 2 parameters: |
+ |
+ input_files: a file containing the full path in GCS to each file that is to |
+ be downloaded. |
+ output_folder: the folder to which the specified files should be downloaded. |
+ |
+ This scripts expects that its execution is done on a machine where the |
+ credentials are correctly setup to obtain the required permissions for |
+ downloading files from the specified GCS buckets. |
+""" |
+ |
+import argparse |
+import ntpath |
+import os |
+import subprocess |
+import sys |
+ |
+ |
+def CopyFromGCS(source, destination): |
+ """Given path to a source file in GCS, copies it to the specified destination. |
+ |
+ Assumes gsutil is accessible from command-shell (i.e., is in $PATH), and |
+ required privileges to access GCS are available. |
+ |
+ Args: |
+ source: path to file in GCS. |
joedow
2015/07/13 19:10:12
nit: capitalize first letter of the first word.
anandc
2015/07/14 01:03:07
Acknowledged.
|
+ destination: path to destination on local file system. |
+ Returns: |
+ True on success, False on failure. |
+ """ |
+ |
+ cp_cmd = ['gsutil cp %s %s' % (source, destination)] |
+ process = subprocess.Popen(cp_cmd, shell=True, |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ process.communicate() |
+ if not process.returncode: |
+ return True |
+ return False |
joedow
2015/07/13 19:10:12
Is it pythonic to just use:
return (not process.re
anandc
2015/07/14 01:03:07
Got rid of this function because it wasn't really
|
+ |
+ |
+def main(): |
+ |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument('-i', '--input_files', |
+ help='File specifying files to be downloaded .') |
+ parser.add_argument( |
+ '-o', '--output_folder', |
+ help='Folder where specified files should be downloaded .') |
+ |
+ if len(sys.argv) < 3: |
+ parser.print_help() |
+ sys.exit(1) |
+ |
+ args = parser.parse_args() |
+ if not args.input_files or not args.output_folder: |
+ parser.print_help() |
+ sys.exit(1) |
+ |
+ with open(args.input_files) as f: |
+ for line in f: |
+ output_file = os.path.join(args.output_folder, ntpath.basename(line)) |
+ CopyFromGCS(line, output_file) |
+ |
+if __name__ == '__main__': |
+ main() |