tools/metrics/histograms/expand_owners.py
def _ExtractEmailAddressesFromOWNERS(path, depth=0):
  """Returns a list of email addresses in the given file.

  Args:
    path: The path to an OWNERS file.
    depth: The depth of the recursion, which is used to fail fast in the rare
      case that the OWNERS file path results in a loop.

  Raises:
    Error: Raised in two situations. First, raised if (A) the OWNERS file with
      the given path has a file directive and (B) the OWNERS file indicated by
      the directive does not exist. Second, raised if the depth reaches a
      certain limit.
  """
  # It is unlikely that any chain of OWNERS files will exceed 10 redirections
  # via file:// directives.
  limit = 10
  if (depth > limit):
    raise Error('_ExtractEmailAddressesFromOWNERS has been called {} times. The'
                ' path {} may be part of an OWNERS loop.'.format(limit, path))

  directive = 'file://'
  email_pattern = re.compile(_EMAIL_PATTERN)
  extracted_emails = []

  with open(path, 'r') as owners_file:
    for line in [line.lstrip()
                 for line in owners_file.read().splitlines() if line]:
      index = line.find(' ')
      first_word = line[:index] if index != -1 else line

      if email_pattern.match(first_word):
        extracted_emails.append(first_word)

      elif first_word.startswith(directive):
        next_path = _GetOwnersFilePath(
            os.path.join(SRC, first_word[len(directive):]))

        if os.path.exists(next_path) and os.path.isfile(next_path):
          extracted_emails.extend(
              _ExtractEmailAddressesFromOWNERS(next_path, depth + 1))
        else:
          raise Error('The path derived from {} does not exist. '
                      'Derived path: {}'.format(first_word, next_path))

  return extracted_emails
Returns a list of email addresses in the given file.

  Args:
    path: The path to an OWNERS file.
    depth: The depth of the recursion, which is used to fail fast in the rare
      case that the OWNERS file path results in a loop.

  Raises:
    Error: Raised in two situations. First, raised if (A) the OWNERS file with
      the given path has a file directive and (B) the OWNERS file indicated by
      the directive does not exist. Second, raised if the depth reaches a
      certain limit.
  
Returns a list of email addresses in the given file.
Returns a list of email addresses in the given file .
def _ExtractEmailAddressesFromOWNERS(path, depth=0):
  limit = 10
  if (depth > limit):
    raise Error('_ExtractEmailAddressesFromOWNERS has been called {} times. The'
                ' path {} may be part of an OWNERS loop.'.format(limit, path))
  directive = 'file://'
  email_pattern = re.compile(_EMAIL_PATTERN)
  extracted_emails = []
  with open(path, 'r') as owners_file:
    for line in [line.lstrip()
                 for line in owners_file.read().splitlines() if line]:
      index = line.find(' ')
      first_word = line[:index] if index != -1 else line
      if email_pattern.match(first_word):
        extracted_emails.append(first_word)
      elif first_word.startswith(directive):
        next_path = _GetOwnersFilePath(
            os.path.join(SRC, first_word[len(directive):]))
        if os.path.exists(next_path) and os.path.isfile(next_path):
          extracted_emails.extend(
              _ExtractEmailAddressesFromOWNERS(next_path, depth + 1))
        else:
          raise Error('The path derived from {} does not exist. '
                      'Derived path: {}'.format(first_word, next_path))
  return extracted_emails
def _ExtractEmailAddressesFromOWNERS ( path , depth = 0 ) : limit = 10 if ( depth > limit ) : raise Error ( '_ExtractEmailAddressesFromOWNERS has been called {} times. The' ' path {} may be part of an OWNERS loop.' . format ( limit , path ) ) directive = 'file://' email_pattern = re . compile ( _EMAIL_PATTERN ) extracted_emails = [ ] with open ( path , 'r' ) as owners_file : for line in [ line . lstrip ( ) for line in owners_file . read ( ) . splitlines ( ) if line ] : index = line . find ( ' ' ) first_word = line [ : index ] if index != - 1 else line if email_pattern . match ( first_word ) : extracted_emails . append ( first_word ) elif first_word . startswith ( directive ) : next_path = _GetOwnersFilePath ( os . path . join ( SRC , first_word [ len ( directive ) : ] ) ) if os . path . exists ( next_path ) and os . path . isfile ( next_path ) : extracted_emails . extend ( _ExtractEmailAddressesFromOWNERS ( next_path , depth + 1 ) ) else : raise Error ( 'The path derived from {} does not exist. ' 'Derived path: {}' . format ( first_word , next_path ) ) return extracted_emails
Returns a list of email addresses in the given file.
Returns a list of email addresses in the given file .
"""Returns a list of email addresses in the given file.

  Args:
    path: The path to an OWNERS file.
    depth: The depth of the recursion, which is used to fail fast in the rare
      case that the OWNERS file path results in a loop.

  Raises:
    Error: Raised in two situations. First, raised if (A) the OWNERS file with
      the given path has a file directive and (B) the OWNERS file indicated by
      the directive does not exist. Second, raised if the depth reaches a
      certain limit.
  """ # It is unlikely that any chain of OWNERS files will exceed 10 redirections # via file:// directives.
Raised in two situations. First, raised if (A) the OWNERS file with
the given path has a file directive and (B) the OWNERS file indicated by
the directive does not exist. Second, raised if the depth reaches a
certain limit.
Raised in two situations . First raised if ( A ) the OWNERS file with the given path has a file directive and ( B ) the OWNERS file indicated by the directive does not exist . Second raised if the depth reaches a certain limit .
Error
path
The path to an OWNERS file.
The path to an OWNERS file .
depth
The depth of the recursion, which is used to fail fast in the rare
case that the OWNERS file path results in a loop.
The depth of the recursion which is used to fail fast in the rare case that the OWNERS file path results in a loop .