tools/metrics/histograms/expand_owners.py
def ExpandHistogramsOWNERS(histograms):
  """Updates the given DOM Element's descendants, if necessary.

  When a histogram has an owner node whose text is an OWNERS file path rather
  than an email address, e.g. <owner>src/base/android/OWNERS</owner> instead of
  <owner>joy@chromium.org</owner>, then (A) the histogram's owners need to be
  updated and (B) a component may be added.

  If the text of an owner node is an OWNERS file path, then this node is
  replaced by owner nodes for the emails derived from the OWNERS file. If a
  component, e.g. UI>GFX, can be derived from the OWNERS file or an OWNERS file
  in a higher-level directory, then a component tag will be added to the
  histogram, e.g. <component>UI&gt;GFX</component>.

  Args:
    histograms: The DOM Element whose descendants may be updated.

  Raises:
    Error: Raised if the OWNERS file with the given path does not exist.
  """
  email_pattern = re.compile(_EMAIL_PATTERN)
  iter_matches = extract_histograms.IterElementsWithTag

  for histogram in iter_matches(histograms, 'histogram'):
    owners = [owner for owner in iter_matches(histogram, 'owner', 1)]

    # owner is a DOM Element with a single child, which is a DOM Text Node.
    emails_with_dom_elements = set([
        owner.childNodes[0].data
        for owner in owners
        if email_pattern.match(owner.childNodes[0].data)])

    # component is a DOM Element with a single child, which is a DOM Text Node.
    components_with_dom_elements = set([
      extract_histograms.NormalizeString(component.childNodes[0].data)
      for component in iter_matches(histogram, 'component', 1)])

    for index, owner in enumerate(owners):
      owner_text = owner.childNodes[0].data.strip()
      name = histogram.getAttribute('name')
      obsolete_tags = [tag for tag in iter_matches(histogram, 'obsolete', 1)]
      is_obsolete = len(obsolete_tags) > 0
      if _IsEmailOrPlaceholder(index == 0, owner_text, name, is_obsolete):
        continue

      path = _GetOwnersFilePath(owner_text)
      if not os.path.exists(path) or not os.path.isfile(path):
        raise Error('The file at {} does not exist.'.format(path))

      owners_to_add = _MakeOwners(
        owner.ownerDocument, path, emails_with_dom_elements)
      if not owners_to_add:
        continue

      _UpdateHistogramOwners(histogram, owner, owners_to_add)

      component = _ExtractComponentViaDirmd(os.path.dirname(path))
      if component and component not in components_with_dom_elements:
        components_with_dom_elements.add(component)
        _AddHistogramComponent(histogram, component)
Updates the given DOM Element's descendants, if necessary.

  When a histogram has an owner node whose text is an OWNERS file path rather
  than an email address, e.g. <owner>src/base/android/OWNERS</owner> instead of
  <owner>joy@chromium.org</owner>, then (A) the histogram's owners need to be
  updated and (B) a component may be added.

  If the text of an owner node is an OWNERS file path, then this node is
  replaced by owner nodes for the emails derived from the OWNERS file. If a
  component, e.g. UI>GFX, can be derived from the OWNERS file or an OWNERS file
  in a higher-level directory, then a component tag will be added to the
  histogram, e.g. <component>UI&gt;GFX</component>.

  Args:
    histograms: The DOM Element whose descendants may be updated.

  Raises:
    Error: Raised if the OWNERS file with the given path does not exist.
  
Updates the given DOM Element's descendants, if necessary.
When a histogram has an owner node whose text is an OWNERS file path rather
than an email address, e.g. src/base/android/OWNERS instead of
joy@chromium.org, then (A) the histogram's owners need to be
updated and (B) a component may be added.

If the text of an owner node is an OWNERS file path, then this node is
replaced by owner nodes for the emails derived from the OWNERS file.
Updates the given DOM Element ' s descendants if necessary . When a histogram has an owner node whose text is an OWNERS file path rather than an email address e . g . src / base / android / OWNERS instead of joy@chromium . org then ( A ) the histogram ' s owners need to be updated and ( B ) a component may be added . If the text of an owner node is an OWNERS file path then this node is replaced by owner nodes for the emails derived from the OWNERS file .
def ExpandHistogramsOWNERS(histograms):
  email_pattern = re.compile(_EMAIL_PATTERN)
  iter_matches = extract_histograms.IterElementsWithTag
  for histogram in iter_matches(histograms, 'histogram'):
    owners = [owner for owner in iter_matches(histogram, 'owner', 1)]
    emails_with_dom_elements = set([
        owner.childNodes[0].data
        for owner in owners
        if email_pattern.match(owner.childNodes[0].data)])
    components_with_dom_elements = set([
      extract_histograms.NormalizeString(component.childNodes[0].data)
      for component in iter_matches(histogram, 'component', 1)])
    for index, owner in enumerate(owners):
      owner_text = owner.childNodes[0].data.strip()
      name = histogram.getAttribute('name')
      obsolete_tags = [tag for tag in iter_matches(histogram, 'obsolete', 1)]
      is_obsolete = len(obsolete_tags) > 0
      if _IsEmailOrPlaceholder(index == 0, owner_text, name, is_obsolete):
        continue
      path = _GetOwnersFilePath(owner_text)
      if not os.path.exists(path) or not os.path.isfile(path):
        raise Error('The file at {} does not exist.'.format(path))
      owners_to_add = _MakeOwners(
        owner.ownerDocument, path, emails_with_dom_elements)
      if not owners_to_add:
        continue
      _UpdateHistogramOwners(histogram, owner, owners_to_add)
      component = _ExtractComponentViaDirmd(os.path.dirname(path))
      if component and component not in components_with_dom_elements:
        components_with_dom_elements.add(component)
        _AddHistogramComponent(histogram, component)
def ExpandHistogramsOWNERS ( histograms ) : email_pattern = re . compile ( _EMAIL_PATTERN ) iter_matches = extract_histograms . IterElementsWithTag for histogram in iter_matches ( histograms , 'histogram' ) : owners = [ owner for owner in iter_matches ( histogram , 'owner' , 1 ) ] emails_with_dom_elements = set ( [ owner . childNodes [ 0 ] . data for owner in owners if email_pattern . match ( owner . childNodes [ 0 ] . data ) ] ) components_with_dom_elements = set ( [ extract_histograms . NormalizeString ( component . childNodes [ 0 ] . data ) for component in iter_matches ( histogram , 'component' , 1 ) ] ) for index , owner in enumerate ( owners ) : owner_text = owner . childNodes [ 0 ] . data . strip ( ) name = histogram . getAttribute ( 'name' ) obsolete_tags = [ tag for tag in iter_matches ( histogram , 'obsolete' , 1 ) ] is_obsolete = len ( obsolete_tags ) > 0 if _IsEmailOrPlaceholder ( index == 0 , owner_text , name , is_obsolete ) : continue path = _GetOwnersFilePath ( owner_text ) if not os . path . exists ( path ) or not os . path . isfile ( path ) : raise Error ( 'The file at {} does not exist.' . format ( path ) ) owners_to_add = _MakeOwners ( owner . ownerDocument , path , emails_with_dom_elements ) if not owners_to_add : continue _UpdateHistogramOwners ( histogram , owner , owners_to_add ) component = _ExtractComponentViaDirmd ( os . path . dirname ( path ) ) if component and component not in components_with_dom_elements : components_with_dom_elements . add ( component ) _AddHistogramComponent ( histogram , component )
Updates the given DOM Element's descendants, if necessary.
Updates the given DOM Element ' s descendants if necessary .
"""Updates the given DOM Element's descendants, if necessary.

  When a histogram has an owner node whose text is an OWNERS file path rather
  than an email address, e.g. <owner>src/base/android/OWNERS</owner> instead of
  <owner>joy@chromium.org</owner>, then (A) the histogram's owners need to be
  updated and (B) a component may be added.

  If the text of an owner node is an OWNERS file path, then this node is
  replaced by owner nodes for the emails derived from the OWNERS file. If a
  component, e.g. UI>GFX, can be derived from the OWNERS file or an OWNERS file
  in a higher-level directory, then a component tag will be added to the
  histogram, e.g. <component>UI&gt;GFX</component>.

  Args:
    histograms: The DOM Element whose descendants may be updated.

  Raises:
    Error: Raised if the OWNERS file with the given path does not exist.
  """ # owner is a DOM Element with a single child, which is a DOM Text Node. # component is a DOM Element with a single child, which is a DOM Text Node.
Raised if the OWNERS file with the given path does not exist.
Raised if the OWNERS file with the given path does not exist .
Error
histograms
The DOM Element whose descendants may be updated.
The DOM Element whose descendants may be updated .