|
3 | 3 | # Copyright 2015 (c) Lei Xu <eddyxu@gmail.com> |
4 | 4 |
|
5 | 5 | from __future__ import absolute_import |
| 6 | +from builtins import str |
6 | 7 |
|
7 | 8 | import argparse |
8 | 9 | import hashlib |
@@ -292,21 +293,17 @@ def parse_lcov_file_info(args, filepath, line_iter, line_coverage_re, file_end_s |
292 | 293 | """ |
293 | 294 | coverage = [] |
294 | 295 | lines_covered = [] |
295 | | - while True: |
296 | | - try: |
297 | | - line = line_iter.next() |
298 | | - if line != "end_of_record": |
299 | | - line_coverage_match = line_coverage_re.match(line) |
300 | | - if line_coverage_match: |
301 | | - line_no = line_coverage_match.group(1) |
302 | | - cov_count = int(line_coverage_match.group(2)) |
303 | | - if args.max_cov_count: |
304 | | - if cov_count > args.max_cov_count: |
305 | | - cov_count = args.max_cov_count + 1 |
306 | | - lines_covered.append((line_no, cov_count)) |
307 | | - else: |
308 | | - break |
309 | | - except StopIteration: |
| 296 | + for line in line_iter: |
| 297 | + if line != "end_of_record": |
| 298 | + line_coverage_match = line_coverage_re.match(line) |
| 299 | + if line_coverage_match: |
| 300 | + line_no = line_coverage_match.group(1) |
| 301 | + cov_count = int(line_coverage_match.group(2)) |
| 302 | + if args.max_cov_count: |
| 303 | + if cov_count > args.max_cov_count: |
| 304 | + cov_count = args.max_cov_count + 1 |
| 305 | + lines_covered.append((line_no, cov_count)) |
| 306 | + else: |
310 | 307 | break |
311 | 308 |
|
312 | 309 | num_code_lines = len([line.rstrip('\n') for line in open(filepath, 'r')]) |
@@ -394,27 +391,23 @@ def collect(args): |
394 | 391 | line_iter = iter(info_lines) |
395 | 392 | new_file_re = re.compile('SF:(.*)') |
396 | 393 | line_coverage_re = re.compile('DA:(\d+),(\d+)'); |
397 | | - while True: |
398 | | - try: |
399 | | - line = line_iter.next() |
400 | | - new_file_match = new_file_re.match(line) |
401 | | - if new_file_match: |
402 | | - src_report = {} |
403 | | - filepath = new_file_match.group(1) |
404 | | - if args.build_root: |
405 | | - filepath = os.path.relpath(filepath, args.build_root) |
406 | | - abs_filepath = os.path.join(abs_root, filepath) |
407 | | - src_report['name'] = unicode(posix_path(filepath)) |
408 | | - with io.open(abs_filepath, mode='rb') as src_file: |
409 | | - src_report['source_digest'] = hashlib.md5(src_file.read()).hexdigest() |
410 | | - src_report['coverage'] = parse_lcov_file_info(args, abs_filepath, line_iter, line_coverage_re, "end_of_record") |
411 | | - src_files[filepath] = src_report |
412 | | - elif line != "TN:": |
413 | | - print('Invalid info file') |
414 | | - print('line: ' + line) |
415 | | - sys.exit(0) |
416 | | - except StopIteration: |
417 | | - break |
| 394 | + for line in line_iter: |
| 395 | + new_file_match = new_file_re.match(line) |
| 396 | + if new_file_match: |
| 397 | + src_report = {} |
| 398 | + filepath = new_file_match.group(1) |
| 399 | + if args.root: |
| 400 | + filepath = os.path.relpath(filepath, args.root) |
| 401 | + abs_filepath = os.path.join(abs_root, filepath) |
| 402 | + src_report['name'] = str(posix_path(filepath)) |
| 403 | + with io.open(abs_filepath, mode='rb') as src_file: |
| 404 | + src_report['source_digest'] = hashlib.md5(src_file.read()).hexdigest() |
| 405 | + src_report['coverage'] = parse_lcov_file_info(args, abs_filepath, line_iter, line_coverage_re, "end_of_record") |
| 406 | + src_files[filepath] = src_report |
| 407 | + elif line != "TN:": |
| 408 | + print('Invalid info file') |
| 409 | + print('line: ' + line) |
| 410 | + sys.exit(0) |
418 | 411 | else: |
419 | 412 | for root, dirs, files in os.walk(args.root, followlinks=args.follow_symlinks): |
420 | 413 | dirs[:] = filter_dirs(root, dirs, excl_paths) |
|
0 commit comments