def keep_file(gcov):
  """
      Some files should not be considered in coverage.
      Files to skip include system files (in /usr), the unit tests themselves
      (in tests/ directories) and the unit test infrastructure (in external_codes/)
  """
  source_file = gcov.tags['Source']

  path_elements = source_file.split('/')

  # Only looking at specific depths of directories. This might need
  # to be expanded, for example if unit test directories contain
  # subdirectories.
  try:
    if path_elements[-2] == 'tests':
      #print 'Unit test, skipping'
      return False
    if path_elements[-3] == 'external_codes':
      #print 'External code, skipping'
      return False
  except IndexError:
    pass

  if source_file.startswith('/usr/'):
    return False

  return True