tools/resources/list_unused_grit_header.py
def GetResourcesForNode(node, parent_file, resource_tag):
  """Recursively iterate through a node and extract resource names.

  Args:
    node: The node to iterate through.
    parent_file: The file that contains node.
    resource_tag: The resource tag to extract names from.

  Returns:
    A list of resource names.
  """
  resources = []
  for child in node.getchildren():
    if child.tag == resource_tag:
      resources.append(child.attrib['name'])
    elif child.tag in IF_ELSE_THEN_TAGS:
      resources.extend(GetResourcesForNode(child, parent_file, resource_tag))
    elif child.tag == 'part':
      parent_dir = os.path.dirname(parent_file)
      part_file = os.path.join(parent_dir, child.attrib['file'])
      part_tree = xml.etree.ElementTree.parse(part_file)
      part_root = part_tree.getroot()
      assert part_root.tag == 'grit-part'
      resources.extend(GetResourcesForNode(part_root, part_file, resource_tag))
    else:
      raise Exception('unknown tag:', child.tag)

  # Handle the special case for resources of type "FOO_{LEFT,RIGHT,TOP}".
  if resource_tag == 'structure':
    resources = [FilterResourceIds(resource_id) for resource_id in resources]
  return resources
Recursively iterate through a node and extract resource names.

  Args:
    node: The node to iterate through.
    parent_file: The file that contains node.
    resource_tag: The resource tag to extract names from.

  Returns:
    A list of resource names.
  
Recursively iterate through a node and extract resource names.
Recursively iterate through a node and extract resource names .
def GetResourcesForNode(node, parent_file, resource_tag):
  resources = []
  for child in node.getchildren():
    if child.tag == resource_tag:
      resources.append(child.attrib['name'])
    elif child.tag in IF_ELSE_THEN_TAGS:
      resources.extend(GetResourcesForNode(child, parent_file, resource_tag))
    elif child.tag == 'part':
      parent_dir = os.path.dirname(parent_file)
      part_file = os.path.join(parent_dir, child.attrib['file'])
      part_tree = xml.etree.ElementTree.parse(part_file)
      part_root = part_tree.getroot()
      assert part_root.tag == 'grit-part'
      resources.extend(GetResourcesForNode(part_root, part_file, resource_tag))
    else:
      raise Exception('unknown tag:', child.tag)
  if resource_tag == 'structure':
    resources = [FilterResourceIds(resource_id) for resource_id in resources]
  return resources
def GetResourcesForNode ( node , parent_file , resource_tag ) : resources = [ ] for child in node . getchildren ( ) : if child . tag == resource_tag : resources . append ( child . attrib [ 'name' ] ) elif child . tag in IF_ELSE_THEN_TAGS : resources . extend ( GetResourcesForNode ( child , parent_file , resource_tag ) ) elif child . tag == 'part' : parent_dir = os . path . dirname ( parent_file ) part_file = os . path . join ( parent_dir , child . attrib [ 'file' ] ) part_tree = xml . etree . ElementTree . parse ( part_file ) part_root = part_tree . getroot ( ) assert part_root . tag == 'grit-part' resources . extend ( GetResourcesForNode ( part_root , part_file , resource_tag ) ) else : raise Exception ( 'unknown tag:' , child . tag ) if resource_tag == 'structure' : resources = [ FilterResourceIds ( resource_id ) for resource_id in resources ] return resources
Recursively iterate through a node and extract resource names.
Recursively iterate through a node and extract resource names .
"""Recursively iterate through a node and extract resource names.

  Args:
    node: The node to iterate through.
    parent_file: The file that contains node.
    resource_tag: The resource tag to extract names from.

  Returns:
    A list of resource names.
  """ # Handle the special case for resources of type "FOO_{LEFT,RIGHT,TOP}".
A list of resource names.
A list of resource names .
node
The node to iterate through.
The node to iterate through .
parent_file
The file that contains node.
The file that contains node .
resource_tag
The resource tag to extract names from.
The resource tag to extract names from .