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

Side by Side Diff: tools/findit/crash_utils.py

Issue 504443004: [Findit] Improve output format and cherry-pick bugs fix. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit. Created 6 years, 3 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/findit/common/utils.py ('k') | tools/findit/deps_config.json » ('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 (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 cgi 5 import cgi
6 import ConfigParser 6 import ConfigParser
7 import json 7 import json
8 import os 8 import os
9 import time 9 import time
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 path: A string representing a path. 101 path: A string representing a path.
102 parsed_deps: A map from component path to its component name, repository, 102 parsed_deps: A map from component path to its component name, repository,
103 etc. 103 etc.
104 104
105 Returns: 105 Returns:
106 A tuple containing a component this path is in (e.g blink, skia, etc) 106 A tuple containing a component this path is in (e.g blink, skia, etc)
107 and a path in that component's repository. Returns None if the component 107 and a path in that component's repository. Returns None if the component
108 repository is not supported, i.e from googlecode. 108 repository is not supported, i.e from googlecode.
109 """ 109 """
110 # First normalize the path by retreiving the normalized path. 110 # First normalize the path by retreiving the normalized path.
111 normalized_path = os.path.normpath(path.replace('\\', '/')) 111 normalized_path = os.path.normpath(path).replace('\\', '/')
112 112
113 # Iterate through all component paths in the parsed DEPS, in the decreasing 113 # Iterate through all component paths in the parsed DEPS, in the decreasing
114 # order of the length of the file path. 114 # order of the length of the file path.
115 for component_path in sorted(parsed_deps, 115 for component_path in sorted(parsed_deps,
116 key=(lambda path: -len(path))): 116 key=(lambda path: -len(path))):
117 # new_component_path is the component path with 'src/' removed. 117 # new_component_path is the component path with 'src/' removed.
118 new_component_path = component_path 118 new_component_path = component_path
119 if new_component_path.startswith('src/') and new_component_path != 'src/': 119 if new_component_path.startswith('src/') and new_component_path != 'src/':
120 new_component_path = new_component_path[len('src/'):] 120 new_component_path = new_component_path[len('src/'):]
121 121
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 timeout: Time in seconds to wait before time out. 223 timeout: Time in seconds to wait before time out.
224 224
225 Returns: 225 Returns:
226 None if the data retrieval fails, or the raw data. 226 None if the data retrieval fails, or the raw data.
227 """ 227 """
228 count = 0 228 count = 0
229 while True: 229 while True:
230 count += 1 230 count += 1
231 # Retrieves data from URL. 231 # Retrieves data from URL.
232 try: 232 try:
233 _, data = utils.GetHttpClient().Get(url, timeout=timeout) 233 status_code, data = utils.GetHttpClient().Get(url, timeout=timeout)
234 except IOError:
235 status_code = -1
236 data = None
237
238 if status_code == 200:
234 return data 239 return data
235 except IOError: 240
236 if count < retries: 241 if count < retries:
237 # If retrieval fails, try after sleep_time second. 242 # If retrieval fails, try after sleep_time second.
238 time.sleep(sleep_time) 243 time.sleep(sleep_time)
239 else: 244 else:
240 break 245 break
241 246
242 # Return None if it fails to read data from URL 'retries' times. 247 # Return None if it fails to read data from URL 'retries' times.
243 return None 248 return None
244 249
245 250
246 def FindMinLineDistance(crashed_line_list, changed_line_numbers, 251 def FindMinLineDistance(crashed_line_list, changed_line_numbers,
247 line_range=3): 252 line_range=3):
248 """Calculates how far the changed line is from one of the crashes. 253 """Calculates how far the changed line is from one of the crashes.
249 254
250 Finds the minimum distance between the lines that the file crashed on 255 Finds the minimum distance between the lines that the file crashed on
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 link: A link to add to the string. 347 link: A link to add to the string.
343 348
344 Returns: 349 Returns:
345 A string with hyperlink added. 350 A string with hyperlink added.
346 """ 351 """
347 sanitized_link = cgi.escape(link, quote=True) 352 sanitized_link = cgi.escape(link, quote=True)
348 sanitized_text = cgi.escape(str(text)) 353 sanitized_text = cgi.escape(str(text))
349 return '<a href="%s">%s</a>' % (sanitized_link, sanitized_text) 354 return '<a href="%s">%s</a>' % (sanitized_link, sanitized_text)
350 355
351 356
352 def PrettifyList(l): 357 def PrettifyList(items):
353 """Returns a string representation of a list. 358 """Returns a string representation of a list.
354 359
355 It adds comma in between the elements and removes the brackets. 360 It adds comma in between the elements and removes the brackets.
356 Args: 361 Args:
357 l: A list to prettify. 362 items: A list to prettify.
358 Returns: 363 Returns:
359 A string representation of the list. 364 A string representation of the list.
360 """ 365 """
361 return str(l)[1:-1] 366 return ', '.join(map(str, items))
367
368
369 def PrettifyFrameInfo(frame_indices, functions):
370 """Return a string to represent the frames with functions."""
371 frames = []
372 for frame_index, function in zip(frame_indices, functions):
373 frames.append('frame #%s, function "%s"' % (frame_index, function))
374 return '; '.join(frames)
362 375
363 376
364 def PrettifyFiles(file_list): 377 def PrettifyFiles(file_list):
365 """Returns a string representation of a list of file names. 378 """Returns a string representation of a list of file names.
366 379
367 Args: 380 Args:
368 file_list: A list of tuple, (file_name, file_url). 381 file_list: A list of tuple, (file_name, file_url).
369 Returns: 382 Returns:
370 A string representation of file names with their urls. 383 A string representation of file names with their urls.
371 """ 384 """
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 review_url = None 502 review_url = None
490 reviewers = None 503 reviewers = None
491 line_content = blame.line_content 504 line_content = blame.line_content
492 message = blame.message 505 message = blame.message
493 506
494 result = Result(suspected_cl, revision_url, component_name, author, reason, 507 result = Result(suspected_cl, revision_url, component_name, author, reason,
495 review_url, reviewers, line_content, message) 508 review_url, reviewers, line_content, message)
496 result_list.append(result) 509 result_list.append(result)
497 510
498 return result_list 511 return result_list
OLDNEW
« no previous file with comments | « tools/findit/common/utils.py ('k') | tools/findit/deps_config.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698