<commit_before>#!/usr/bin/python

import sys
import os
import re
import commands
from optparse import OptionParser

FILE_MATCHER = re.compile('File \'(.*)\'')
EXECUTED_MATCHER = re.compile('Lines executed:([0-9.]+)% of ([0-9]+)')

def FindObjectFiles(directory):
  results = []
  for root, dirs, files in os.walk(directory):
    for file in files:
      (name, ext) = os.path.splitext(file)
      if ext == '.o':
        results.append(os.path.join(root, file))
  return results

def ParseGcovOutput(output, srcRoot, exceptDirectory):
  results = []
  item = {}

  lines = output.splitlines()
  for line in lines:
    if line == '':
      if 'file' in item:
        results.append(item)
      item = {}
      continue

    m = FILE_MATCHER.match(line)
    if m != None:
      path = m.group(1)
      fullpath = os.path.realpath(path)
      relpath = os.path.relpath(path, srcRoot)
      if (fullpath.startswith(os.path.realpath(srcRoot)) and
          (exceptDirectory == None or
           not relpath.startswith(exceptDirectory))):
        item['file'] = relpath
        item['gcov'] = os.path.realpath(os.path.basename(path) + '.gcov')
      continue

    m = EXECUTED_MATCHER.match(line)
    if m != None:
      item['executed'] = float(m.group(1))
      item['executable'] = int(m.group(2))
      continue

  return results

def PrintResult(results):
  maxSrcLength = 0
  for result in results:
    maxSrcLength = max(maxSrcLength, len(result['file']))

  print '    %    executable source'
  print 'executed      lines file'
  fmt = '  %6.2f      %5d %-' + str(maxSrcLength) + 's %s'
  for result in results:
    print fmt % (
        result.get('executed', 0.0), result.get('executable', 0),
        result.get('file', ''), result.get('gcov', ''))

def GetExecuted(item):
  return item.get('executed', 0.0)<commit_msg>exclude the source file had no executable lines from coverage reports<commit_after>#!/usr/bin/python

import sys
import os
import re
import commands
from optparse import OptionParser

FILE_MATCHER = re.compile('File \'(.*)\'')
EXECUTED_MATCHER = re.compile('Lines executed:([0-9.]+)% of ([0-9]+)')

def FindObjectFiles(directory):
  results = []
  for root, dirs, files in os.walk(directory):
    for file in files:
      (name, ext) = os.path.splitext(file)
      if ext == '.o':
        results.append(os.path.join(root, file))
  return results

def ParseGcovOutput(output, srcRoot, exceptDirectory):
  results = []
  item = {}

  lines = output.splitlines()
  for line in lines:
    if line == '':
      if 'file' in item:
        results.append(item)
      item = {}
      continue

    m = FILE_MATCHER.match(line)
    if m != None:
      path = m.group(1)
      fullpath = os.path.realpath(path)
      relpath = os.path.relpath(path, srcRoot)
      if (fullpath.startswith(os.path.realpath(srcRoot)) and
          (exceptDirectory == None or
           not relpath.startswith(exceptDirectory))):
        item['file'] = relpath
        item['gcov'] = os.path.realpath(os.path.basename(path) + '.gcov')
      continue

    m = EXECUTED_MATCHER.match(line)
    if m != None:
      item['executed'] = float(m.group(1))
      item['executable'] = int(m.group(2))
      continue

  return results

def PrintResult(results):
  maxSrcLength = 0
  for result in results:
    maxSrcLength = max(maxSrcLength, len(result['file']))

  print '    %    executable source'
  print 'executed      lines file'
  fmt = '  %6.2f      %5d %-' + str(maxSrcLength) + 's %s'
  for result in results:
    if result.get('executable', 0) != 0:
      print fmt % (
          result.get('executed', 0.0), result.get('executable', 0),
          result.get('file', ''), result.get('gcov', ''))

def GetExecuted(item):
  return item.get('executed', 0.0)
{'fraction_non_alphanumeric': 0.15001332267519318, 'fraction_numerical': 0.009059419131361577, 'mean_word_length': 2.8982346832814123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6166070', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1256, 'n_words': 299}