| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright 2016 Google Inc. | |
| 4 # | |
| 5 # Use of this source code is governed by a BSD-style license that can be | |
| 6 # found in the LICENSE file. | |
| 7 | |
| 8 | |
| 9 import os | |
| 10 import shutil | |
| 11 import subprocess | |
| 12 | |
| 13 | |
| 14 GS_GM_BUCKET = 'chromium-skia-gm' | |
| 15 | |
| 16 GS_SUBDIR_TMPL_SKP = 'playback_%s/skps' | |
| 17 | |
| 18 VERSION_FILE_SKP = 'SKP_VERSION' | |
| 19 | |
| 20 | |
| 21 def download_dir(skia_dir, tmp_dir, version_file, gs_path_tmpl, dst_dir): | |
| 22 # Ensure that the tmp_dir exists. | |
| 23 if not os.path.isdir(tmp_dir): | |
| 24 os.makedirs(tmp_dir) | |
| 25 | |
| 26 # Get the expected version. | |
| 27 with open(os.path.join(skia_dir, version_file)) as f: | |
| 28 expected_version = f.read().rstrip() | |
| 29 | |
| 30 print 'Expected %s = %s' % (version_file, expected_version) | |
| 31 | |
| 32 # Get the actually-downloaded version, if we have one. | |
| 33 actual_version_file = os.path.join(tmp_dir, version_file) | |
| 34 try: | |
| 35 with open(actual_version_file) as f: | |
| 36 actual_version = f.read().rstrip() | |
| 37 except IOError: | |
| 38 actual_version = -1 | |
| 39 | |
| 40 print 'Actual %s = %s' % (version_file, actual_version) | |
| 41 | |
| 42 # If we don't have the desired version, download it. | |
| 43 if actual_version != expected_version: | |
| 44 if actual_version != -1: | |
| 45 os.remove(actual_version_file) | |
| 46 if os.path.isdir(dst_dir): | |
| 47 shutil.rmtree(dst_dir) | |
| 48 os.makedirs(dst_dir) | |
| 49 gs_path = 'gs://%s/%s/*' % (GS_GM_BUCKET, gs_path_tmpl % expected_version) | |
| 50 print 'Downloading from %s' % gs_path | |
| 51 subprocess.check_call(['gsutil', 'cp', '-R', gs_path, dst_dir]) | |
| 52 with open(actual_version_file, 'w') as f: | |
| 53 f.write(expected_version) | |
| OLD | NEW |