blob: e4314dd78fa100ff2e606b890a41f27f8d32f16b [file] [log] [blame]
borenetd9fa7582016-02-18 08:05:48 -08001#!/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
9import os
boreneta7a6f2e2016-02-29 05:57:31 -080010import shutil
borenetd9fa7582016-02-18 08:05:48 -080011import subprocess
borenetd9fa7582016-02-18 08:05:48 -080012
boreneta7a6f2e2016-02-29 05:57:31 -080013
borenetd9fa7582016-02-18 08:05:48 -080014GS_GM_BUCKET = 'chromium-skia-gm'
borenetd9fa7582016-02-18 08:05:48 -080015
boreneta7a6f2e2016-02-29 05:57:31 -080016GS_SUBDIR_TMPL_SK_IMAGE = 'skimage/v%s'
17GS_SUBDIR_TMPL_SKP = 'playback_%s/skps'
18
boreneta7a6f2e2016-02-29 05:57:31 -080019VERSION_FILE_SK_IMAGE = 'SK_IMAGE_VERSION'
20VERSION_FILE_SKP = 'SKP_VERSION'
21
borenetd9fa7582016-02-18 08:05:48 -080022
boreneta7a6f2e2016-02-29 05:57:31 -080023def 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)