tools/metrics/histograms/update_policies.py
def UpdatePoliciesHistogramDefinitions(policy_templates, doc):
  """Sets the children of <enum name="EnterprisePolicies" ...> node in |doc| to
  values generated from policy ids contained in |policy_templates|.

  Args:
    policy_templates: A list of dictionaries, defining policies or policy
                      groups. The format is exactly the same as in
                      policy_templates.json file.
    doc: A minidom.Document object representing parsed histogram definitions
         XML file.
  """
  # Find EnterprisePolicies enum.
  for enum_node in doc.getElementsByTagName('enum'):
    if enum_node.attributes['name'].value == POLICIES_ENUM_NAME:
      policy_enum_node = enum_node
      break
  else:
    raise UserError('No policy enum node found')

  # Remove existing values.
  while policy_enum_node.hasChildNodes():
    policy_enum_node.removeChild(policy_enum_node.lastChild)

  # Add a "Generated from (...)" comment
  comment = ' Generated from {0} '.format(POLICY_TEMPLATES_PATH)
  policy_enum_node.appendChild(doc.createComment(comment))

  # Add values generated from policy templates.
  ordered_policies = [x for x in policy_templates['policy_definitions']
                      if x['type'] != 'group']
  ordered_policies.sort(key=lambda policy: policy['id'])
  for policy in ordered_policies:
    node = doc.createElement('int')
    node.attributes['value'] = str(policy['id'])
    node.attributes['label'] = policy['name']
    policy_enum_node.appendChild(node)
Sets the children of <enum name="EnterprisePolicies" ...> node in |doc| to
  values generated from policy ids contained in |policy_templates|.

  Args:
    policy_templates: A list of dictionaries, defining policies or policy
                      groups. The format is exactly the same as in
                      policy_templates.json file.
    doc: A minidom.Document object representing parsed histogram definitions
         XML file.
  
Sets the children of  node in |doc| to
values generated from policy ids contained in |policy_templates|.
Sets the children of node in |doc| to values generated from policy ids contained in |policy_templates| .
def UpdatePoliciesHistogramDefinitions(policy_templates, doc):
  for enum_node in doc.getElementsByTagName('enum'):
    if enum_node.attributes['name'].value == POLICIES_ENUM_NAME:
      policy_enum_node = enum_node
      break
  else:
    raise UserError('No policy enum node found')
  while policy_enum_node.hasChildNodes():
    policy_enum_node.removeChild(policy_enum_node.lastChild)
  comment = ' Generated from {0} '.format(POLICY_TEMPLATES_PATH)
  policy_enum_node.appendChild(doc.createComment(comment))
  ordered_policies = [x for x in policy_templates['policy_definitions']
                      if x['type'] != 'group']
  ordered_policies.sort(key=lambda policy: policy['id'])
  for policy in ordered_policies:
    node = doc.createElement('int')
    node.attributes['value'] = str(policy['id'])
    node.attributes['label'] = policy['name']
    policy_enum_node.appendChild(node)
def UpdatePoliciesHistogramDefinitions ( policy_templates , doc ) : for enum_node in doc . getElementsByTagName ( 'enum' ) : if enum_node . attributes [ 'name' ] . value == POLICIES_ENUM_NAME : policy_enum_node = enum_node break else : raise UserError ( 'No policy enum node found' ) while policy_enum_node . hasChildNodes ( ) : policy_enum_node . removeChild ( policy_enum_node . lastChild ) comment = ' Generated from {0} ' . format ( POLICY_TEMPLATES_PATH ) policy_enum_node . appendChild ( doc . createComment ( comment ) ) ordered_policies = [ x for x in policy_templates [ 'policy_definitions' ] if x [ 'type' ] != 'group' ] ordered_policies . sort ( key = lambda policy : policy [ 'id' ] ) for policy in ordered_policies : node = doc . createElement ( 'int' ) node . attributes [ 'value' ] = str ( policy [ 'id' ] ) node . attributes [ 'label' ] = policy [ 'name' ] policy_enum_node . appendChild ( node )
Sets the children of <enum name="EnterprisePolicies" ...> node in |doc| to
values generated from policy ids contained in |policy_templates|.
Sets the children of <enum name = " EnterprisePolicies " ... > node in |doc| to values generated from policy ids contained in |policy_templates| .
"""Sets the children of <enum name="EnterprisePolicies" ...> node in |doc| to
  values generated from policy ids contained in |policy_templates|.

  Args:
    policy_templates: A list of dictionaries, defining policies or policy
                      groups. The format is exactly the same as in
                      policy_templates.json file.
    doc: A minidom.Document object representing parsed histogram definitions
         XML file.
  """ # Find EnterprisePolicies enum. # Remove existing values. # Add a "Generated from (...)" comment # Add values generated from policy templates.
policy_templates
A list of dictionaries, defining policies or policy
groups. The format is exactly the same as in
policy_templates.json file.
A list of dictionaries defining policies or policy groups . The format is exactly the same as in policy_templates . json file .
doc
A minidom.Document object representing parsed histogram definitions
XML file.
A minidom . Document object representing parsed histogram definitions XML file .