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): | |
aarya
2014/08/26 02:13:53
Please don't use accepted_gap. When someone modifi
stgao
2014/08/26 18:35:24
I think I didn't make it clear for the meaning of
| |
35 """Join line numbers into line blocks.""" | |
36 if not line_numbers: | |
37 return '' | |
38 | |
39 line_numbers = map(int, line_numbers) | |
40 line_numbers.sort() | |
41 | |
42 block = [] | |
43 start_line_number = line_numbers[0] | |
44 last_line_number = start_line_number | |
45 for current_line_number in line_numbers[1:]: | |
46 if last_line_number + accepted_gap < current_line_number: | |
47 if start_line_number == last_line_number: | |
48 block.append('%d' % start_line_number) | |
49 else: | |
50 block.append('%d-%d' % (start_line_number, last_line_number)) | |
51 start_line_number = current_line_number | |
52 last_line_number = current_line_number | |
53 else: | |
54 if start_line_number == last_line_number: | |
55 block.append('%d' % start_line_number) | |
56 else: | |
57 block.append('%d-%d' % (start_line_number, last_line_number)) | |
58 | |
59 return ', '.join(block) | |
OLD | NEW |