tools/metrics/histograms/suffixes_to_variants.py
def _PopulateVariantsWithSuffixes(doc, node, histogram_suffixes):
  """Populates <variant> nodes to |node| from <suffix>.

  This function returns True if none of the suffixes contains 'base' attribute.
  If this function returns false, the caller's histogram node will not be
  updated. This is mainly because base suffix is a much more complicated case
  and thus it can not be automatically updated at least for now.

  Args:
    doc: A Document object which is used to create a new <variant> node.
    node: The node to be populated. it should be either <token> for inline
      variants or <variants> for out-of-line variants.
    histogram_suffixes: A <histogram_suffixes> node.

  Returns:
    True if the node can be updated automatically.
  """
  separator = histogram_suffixes.getAttribute('separator')
  suffixes_owners = _ExtractOwnerNodes(histogram_suffixes)
  suffixes_name = histogram_suffixes.getAttribute('name')
  # Check if <histogram_suffixes> node has its own <obsolete> node.
  obsolete_histogram_suffix_node = _ExtractObsoleteNode(histogram_suffixes,
                                                        False)
  for suffix in histogram_suffixes.getElementsByTagName('suffix'):
    # The base suffix is a much more complicated case. It might require manual
    # effort to migrate them so skip this case for now.
    suffix_name = suffix.getAttribute('name')
    if suffix.hasAttribute('base'):
      logging.warning(
          'suffix: %s in histogram_suffixes %s has base attribute. Please '
          'manually migrate it.', suffix_name, suffixes_name)
      return False
    # Suffix name might be empty. In this case, in order not to collide with the
    # base variant, remove the base variant first before populating this.
    if not suffix_name:
      logging.warning(
          'histogram suffixes: %s contains empty string suffix and thus we '
          'have to manually update the empty string variant in these base '
          'histograms: %s.', suffixes_name, ','.join(
              h.getAttribute('name') for h in
              histogram_suffixes.getElementsByTagName('affected-histogram')))
      return False
    variant = doc.createElement('variant')
    if histogram_suffixes.hasAttribute('ordering'):
      variant.setAttribute('name', suffix_name + separator)
    else:
      variant.setAttribute('name', separator + suffix_name)
    if suffix.hasAttribute('label'):
      variant.setAttribute('summary', suffix.getAttribute('label'))
    # Obsolete the obsolete node from suffix to the new variant. The obsolete
    # node for each suffix should override the obsolete node, if exists,
    # in the histogram_suffixes node.
    obsolete = _ExtractObsoleteNode(suffix) or obsolete_histogram_suffix_node
    if obsolete:
      variant.appendChild(obsolete.cloneNode(deep=True))
    # Populate owner's node from histogram suffixes to each new variant.
    for owner in suffixes_owners:
      variant.appendChild(owner.cloneNode(deep=True))
    node.appendChild(variant)
  return True
Populates <variant> nodes to |node| from <suffix>.

  This function returns True if none of the suffixes contains 'base' attribute.
  If this function returns false, the caller's histogram node will not be
  updated. This is mainly because base suffix is a much more complicated case
  and thus it can not be automatically updated at least for now.

  Args:
    doc: A Document object which is used to create a new <variant> node.
    node: The node to be populated. it should be either <token> for inline
      variants or <variants> for out-of-line variants.
    histogram_suffixes: A <histogram_suffixes> node.

  Returns:
    True if the node can be updated automatically.
  
Populates  nodes to |node| from .
This function returns True if none of the suffixes contains 'base' attribute.
If this function returns false, the caller's histogram node will not be
updated. This is mainly because base suffix is a much more complicated case
and thus it can not be automatically updated at least for now.
Populates nodes to |node| from . This function returns True if none of the suffixes contains ' base ' attribute . If this function returns false the caller ' s histogram node will not be updated . This is mainly because base suffix is a much more complicated case and thus it can not be automatically updated at least for now .
def _PopulateVariantsWithSuffixes(doc, node, histogram_suffixes):
  separator = histogram_suffixes.getAttribute('separator')
  suffixes_owners = _ExtractOwnerNodes(histogram_suffixes)
  suffixes_name = histogram_suffixes.getAttribute('name')
  obsolete_histogram_suffix_node = _ExtractObsoleteNode(histogram_suffixes,
                                                        False)
  for suffix in histogram_suffixes.getElementsByTagName('suffix'):
    suffix_name = suffix.getAttribute('name')
    if suffix.hasAttribute('base'):
      logging.warning(
          'suffix: %s in histogram_suffixes %s has base attribute. Please '
          'manually migrate it.', suffix_name, suffixes_name)
      return False
    if not suffix_name:
      logging.warning(
          'histogram suffixes: %s contains empty string suffix and thus we '
          'have to manually update the empty string variant in these base '
          'histograms: %s.', suffixes_name, ','.join(
              h.getAttribute('name') for h in
              histogram_suffixes.getElementsByTagName('affected-histogram')))
      return False
    variant = doc.createElement('variant')
    if histogram_suffixes.hasAttribute('ordering'):
      variant.setAttribute('name', suffix_name + separator)
    else:
      variant.setAttribute('name', separator + suffix_name)
    if suffix.hasAttribute('label'):
      variant.setAttribute('summary', suffix.getAttribute('label'))
    obsolete = _ExtractObsoleteNode(suffix) or obsolete_histogram_suffix_node
    if obsolete:
      variant.appendChild(obsolete.cloneNode(deep=True))
    for owner in suffixes_owners:
      variant.appendChild(owner.cloneNode(deep=True))
    node.appendChild(variant)
  return True
def _PopulateVariantsWithSuffixes ( doc , node , histogram_suffixes ) : separator = histogram_suffixes . getAttribute ( 'separator' ) suffixes_owners = _ExtractOwnerNodes ( histogram_suffixes ) suffixes_name = histogram_suffixes . getAttribute ( 'name' ) obsolete_histogram_suffix_node = _ExtractObsoleteNode ( histogram_suffixes , False ) for suffix in histogram_suffixes . getElementsByTagName ( 'suffix' ) : suffix_name = suffix . getAttribute ( 'name' ) if suffix . hasAttribute ( 'base' ) : logging . warning ( 'suffix: %s in histogram_suffixes %s has base attribute. Please ' 'manually migrate it.' , suffix_name , suffixes_name ) return False if not suffix_name : logging . warning ( 'histogram suffixes: %s contains empty string suffix and thus we ' 'have to manually update the empty string variant in these base ' 'histograms: %s.' , suffixes_name , ',' . join ( h . getAttribute ( 'name' ) for h in histogram_suffixes . getElementsByTagName ( 'affected-histogram' ) ) ) return False variant = doc . createElement ( 'variant' ) if histogram_suffixes . hasAttribute ( 'ordering' ) : variant . setAttribute ( 'name' , suffix_name + separator ) else : variant . setAttribute ( 'name' , separator + suffix_name ) if suffix . hasAttribute ( 'label' ) : variant . setAttribute ( 'summary' , suffix . getAttribute ( 'label' ) ) obsolete = _ExtractObsoleteNode ( suffix ) or obsolete_histogram_suffix_node if obsolete : variant . appendChild ( obsolete . cloneNode ( deep = True ) ) for owner in suffixes_owners : variant . appendChild ( owner . cloneNode ( deep = True ) ) node . appendChild ( variant ) return True
Populates <variant> nodes to |node| from <suffix>.
Populates <variant > nodes to |node| from <suffix > .
"""Populates <variant> nodes to |node| from <suffix>.

  This function returns True if none of the suffixes contains 'base' attribute.
  If this function returns false, the caller's histogram node will not be
  updated. This is mainly because base suffix is a much more complicated case
  and thus it can not be automatically updated at least for now.

  Args:
    doc: A Document object which is used to create a new <variant> node.
    node: The node to be populated. it should be either <token> for inline
      variants or <variants> for out-of-line variants.
    histogram_suffixes: A <histogram_suffixes> node.

  Returns:
    True if the node can be updated automatically.
  """ # Check if <histogram_suffixes> node has its own <obsolete> node. # The base suffix is a much more complicated case. It might require manual # effort to migrate them so skip this case for now. # Suffix name might be empty. In this case, in order not to collide with the # base variant, remove the base variant first before populating this. # Obsolete the obsolete node from suffix to the new variant. The obsolete # node for each suffix should override the obsolete node, if exists, # in the histogram_suffixes node. # Populate owner's node from histogram suffixes to each new variant.
True if the node can be updated automatically.
True if the node can be updated automatically .
doc
A Document object which is used to create a new  node.
A Document object which is used to create a new node .
node
The node to be populated. it should be either  for inline
variants or  for out-of-line variants.
The node to be populated . it should be either for inline variants or for out - of - line variants .
histogram_suffixes
None