OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Uploads the results of render_skps.py.""" | 6 """Uploads the results of render_skps.py.""" |
7 | 7 |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import sys | 10 import sys |
11 | 11 |
12 from build_step import BuildStep, PLAYBACK_CANNED_ACL | 12 from build_step import BuildStep, BOTO_CREDENTIALS_FILE |
13 from utils import old_gs_utils as gs_utils | 13 from build_step import PLAYBACK_CANNED_ACL, PLAYBACK_FINEGRAINED_ACL_LIST |
14 from py.utils import gs_utils | |
15 from utils import old_gs_utils | |
14 import skia_vars | 16 import skia_vars |
15 | 17 |
18 GS_PREFIX = 'gs://' | |
borenet
2014/07/21 14:07:47
This could go into gs_utils as it may be useful el
| |
16 GS_SUMMARIES_BUCKET = 'gs://chromium-skia-skp-summaries' | 19 GS_SUMMARIES_BUCKET = 'gs://chromium-skia-skp-summaries' |
17 SUBDIR_NAME = 'rendered-skps' | 20 SUBDIR_NAME = 'rendered-skps' |
18 | 21 |
19 | 22 |
20 class UploadRenderedSKPs(BuildStep): | 23 class UploadRenderedSKPs(BuildStep): |
21 | 24 |
22 def __init__(self, attempts=3, **kwargs): | 25 def __init__(self, attempts=3, **kwargs): |
23 super(UploadRenderedSKPs, self).__init__( | 26 super(UploadRenderedSKPs, self).__init__( |
24 attempts=attempts, **kwargs) | 27 attempts=attempts, **kwargs) |
25 | 28 |
26 def _Run(self): | 29 def _Run(self): |
27 # Upload individual image files to Google Storage. | 30 # Upload individual image files to Google Storage. |
28 # | 31 # |
29 # TODO(epoger): Add a "noclobber" mode to gs_utils.upload_dir_contents() | 32 # TODO(epoger): Add a "noclobber" mode to gs_utils.upload_dir_contents() |
30 # and use it here so we don't re-upload image files we already have | 33 # and use it here so we don't re-upload image files we already have |
31 # in Google Storage. | 34 # in Google Storage. |
32 # | 35 # |
33 # TODO(epoger): Change ACLs of files uploaded to Google Storage to | 36 gs_bucket = skia_vars.GetGlobalVariable('googlestorage_bucket') |
rmistry
2014/07/21 13:56:52
In global_variables, gm_summaries_bucket is "chrom
epoger
2014/07/21 20:01:32
Yes, I agree that it would be better for those buc
| |
34 # google.com:READ . See _SetGoogleReadACLs() in | 37 if gs_bucket.startswith(GS_PREFIX): |
35 # https://skia.googlesource.com/buildbot/+/master/slave/skia_slave_scripts/ | 38 gs_bucket = gs_bucket[len(GS_PREFIX):] |
36 # webpages_playback.py | 39 gs = gs_utils.GSUtils(BOTO_CREDENTIALS_FILE) |
40 | |
37 src_dir = os.path.abspath(self.playback_actual_images_dir) | 41 src_dir = os.path.abspath(self.playback_actual_images_dir) |
38 if os.listdir(src_dir): | 42 if os.listdir(src_dir): |
39 dest_dir = posixpath.join( | 43 print 'Uploading image files from %s to bucket=%s, dir=%s' % ( |
40 skia_vars.GetGlobalVariable('googlestorage_bucket'), SUBDIR_NAME) | 44 src_dir, gs_bucket, SUBDIR_NAME) |
41 print 'Uploading image files from %s to %s.' % (src_dir, dest_dir) | 45 gs.upload_dir_contents( |
42 gs_utils.upload_dir_contents( | 46 source_dir=src_dir, dest_bucket=gs_bucket, dest_dir=SUBDIR_NAME, |
43 local_src_dir=src_dir, remote_dest_dir=dest_dir, | 47 predefined_acl=PLAYBACK_CANNED_ACL, |
44 gs_acl=PLAYBACK_CANNED_ACL) | 48 fine_grained_acl_list=PLAYBACK_FINEGRAINED_ACL_LIST) |
45 else: | 49 else: |
46 print ('No image files in %s, so skipping upload to Google Storage.' % | 50 print ('Skipping upload to Google Storage, because no image files in %s' % |
47 src_dir) | 51 src_dir) |
48 | 52 |
49 # Upload image summaries (checksums) to Google Storage. | 53 # Upload image summaries (checksums) to Google Storage. |
50 src_dir = os.path.abspath(self.playback_actual_summaries_dir) | 54 src_dir = os.path.abspath(self.playback_actual_summaries_dir) |
51 filenames = os.listdir(src_dir) | 55 filenames = os.listdir(src_dir) |
52 if filenames: | 56 if filenames: |
53 dest_dir = posixpath.join(GS_SUMMARIES_BUCKET, self._args['builder_name']) | 57 dest_dir = posixpath.join(GS_SUMMARIES_BUCKET, self._args['builder_name']) |
54 print ('Uploading %d image summaries from %s to %s: %s' % ( | 58 print ('Uploading %d image summaries from %s to %s: %s' % ( |
55 len(filenames), src_dir, dest_dir, filenames)) | 59 len(filenames), src_dir, dest_dir, filenames)) |
56 for filename in filenames: | 60 for filename in filenames: |
57 src_path = os.path.join(src_dir, filename) | 61 src_path = os.path.join(src_dir, filename) |
58 dest_path = posixpath.join(dest_dir, filename) | 62 dest_path = posixpath.join(dest_dir, filename) |
59 gs_utils.upload_file( | 63 # It's important to only upload the summary file when it has changed, |
64 # because we use the history of the file in Google Storage to tell us | |
65 # when any of the results changed. | |
66 # | |
67 # TODO(epoger): Once gs_utils.upload_file() supports only_if_modified | |
68 # parameter, start using it, so we can set fine_grained_acl_list like | |
69 # we do above... we'll need that for google.com users to be able to | |
70 # download the summary files. | |
71 old_gs_utils.upload_file( | |
60 local_src_path=src_path, remote_dest_path=dest_path, | 72 local_src_path=src_path, remote_dest_path=dest_path, |
61 gs_acl=PLAYBACK_CANNED_ACL, only_if_modified=True) | 73 gs_acl=PLAYBACK_CANNED_ACL, only_if_modified=True) |
62 else: | 74 else: |
63 print ('No image summaries in %s, so skipping upload to Google Storage.' % | 75 print ('Skipping upload to Google Storage, because no image summaries ' |
64 src_dir) | 76 'in %s' % src_dir) |
65 | 77 |
66 if '__main__' == __name__: | 78 if '__main__' == __name__: |
67 sys.exit(BuildStep.RunBuildStep(UploadRenderedSKPs)) | 79 sys.exit(BuildStep.RunBuildStep(UploadRenderedSKPs)) |
OLD | NEW |