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

Side by Side Diff: tools/auto_bisect/request_build.py

Issue 1001033004: Fix style in tools/auto_bisect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 9 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
« no previous file with comments | « tools/auto_bisect/query_crbug_test.py ('k') | tools/auto_bisect/source_control.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This module contains functionality for starting build try jobs via HTTP. 5 """This module contains functionality for starting build try jobs via HTTP.
6 6
7 This includes both sending a request to start a job, and also related code 7 This includes both sending a request to start a job, and also related code
8 for querying the status of the job. 8 for querying the status of the job.
9 9
10 This module can be either run as a stand-alone script to send a request to a 10 This module can be either run as a stand-alone script to send a request to a
11 builder, or imported and used by calling the public functions below. 11 builder, or imported and used by calling the public functions below.
12 """ 12 """
13 13
14 import getpass
15 import json 14 import json
16 import optparse
17 import os
18 import sys
19 import urllib
20 import urllib2 15 import urllib2
21 16
22 import fetch_build
23
24 # URL template for fetching JSON data about builds. 17 # URL template for fetching JSON data about builds.
25 BUILDER_JSON_URL = ('%(server_url)s/json/builders/%(bot_name)s/builds/' 18 BUILDER_JSON_URL = ('%(server_url)s/json/builders/%(bot_name)s/builds/'
26 '%(build_num)s?as_text=1&filter=0') 19 '%(build_num)s?as_text=1&filter=0')
27 20
28 # URL template for displaying build steps. 21 # URL template for displaying build steps.
29 BUILDER_HTML_URL = '%(server_url)s/builders/%(bot_name)s/builds/%(build_num)s' 22 BUILDER_HTML_URL = '%(server_url)s/builders/%(bot_name)s/builds/%(build_num)s'
30 23
31 # Status codes that can be returned by the GetBuildStatus method 24 # Status codes that can be returned by the GetBuildStatus method
32 # From buildbot.status.builder. 25 # From buildbot.status.builder.
33 # See: http://docs.buildbot.net/current/developer/results.html 26 # See: http://docs.buildbot.net/current/developer/results.html
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 # See: http://docs.buildbot.net/current/developer/results.html 95 # See: http://docs.buildbot.net/current/developer/results.html
103 # results[1]: List of items, contains text if step fails, otherwise empty. 96 # results[1]: List of items, contains text if step fails, otherwise empty.
104 if (item.get('name') == 'package_build' and 97 if (item.get('name') == 'package_build' and
105 item.get('isFinished') and 98 item.get('isFinished') and
106 item.get('results')[0] in OK): 99 item.get('results')[0] in OK):
107 return True 100 return True
108 return False 101 return False
109 102
110 103
111 def _FetchBuilderData(builder_url): 104 def _FetchBuilderData(builder_url):
112 """Fetches JSON data for the all the builds from the tryserver. 105 """Fetches JSON data for the all the builds from the try server.
113 106
114 Args: 107 Args:
115 builder_url: A tryserver URL to fetch builds information. 108 builder_url: A try server URL to fetch builds information.
116 109
117 Returns: 110 Returns:
118 A dictionary with information of all build on the tryserver. 111 A dictionary with information of all build on the try server.
119 """ 112 """
120 data = None 113 data = None
121 try: 114 try:
122 url = urllib2.urlopen(builder_url) 115 url = urllib2.urlopen(builder_url)
123 except urllib2.URLError as e: 116 except urllib2.URLError as e:
124 print ('urllib2.urlopen error %s, waterfall status page down.[%s]' % ( 117 print ('urllib2.urlopen error %s, waterfall status page down.[%s]' % (
125 builder_url, str(e))) 118 builder_url, str(e)))
126 return None 119 return None
127 if url is not None: 120 if url is not None:
128 try: 121 try:
129 data = url.read() 122 data = url.read()
130 except IOError as e: 123 except IOError as e:
131 print 'urllib2 file object read error %s, [%s].' % (builder_url, str(e)) 124 print 'urllib2 file object read error %s, [%s].' % (builder_url, str(e))
132 return data 125 return data
133 126
134 127
135 def _GetBuildData(buildbot_url): 128 def _GetBuildData(buildbot_url):
136 """Gets build information for the given build id from the tryserver. 129 """Gets build information for the given build id from the try server.
137 130
138 Args: 131 Args:
139 buildbot_url: A tryserver URL to fetch build information. 132 buildbot_url: A try server URL to fetch build information.
140 133
141 Returns: 134 Returns:
142 A dictionary with build information if build exists, otherwise None. 135 A dictionary with build information if build exists, otherwise None.
143 """ 136 """
144 builds_json = _FetchBuilderData(buildbot_url) 137 builds_json = _FetchBuilderData(buildbot_url)
145 if builds_json: 138 if builds_json:
146 return json.loads(builds_json) 139 return json.loads(builds_json)
147 return None 140 return None
148 141
149 142
150 def GetBuildStatus(build_num, bot_name, server_url): 143 def GetBuildStatus(build_num, bot_name, server_url):
151 """Gets build status from the buildbot status page for a given build number. 144 """Gets build status from the buildbot status page for a given build number.
152 145
153 Args: 146 Args:
154 build_num: A build number on tryserver to determine its status. 147 build_num: A build number on try server to determine its status.
155 bot_name: Name of the bot where the build information is scanned. 148 bot_name: Name of the bot where the build information is scanned.
156 server_url: URL of the buildbot. 149 server_url: URL of the buildbot.
157 150
158 Returns: 151 Returns:
159 A pair which consists of build status (SUCCESS, FAILED or PENDING) and a 152 A pair which consists of build status (SUCCESS, FAILED or PENDING) and a
160 link to build status page on the waterfall. 153 link to build status page on the waterfall.
161 """ 154 """
162 results_url = None 155 results_url = None
163 if build_num: 156 if build_num:
164 # Get the URL for requesting JSON data with status information. 157 # Get the URL for requesting JSON data with status information.
(...skipping 16 matching lines...) Expand all
181 elif _IsBuildSuccessful(build_data): 174 elif _IsBuildSuccessful(build_data):
182 return (OK, results_url) 175 return (OK, results_url)
183 return (PENDING, results_url) 176 return (PENDING, results_url)
184 177
185 178
186 def GetBuildNumFromBuilder(build_reason, bot_name, server_url): 179 def GetBuildNumFromBuilder(build_reason, bot_name, server_url):
187 """Gets build number on build status page for a given 'build reason'. 180 """Gets build number on build status page for a given 'build reason'.
188 181
189 This function parses the JSON data from buildbot page and collects basic 182 This function parses the JSON data from buildbot page and collects basic
190 information about the all the builds, and then uniquely identifies the build 183 information about the all the builds, and then uniquely identifies the build
191 based on the 'reason' attribute in builds's JSON data. 184 based on the 'reason' attribute in the JSON data about the build.
192 185
193 The 'reason' attribute set is when a build request is posted, and it is used 186 The 'reason' attribute set is when a build request is posted, and it is used
194 to identify the build on status page. 187 to identify the build on status page.
195 188
196 Args: 189 Args:
197 build_reason: A unique build name set to build on tryserver. 190 build_reason: A unique build name set to build on try server.
198 bot_name: Name of the bot where the build information is scanned. 191 bot_name: Name of the bot where the build information is scanned.
199 server_url: URL of the buildbot. 192 server_url: URL of the buildbot.
200 193
201 Returns: 194 Returns:
202 A build number as a string if found, otherwise None. 195 A build number as a string if found, otherwise None.
203 """ 196 """
204 buildbot_url = BUILDER_JSON_URL % { 197 buildbot_url = BUILDER_JSON_URL % {
205 'server_url': server_url, 198 'server_url': server_url,
206 'bot_name': bot_name, 199 'bot_name': bot_name,
207 'build_num': '_all', 200 'build_num': '_all',
208 } 201 }
209 builds_json = _FetchBuilderData(buildbot_url) 202 builds_json = _FetchBuilderData(buildbot_url)
210 if builds_json: 203 if builds_json:
211 builds_data = json.loads(builds_json) 204 builds_data = json.loads(builds_json)
212 for current_build in builds_data: 205 for current_build in builds_data:
213 if builds_data[current_build].get('reason') == build_reason: 206 if builds_data[current_build].get('reason') == build_reason:
214 return builds_data[current_build].get('number') 207 return builds_data[current_build].get('number')
215 return None 208 return None
OLDNEW
« no previous file with comments | « tools/auto_bisect/query_crbug_test.py ('k') | tools/auto_bisect/source_control.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698