| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from google.appengine.api import urlfetch | 8 from google.appengine.api import urlfetch |
| 9 from google.appengine.runtime import apiproxy_errors | 9 from google.appengine.runtime import apiproxy_errors |
| 10 | 10 |
| 11 from base import constants | 11 from base import constants |
| 12 | 12 |
| 13 | 13 |
| 14 def BuildUrl(master_name, url): | 14 def BuildUrl(master_name, url, use_cbe=False): |
| 15 return '%s/%s/%s' % (constants.BUILDBOT_BASE_URL, master_name, url) | 15 base = constants.BUILDBOT_BASE_URL |
| 16 if use_cbe: |
| 17 base = constants.CBE_BASE_URL + '/p' |
| 18 url += '?json=1' |
| 19 |
| 20 return '%s/%s/%s' % (base, master_name, url) |
| 16 | 21 |
| 17 | 22 |
| 18 def FetchData(url): | 23 def FetchData(url): |
| 19 try: | 24 try: |
| 20 return json.loads(FetchText(url)) | 25 return json.loads(FetchText(url)) |
| 21 except ValueError: | 26 except ValueError: |
| 22 logging.warning('Data is corrupt: %s', url) | 27 logging.warning('Data is corrupt: %s', url) |
| 23 raise | 28 raise |
| 24 | 29 |
| 25 | 30 |
| 26 def FetchText(url): | 31 def FetchText(url): |
| 27 logging.debug('Retrieving %s', url) | 32 logging.debug('Retrieving %s', url) |
| 28 try: | 33 try: |
| 29 return urlfetch.fetch(url).content | 34 return urlfetch.fetch(url).content |
| 30 except (apiproxy_errors.DeadlineExceededError, urlfetch.DownloadError, | 35 except (apiproxy_errors.DeadlineExceededError, urlfetch.DownloadError, |
| 31 urlfetch.InternalTransientError): | 36 urlfetch.InternalTransientError): |
| 32 # Could be intermittent; try again. | 37 # Could be intermittent; try again. |
| 33 try: | 38 try: |
| 34 return urlfetch.fetch(url).content | 39 return urlfetch.fetch(url).content |
| 35 except: | 40 except: |
| 36 logging.error('Error retrieving URL: %s', url) | 41 logging.error('Error retrieving URL: %s', url) |
| 37 raise | 42 raise |
| 38 except: | 43 except: |
| 39 logging.error('Error retrieving URL: %s', url) | 44 logging.error('Error retrieving URL: %s', url) |
| 40 raise | 45 raise |
| OLD | NEW |