OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 re | 5 import re |
6 import sys | 6 import sys |
7 | 7 |
8 from http_client_local import HttpClientLocal | 8 from http_client_local import HttpClientLocal |
9 | 9 |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 return platform_name | 22 return platform_name |
23 | 23 |
24 | 24 |
25 def IsGitHash(revision): | 25 def IsGitHash(revision): |
26 return GIT_HASH_PATTERN.match(str(revision)) | 26 return GIT_HASH_PATTERN.match(str(revision)) |
27 | 27 |
28 | 28 |
29 def GetHttpClient(): | 29 def GetHttpClient(): |
30 # TODO(stgao): return implementation for appengine when running on appengine. | 30 # TODO(stgao): return implementation for appengine when running on appengine. |
31 return HttpClientLocal | 31 return HttpClientLocal |
| 32 |
| 33 |
| 34 def JoinLineNumbers(line_numbers, accepted_gap=1): |
| 35 """Join line numbers into line blocks. |
| 36 |
| 37 Args: |
| 38 line_numbers: a list of line number. |
| 39 accepted_gap: if two line numbers are within the give gap, |
| 40 they would be combined together into a block. |
| 41 Eg: for (1, 2, 3, 6, 7, 8, 12), if |accepted_gap| = 1, result |
| 42 would be 1-3, 6-8, 12; if |accepted_gap| = 3, result would be |
| 43 1-8, 12; if |accepted_gap| =4, result would be 1-12. |
| 44 """ |
| 45 if not line_numbers: |
| 46 return '' |
| 47 |
| 48 line_numbers = map(int, line_numbers) |
| 49 line_numbers.sort() |
| 50 |
| 51 block = [] |
| 52 start_line_number = line_numbers[0] |
| 53 last_line_number = start_line_number |
| 54 for current_line_number in line_numbers[1:]: |
| 55 if last_line_number + accepted_gap < current_line_number: |
| 56 if start_line_number == last_line_number: |
| 57 block.append('%d' % start_line_number) |
| 58 else: |
| 59 block.append('%d-%d' % (start_line_number, last_line_number)) |
| 60 start_line_number = current_line_number |
| 61 last_line_number = current_line_number |
| 62 else: |
| 63 if start_line_number == last_line_number: |
| 64 block.append('%d' % start_line_number) |
| 65 else: |
| 66 block.append('%d-%d' % (start_line_number, last_line_number)) |
| 67 |
| 68 return ', '.join(block) |
OLD | NEW |