| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Updates ExtensionFunctions enum in histograms.xml file with values read from | 5 """Updates ExtensionFunctions enum in histograms.xml file with values read from |
| 6 extension_function_histogram_value.h. | 6 extension_function_histogram_value.h. |
| 7 | 7 |
| 8 If the file was pretty-printed, the updated version is pretty-printed too. | 8 If the file was pretty-printed, the updated version is pretty-printed too. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import logging | 11 import logging |
| 12 import os |
| 12 import re | 13 import re |
| 13 import sys | 14 import sys |
| 14 | 15 |
| 15 from xml.dom import minidom | 16 from xml.dom import minidom |
| 17 import print_style |
| 16 | 18 |
| 17 from diffutil import PromptUserToAcceptDiff | 19 # Import the metrics/common module. |
| 18 from pretty_print import PrettyPrintNode | 20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
| 21 from diff_util import PromptUserToAcceptDiff |
| 19 | 22 |
| 20 HISTOGRAMS_PATH = 'histograms.xml' | 23 HISTOGRAMS_PATH = 'histograms.xml' |
| 21 ENUM_NAME = 'ExtensionFunctions' | 24 ENUM_NAME = 'ExtensionFunctions' |
| 22 | 25 |
| 23 EXTENSION_FUNCTIONS_HISTOGRAM_VALUE_PATH = \ | 26 EXTENSION_FUNCTIONS_HISTOGRAM_VALUE_PATH = \ |
| 24 '../../../extensions/browser/extension_function_histogram_value.h' | 27 '../../../extensions/browser/extension_function_histogram_value.h' |
| 25 ENUM_START_MARKER = "^enum HistogramValue {" | 28 ENUM_START_MARKER = "^enum HistogramValue {" |
| 26 ENUM_END_MARKER = "^ENUM_BOUNDARY" | 29 ENUM_END_MARKER = "^ENUM_BOUNDARY" |
| 27 | 30 |
| 28 | 31 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 Log('Reading existing histograms from "%s".' % (HISTOGRAMS_PATH)) | 132 Log('Reading existing histograms from "%s".' % (HISTOGRAMS_PATH)) |
| 130 with open(HISTOGRAMS_PATH, 'rb') as f: | 133 with open(HISTOGRAMS_PATH, 'rb') as f: |
| 131 histograms_doc = minidom.parse(f) | 134 histograms_doc = minidom.parse(f) |
| 132 f.seek(0) | 135 f.seek(0) |
| 133 xml = f.read() | 136 xml = f.read() |
| 134 | 137 |
| 135 Log('Comparing histograms enum with new enum definition.') | 138 Log('Comparing histograms enum with new enum definition.') |
| 136 UpdateHistogramDefinitions(histogram_values, histograms_doc) | 139 UpdateHistogramDefinitions(histogram_values, histograms_doc) |
| 137 | 140 |
| 138 Log('Writing out new histograms file.') | 141 Log('Writing out new histograms file.') |
| 139 new_xml = PrettyPrintNode(histograms_doc) | 142 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) |
| 143 |
| 140 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): | 144 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): |
| 141 with open(HISTOGRAMS_PATH, 'wb') as f: | 145 with open(HISTOGRAMS_PATH, 'wb') as f: |
| 142 f.write(new_xml) | 146 f.write(new_xml) |
| 143 | 147 |
| 144 Log('Done.') | 148 Log('Done.') |
| 145 | 149 |
| 146 | 150 |
| 147 if __name__ == '__main__': | 151 if __name__ == '__main__': |
| 148 main() | 152 main() |
| OLD | NEW |