download_test_files.py 1.7 KB

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