OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Defines class Rietveld to easily access a rietveld instance. | 5 """Defines class Rietveld to easily access a rietveld instance. |
6 | 6 |
7 Security implications: | 7 Security implications: |
8 | 8 |
9 The following hypothesis are made: | 9 The following hypothesis are made: |
10 - Rietveld enforces: | 10 - Rietveld enforces: |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 if output.startswith('<'): | 296 if output.startswith('<'): |
297 # It's an error message. Return as no result. | 297 # It's an error message. Return as no result. |
298 break | 298 break |
299 data = json.loads(output) or {} | 299 data = json.loads(output) or {} |
300 if not data.get('results'): | 300 if not data.get('results'): |
301 break | 301 break |
302 for i in data['results']: | 302 for i in data['results']: |
303 yield i | 303 yield i |
304 cursor = '&cursor=%s' % data['cursor'] | 304 cursor = '&cursor=%s' % data['cursor'] |
305 | 305 |
| 306 def trigger_try_jobs( |
| 307 self, issue, patchset, reason, clobber, revision, builders_and_tests): |
| 308 """Requests new try jobs. |
| 309 |
| 310 |builders_and_tests| is a map of builders: [tests] to run. |
| 311 |
| 312 Returns the keys of the new TryJobResult entites. |
| 313 """ |
| 314 params = [ |
| 315 ('reason', reason), |
| 316 ('clobber', 'True' if clobber else 'False'), |
| 317 ('revision', revision if revision else 'HEAD'), |
| 318 ('builders', json.dumps(builders_and_tests)), |
| 319 ('xsrf_token', self.xsrf_token()), |
| 320 ] |
| 321 return self.post('/%d/try/%d' % (issue, patchset), params) |
| 322 |
| 323 def get_pending_try_jobs(self, cursor=None, limit=100): |
| 324 """Retrieves the try job requests in pending state. |
| 325 |
| 326 Returns a tuple of the list of try jobs and the cursor for the next request. |
| 327 """ |
| 328 url = '/get_pending_try_patchsets?limit=%d' % limit |
| 329 extra = ('&cursor=' + cursor) if cursor else '' |
| 330 data = json.loads(self.get(url + extra)) |
| 331 return data['jobs'], data['cursor'] |
| 332 |
306 def get(self, request_path, **kwargs): | 333 def get(self, request_path, **kwargs): |
307 kwargs.setdefault('payload', None) | 334 kwargs.setdefault('payload', None) |
308 return self._send(request_path, **kwargs) | 335 return self._send(request_path, **kwargs) |
309 | 336 |
310 def post(self, request_path, data, **kwargs): | 337 def post(self, request_path, data, **kwargs): |
311 ctype, body = upload.EncodeMultipartFormData(data, []) | 338 ctype, body = upload.EncodeMultipartFormData(data, []) |
312 return self._send(request_path, payload=body, content_type=ctype, **kwargs) | 339 return self._send(request_path, payload=body, content_type=ctype, **kwargs) |
313 | 340 |
314 def _send(self, request_path, **kwargs): | 341 def _send(self, request_path, **kwargs): |
315 """Sends a POST/GET to Rietveld. Returns the response body.""" | 342 """Sends a POST/GET to Rietveld. Returns the response body.""" |
(...skipping 29 matching lines...) Expand all Loading... |
345 if not 'Name or service not known' in e.reason: | 372 if not 'Name or service not known' in e.reason: |
346 # Usually internal GAE flakiness. | 373 # Usually internal GAE flakiness. |
347 raise | 374 raise |
348 # If reaching this line, loop again. Uses a small backoff. | 375 # If reaching this line, loop again. Uses a small backoff. |
349 time.sleep(1+maxtries*2) | 376 time.sleep(1+maxtries*2) |
350 finally: | 377 finally: |
351 upload.ErrorExit = old_error_exit | 378 upload.ErrorExit = old_error_exit |
352 | 379 |
353 # DEPRECATED. | 380 # DEPRECATED. |
354 Send = get | 381 Send = get |
OLD | NEW |