Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: infra/bots/recipe_modules/skia/resources/upload_dm_results.py

Issue 2175373002: Move Skia recipes from build repo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixes, add simulation test to presubmit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 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 """Upload DM output PNG files and JSON summary to Google Storage.""" 6 """Upload DM output PNG files and JSON summary to Google Storage."""
7 7
8
9 import datetime 8 import datetime
9 import json
10 import os 10 import os
11 import shutil 11 import shutil
12 import sys 12 import sys
13 import tempfile 13 import tempfile
14 14
15 def main(dm_dir, build_number, builder_name): 15 def main(dm_dir, git_hash, builder_name, build_number, try_issue, import_path):
16 """Upload DM output PNG files and JSON summary to Google Storage. 16 """Upload DM output PNG files and JSON summary to Google Storage.
17 17
18 dm_dir: path to PNG files and JSON summary (str) 18 dm_dir: path to PNG files and JSON summary (str)
19 git_hash: this build's Git hash (str)
20 builder_name: name of this builder (str)
19 build_number: nth build on this builder (str or int) 21 build_number: nth build on this builder (str or int)
20 builder_name: name of this builder (str) 22 try_issue: Rietveld issue if this is a try job (str, int, or None)
23 import_path: Path to import the gs_utils package (str)
21 """ 24 """
22 # import gs_utils 25 # import gs_utils
23 current_dir = os.path.dirname(os.path.abspath(__file__)) 26 sys.path.insert(0, import_path)
24 sys.path.insert(0, os.path.join(current_dir, "../../../common/py/utils"))
25 import gs_utils 27 import gs_utils
26 28
27 # Private, but Google-readable. 29 # Private, but Google-readable.
28 ACL = gs_utils.GSUtils.PredefinedACL.PRIVATE 30 ACL = gs_utils.GSUtils.PredefinedACL.PRIVATE
29 FINE_ACLS = [( 31 FINE_ACLS = [(
30 gs_utils.GSUtils.IdType.GROUP_BY_DOMAIN, 32 gs_utils.GSUtils.IdType.GROUP_BY_DOMAIN,
31 'google.com', 33 'google.com',
32 gs_utils.GSUtils.Permission.READ 34 gs_utils.GSUtils.Permission.READ
33 )] 35 )]
34 36
35 if not os.path.isfile(os.path.join(dm_dir, 'dm.json')): 37 # Move dm.json and verbose.log to their own directory for easy upload.
36 sys.exit("no dm.json file found in output directory.")
37
38 # Move dm.json to its own directory to make uploading it easier.
39 tmp = tempfile.mkdtemp() 38 tmp = tempfile.mkdtemp()
40 shutil.move(os.path.join(dm_dir, 'dm.json'), 39 shutil.move(os.path.join(dm_dir, 'dm.json'),
41 os.path.join(tmp, 'dm.json')) 40 os.path.join(tmp, 'dm.json'))
41 shutil.move(os.path.join(dm_dir, 'verbose.log'),
42 os.path.join(tmp, 'verbose.log'))
43
44 # Make sure the JSON file parses correctly.
45 json_file_name = os.path.join(tmp, 'dm.json')
46 with open(json_file_name) as jsonFile:
47 try:
48 json.load(jsonFile)
49 except ValueError:
50 json_content = open(json_file_name).read()
51 print >> sys.stderr, "Invalid JSON: \n\n%s\n" % json_content
52 raise
42 53
43 # Only images are left in dm_dir. Upload any new ones. 54 # Only images are left in dm_dir. Upload any new ones.
44 gs = gs_utils.GSUtils() 55 gs = gs_utils.GSUtils()
56 bucket, image_dest_dir = 'chromium-skia-gm', 'dm-images-v1'
57 print 'Uploading images to gs://' + bucket + '/' + image_dest_dir
45 gs.upload_dir_contents(dm_dir, 58 gs.upload_dir_contents(dm_dir,
46 'skia-android-dm', 59 bucket,
47 'dm-images-v1', 60 image_dest_dir,
48 upload_if = gs.UploadIf.IF_NEW, 61 upload_if = gs.UploadIf.ALWAYS,
49 predefined_acl = ACL, 62 predefined_acl = ACL,
50 fine_grained_acl_list = FINE_ACLS) 63 fine_grained_acl_list = FINE_ACLS)
51 64
52 65
53 # /dm-json-v1/year/month/day/hour/build-number/builder/dm.json 66 # /dm-json-v1/year/month/day/hour/git-hash/builder/build-number/dm.json
54 now = datetime.datetime.utcnow() 67 now = datetime.datetime.utcnow()
55 summary_dest_dir = '/'.join(['dm-json-v1', 68 summary_dest_dir = '/'.join(['dm-json-v1',
56 str(now.year ).zfill(4), 69 str(now.year ).zfill(4),
57 str(now.month).zfill(2), 70 str(now.month).zfill(2),
58 str(now.day ).zfill(2), 71 str(now.day ).zfill(2),
59 str(now.hour ).zfill(2), 72 str(now.hour ).zfill(2),
60 str(build_number), 73 git_hash,
61 builder_name]) 74 builder_name,
75 str(build_number)])
62 76
63 # Upload the JSON summary. 77 # Trybot results are further siloed by CL.
78 if try_issue:
79 summary_dest_dir = '/'.join(['trybot', summary_dest_dir, str(try_issue)])
80
81 # Upload the JSON summary and verbose.log.
82 print 'Uploading logs to gs://' + bucket + '/' + summary_dest_dir
64 gs.upload_dir_contents(tmp, 83 gs.upload_dir_contents(tmp,
65 'skia-android-dm', 84 bucket,
66 summary_dest_dir, 85 summary_dest_dir,
67 predefined_acl = ACL, 86 predefined_acl = ACL,
68 fine_grained_acl_list = FINE_ACLS) 87 fine_grained_acl_list = FINE_ACLS)
69 88
70 89
71 # Just for hygiene, put dm.json back. 90 # Just for hygiene, put dm.json and verbose.log back.
72 shutil.move(os.path.join(tmp, 'dm.json'), 91 shutil.move(os.path.join(tmp, 'dm.json'),
73 os.path.join(dm_dir, 'dm.json')) 92 os.path.join(dm_dir, 'dm.json'))
93 shutil.move(os.path.join(tmp, 'verbose.log'),
94 os.path.join(dm_dir, 'verbose.log'))
74 os.rmdir(tmp) 95 os.rmdir(tmp)
75 96
76 if '__main__' == __name__: 97 if '__main__' == __name__:
77 main(*sys.argv[1:]) 98 main(*sys.argv[1:])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698