예제 #1
0
def UpdateHistogramFromDict(histogram_enum_name, source_enum_values,
                            source_enum_path):
    """Updates |histogram_enum_name| enum in histograms.xml file with values
  from the {value: 'key'} dictionary |source_enum_values|. A comment is added
  to histograms.xml citing that the values in |histogram_enum_name| were
  sourced from |source_enum_path|.
  """
    HISTOGRAMS_PATH = path_util.GetHistogramsFile()

    Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH))
    with open(HISTOGRAMS_PATH, 'rb') as f:
        histograms_doc = minidom.parse(f)
        f.seek(0)
        xml = f.read()

    Log('Comparing histograms enum with new enum definition.')
    UpdateHistogramDefinitions(histogram_enum_name, source_enum_values,
                               source_enum_path, histograms_doc)

    Log('Writing out new histograms file.')
    new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
    if not diff_util.PromptUserToAcceptDiff(
            xml, new_xml, 'Is the updated version acceptable?'):
        Log('Cancelled.')
        return

    with open(HISTOGRAMS_PATH, 'wb') as f:
        f.write(new_xml)

    Log('Done.')
예제 #2
0
def main():
  tree = xml.etree.ElementTree.parse(path_util.GetHistogramsFile())
  root = tree.getroot()
  assert root.tag == 'histogram-configuration'

  root_children = root.getchildren()
  histograms = None
  for node in root_children:
    if node.tag == 'histograms':
      histograms = node
      break
  assert histograms != None

  for histogram in histograms.getchildren():
    if histogram.tag != 'histogram':
      continue

    name = histogram.attrib['name']
    owners = []
    obsolete = False
    for node in histogram.getchildren():
      if node.tag == 'obsolete':
        obsolete = True
        continue
      if node.tag != 'owner':
        continue
      if node.text == DUMMY_OWNER:
        continue
      assert '@' in node.text
      owners.append(node.text)

    if not obsolete:
      if owners:
        print name, ' '.join(owners)
      else:
        print name, 'NO_OWNER'
예제 #3
0
import os
import re
import sys

from ast import literal_eval
from optparse import OptionParser
from xml.dom import minidom

sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
from diff_util import PromptUserToAcceptDiff
import path_util

import print_style

HISTOGRAMS_PATH = path_util.GetHistogramsFile()
POLICY_TEMPLATES_PATH = 'components/policy/resources/policy_templates.json'
ENUM_NAME = 'EnterprisePolicies'


class UserError(Exception):
    def __init__(self, message):
        Exception.__init__(self, message)

    @property
    def message(self):
        return self.args[0]


def FlattenPolicies(policy_definitions, policy_list):
    """Appends a list of policies defined in |policy_definitions| to
예제 #4
0
def main():
    # This will raise an exception if the file is not well-formatted.
    xml_file = path_util.GetHistogramsFile()
    histograms = extract_histograms.ExtractHistograms(xml_file)