borenet | d9fa758 | 2016-02-18 08:05:48 -0800 | [diff] [blame] | 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 |
borenet | a7a6f2e | 2016-02-29 05:57:31 -0800 | [diff] [blame] | 10 | import shutil |
borenet | d9fa758 | 2016-02-18 08:05:48 -0800 | [diff] [blame] | 11 | import subprocess |
borenet | d9fa758 | 2016-02-18 08:05:48 -0800 | [diff] [blame] | 12 | |
borenet | a7a6f2e | 2016-02-29 05:57:31 -0800 | [diff] [blame] | 13 | |
borenet | d9fa758 | 2016-02-18 08:05:48 -0800 | [diff] [blame] | 14 | GS_GM_BUCKET = 'chromium-skia-gm' |
borenet | d9fa758 | 2016-02-18 08:05:48 -0800 | [diff] [blame] | 15 | |
borenet | a7a6f2e | 2016-02-29 05:57:31 -0800 | [diff] [blame] | 16 | GS_SUBDIR_TMPL_SK_IMAGE = 'skimage/v%s' |
| 17 | GS_SUBDIR_TMPL_SKP = 'playback_%s/skps' |
| 18 | |
borenet | a7a6f2e | 2016-02-29 05:57:31 -0800 | [diff] [blame] | 19 | VERSION_FILE_SK_IMAGE = 'SK_IMAGE_VERSION' |
| 20 | VERSION_FILE_SKP = 'SKP_VERSION' |
| 21 | |
borenet | d9fa758 | 2016-02-18 08:05:48 -0800 | [diff] [blame] | 22 | |
borenet | a7a6f2e | 2016-02-29 05:57:31 -0800 | [diff] [blame] | 23 | def download_dir(skia_dir, tmp_dir, version_file, gs_path_tmpl, dst_dir): |
| 24 | # Ensure that the tmp_dir exists. |
| 25 | if not os.path.isdir(tmp_dir): |
| 26 | os.makedirs(tmp_dir) |
| 27 | |
| 28 | # Get the expected version. |
| 29 | with open(os.path.join(skia_dir, version_file)) as f: |
| 30 | expected_version = f.read().rstrip() |
| 31 | |
| 32 | print 'Expected %s = %s' % (version_file, expected_version) |
| 33 | |
| 34 | # Get the actually-downloaded version, if we have one. |
| 35 | actual_version_file = os.path.join(tmp_dir, version_file) |
| 36 | try: |
| 37 | with open(actual_version_file) as f: |
| 38 | actual_version = f.read().rstrip() |
| 39 | except IOError: |
| 40 | actual_version = -1 |
| 41 | |
| 42 | print 'Actual %s = %s' % (version_file, actual_version) |
| 43 | |
| 44 | # If we don't have the desired version, download it. |
| 45 | if actual_version != expected_version: |
| 46 | if actual_version != -1: |
| 47 | os.remove(actual_version_file) |
| 48 | if os.path.isdir(dst_dir): |
| 49 | shutil.rmtree(dst_dir) |
| 50 | os.makedirs(dst_dir) |
| 51 | gs_path = 'gs://%s/%s/*' % (GS_GM_BUCKET, gs_path_tmpl % expected_version) |
| 52 | print 'Downloading from %s' % gs_path |
| 53 | subprocess.check_call(['gsutil', 'cp', '-R', gs_path, dst_dir]) |
| 54 | with open(actual_version_file, 'w') as f: |
| 55 | f.write(expected_version) |