OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 import atexit | 5 import atexit |
6 import cgi | 6 import cgi |
7 import ConfigParser | 7 import ConfigParser |
8 import json | 8 import json |
9 import os | 9 import os |
10 import Queue | 10 import Queue |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 JSON object if the string represents a JSON object, None otherwise. | 286 JSON object if the string represents a JSON object, None otherwise. |
287 """ | 287 """ |
288 try: | 288 try: |
289 data = json.loads(json_string) | 289 data = json.loads(json_string) |
290 except ValueError: | 290 except ValueError: |
291 data = None | 291 data = None |
292 | 292 |
293 return data | 293 return data |
294 | 294 |
295 | 295 |
296 def GetDataFromURL(url, retries=10, sleep_time=0.1, timeout=5): | 296 def GetDataFromURL(url): |
297 """Retrieves raw data from URL, tries 10 times. | 297 """Retrieves raw data from URL, tries 10 times. |
298 | 298 |
299 Args: | 299 Args: |
300 url: URL to get data from. | 300 url: URL to get data from. |
301 retries: Number of times to retry connection. | 301 retries: Number of times to retry connection. |
302 sleep_time: Time in seconds to wait before retrying connection. | |
303 timeout: Time in seconds to wait before time out. | |
304 | 302 |
305 Returns: | 303 Returns: |
306 None if the data retrieval fails, or the raw data. | 304 None if the data retrieval fails, or the raw data. |
307 """ | 305 """ |
308 count = 0 | 306 status_code, data = utils.GetHttpClient().Get(url, retries=10) |
309 while True: | 307 if status_code == 200: |
310 count += 1 | 308 return data |
311 # Retrieves data from URL. | 309 else: |
312 try: | 310 # Return None if it fails to read data. |
313 status_code, data = utils.GetHttpClient().Get(url, timeout=timeout) | 311 return None |
314 except IOError as e: | |
315 status_code = -1 | |
316 data = None | |
317 | |
318 if status_code == 200: | |
319 return data | |
320 | |
321 if count < retries: | |
322 # If retrieval fails, try after sleep_time second. | |
323 time.sleep(sleep_time) | |
324 else: | |
325 break | |
326 | |
327 # Return None if it fails to read data from URL 'retries' times. | |
328 return None | |
329 | 312 |
330 | 313 |
331 def FindMinLineDistance(crashed_line_list, changed_line_numbers, | 314 def FindMinLineDistance(crashed_line_list, changed_line_numbers, |
332 line_range=3): | 315 line_range=3): |
333 """Calculates how far the changed line is from one of the crashes. | 316 """Calculates how far the changed line is from one of the crashes. |
334 | 317 |
335 Finds the minimum distance between the lines that the file crashed on | 318 Finds the minimum distance between the lines that the file crashed on |
336 and the lines that the file changed. For example, if the file crashed on | 319 and the lines that the file changed. For example, if the file crashed on |
337 line 200 and the CL changes line 203,204 and 205, the function returns 3. | 320 line 200 and the CL changes line 203,204 and 205, the function returns 3. |
338 | 321 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 review_url = None | 565 review_url = None |
583 reviewers = None | 566 reviewers = None |
584 line_content = blame.line_content | 567 line_content = blame.line_content |
585 message = blame.message | 568 message = blame.message |
586 | 569 |
587 result = Result(suspected_cl, revision_url, component_name, author, reason, | 570 result = Result(suspected_cl, revision_url, component_name, author, reason, |
588 review_url, reviewers, line_content, message) | 571 review_url, reviewers, line_content, message) |
589 result_list.append(result) | 572 result_list.append(result) |
590 | 573 |
591 return result_list | 574 return result_list |
OLD | NEW |