コード例 #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|.
  """
    # TODO(ahernandez.miralles): The line below is present in nearly every
    # file in this directory; factor out into a central location
    HISTOGRAMS_PATH = 'histograms.xml'

    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 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():
  if len(sys.argv) > 1:
    print >>sys.stderr, 'No arguments expected!'
    sys.stderr.write(__doc__)
    sys.exit(1)

  Log('Reading histogram enum definition from "%s".' % EDITOR_COMMAND_CPP)
  histogram_values = ReadHistogramValues(EDITOR_COMMAND_CPP)

  Log('Reading existing histograms from "%s".' % (ENUMS_PATH))
  with open(ENUMS_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_values, histograms_doc)

  Log('Writing out new histograms file.')
  new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
  if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'):
    with open(ENUMS_PATH, 'wb') as f:
      f.write(new_xml)

  Log('Done.')
コード例 #3
0
def main():
    if len(sys.argv) > 1:
        print >> sys.stderr, 'No arguments expected!'
        sys.stderr.write(__doc__)
        sys.exit(1)

    with open(path_util.GetInputFile(POLICY_TEMPLATES_PATH), 'rb') as f:
        policy_templates = literal_eval(f.read())
    with open(HISTOGRAMS_PATH, 'rb') as f:
        histograms_doc = minidom.parse(f)
        f.seek(0)
        xml = f.read()

    UpdateHistogramDefinitions(policy_templates, histograms_doc)
    new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc)
    if PromptUserToAcceptDiff(xml, new_xml,
                              'Is the updated version acceptable?'):
        with open(HISTOGRAMS_PATH, 'wb') as f:
            f.write(new_xml)
コード例 #4
0
def main():
    if len(sys.argv) > 1:
        print('No arguments expected!', file=sys.stderr)
        sys.stderr.write(__doc__)
        sys.exit(1)

    with open(path_util.GetInputFile(POLICY_TEMPLATES_PATH), 'rb') as f:
        policy_templates = literal_eval(f.read().decode('utf-8'))

    with open(ENUMS_PATH, 'rb') as f:
        histograms_doc = minidom.parse(f)
        f.seek(0)
        xml = f.read().decode('utf-8')

    UpdatePoliciesHistogramDefinitions(policy_templates, histograms_doc)
    UpdateAtomicGroupsHistogramDefinitions(policy_templates, histograms_doc)
    new_xml = histogram_configuration_model.PrettifyTree(histograms_doc)
    if PromptUserToAcceptDiff(xml, new_xml,
                              'Is the updated version acceptable?'):
        with open(ENUMS_PATH, 'wb') as f:
            f.write(new_xml.encode('utf-8'))
コード例 #5
0
def UpdateHistogramEnum(histogram_enum_name, source_enum_path, start_marker,
                        end_marker):
    """Updates |histogram_enum_name| enum in histograms.xml file with values
  read from |source_enum_path|, where |start_marker| and |end_marker| indicate
  the beginning and end of the source enum definition, respectively.
  """
    # TODO(ahernandez.miralles): The line below is present in nearly every
    # file in this directory; factor out into a central location
    HISTOGRAMS_PATH = 'histograms.xml'

    if len(sys.argv) > 1:
        print >> sys.stderr, 'No arguments expected!'
        sys.stderr.write(__doc__)
        sys.exit(1)

    Log('Reading histogram enum definition from "{0}".'.format(
        source_enum_path))
    source_enum_values = ReadHistogramValues(source_enum_path, start_marker,
                                             end_marker)

    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 PromptUserToAcceptDiff(xml, new_xml,
                              'Is the updated version acceptable?'):
        with open(HISTOGRAMS_PATH, 'wb') as f:
            f.write(new_xml)

    Log('Done.')