Chromium Code Reviews| 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 if output.startswith('<'): | 293 if output.startswith('<'): |
| 294 # It's an error message. Return as no result. | 294 # It's an error message. Return as no result. |
| 295 break | 295 break |
| 296 data = json.loads(output) or {} | 296 data = json.loads(output) or {} |
| 297 if not data.get('results'): | 297 if not data.get('results'): |
| 298 break | 298 break |
| 299 for i in data['results']: | 299 for i in data['results']: |
| 300 yield i | 300 yield i |
| 301 cursor = '&cursor=%s' % data['cursor'] | 301 cursor = '&cursor=%s' % data['cursor'] |
| 302 | 302 |
| 303 def trigger_try_jobs( | |
| 304 self, issue, patchset, reason, clobber, revision, builders_and_tests): | |
| 305 """Requests new try jobs. | |
| 306 | |
| 307 |builders_and_tests| is a map of builders: [tests] to run. | |
| 308 | |
| 309 Returns the keys of the new TryJobResult entites. | |
| 310 """ | |
| 311 params = [ | |
| 312 ('reason', reason), | |
| 313 ('clobber', 'True' if clobber else 'False'), | |
| 314 ('revision', revision if revision else 'HEAD'), | |
| 315 ('builders', json.dumps(builders_and_tests)), | |
| 316 ('xsrf_token', self.xsrf_token()), | |
| 317 ] | |
| 318 return self.post('/%d/try/%d' % (issue, patchset), params) | |
| 319 | |
| 320 def get_pending_try_jobs(self): | |
|
Roger Tawa OOO till Jul 10th
2012/09/04 13:40:12
add docstring.
| |
| 321 limit = 100 | |
| 322 url = '/get_pending_try_patchsets?limit=%d' % limit | |
| 323 jobs = [] | |
| 324 cursor = None | |
|
Roger Tawa OOO till Jul 10th
2012/09/04 13:40:12
why not make |cursor| an argument to get_pending_t
| |
| 325 while True: | |
| 326 extra = ('&cursor=' + cursor) if cursor else '' | |
| 327 data = json.loads(self.get(url + extra)) | |
| 328 if not data['jobs']: | |
| 329 break | |
| 330 jobs.extend(data['jobs']) | |
| 331 cursor = data['cursor'] | |
| 332 return jobs | |
| 333 | |
| 303 def get(self, request_path, **kwargs): | 334 def get(self, request_path, **kwargs): |
| 304 kwargs.setdefault('payload', None) | 335 kwargs.setdefault('payload', None) |
| 305 return self._send(request_path, **kwargs) | 336 return self._send(request_path, **kwargs) |
| 306 | 337 |
| 307 def post(self, request_path, data, **kwargs): | 338 def post(self, request_path, data, **kwargs): |
| 308 ctype, body = upload.EncodeMultipartFormData(data, []) | 339 ctype, body = upload.EncodeMultipartFormData(data, []) |
| 309 return self._send(request_path, payload=body, content_type=ctype, **kwargs) | 340 return self._send(request_path, payload=body, content_type=ctype, **kwargs) |
| 310 | 341 |
| 311 def _send(self, request_path, **kwargs): | 342 def _send(self, request_path, **kwargs): |
| 312 """Sends a POST/GET to Rietveld. Returns the response body.""" | 343 """Sends a POST/GET to Rietveld. Returns the response body.""" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 342 if not 'Name or service not known' in e.reason: | 373 if not 'Name or service not known' in e.reason: |
| 343 # Usually internal GAE flakiness. | 374 # Usually internal GAE flakiness. |
| 344 raise | 375 raise |
| 345 # If reaching this line, loop again. Uses a small backoff. | 376 # If reaching this line, loop again. Uses a small backoff. |
| 346 time.sleep(1+maxtries*2) | 377 time.sleep(1+maxtries*2) |
| 347 finally: | 378 finally: |
| 348 upload.ErrorExit = old_error_exit | 379 upload.ErrorExit = old_error_exit |
| 349 | 380 |
| 350 # DEPRECATED. | 381 # DEPRECATED. |
| 351 Send = get | 382 Send = get |
| OLD | NEW |