| 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 re | 12 import re |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 from xml.dom import minidom | 15 from xml.dom import minidom |
| 16 import print_style |
| 16 | 17 |
| 17 from diffutil import PromptUserToAcceptDiff | 18 # Import the metrics/common module. |
| 18 from pretty_print import PrettyPrintNode | 19 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
| 20 from diff_util import PromptUserToAcceptDiff |
| 19 | 21 |
| 20 HISTOGRAMS_PATH = 'histograms.xml' | 22 HISTOGRAMS_PATH = 'histograms.xml' |
| 21 ENUM_NAME = 'ExtensionFunctions' | 23 ENUM_NAME = 'ExtensionFunctions' |
| 22 | 24 |
| 23 EXTENSION_FUNCTIONS_HISTOGRAM_VALUE_PATH = \ | 25 EXTENSION_FUNCTIONS_HISTOGRAM_VALUE_PATH = \ |
| 24 '../../../chrome/browser/extensions/extension_function_histogram_value.h' | 26 '../../../chrome/browser/extensions/extension_function_histogram_value.h' |
| 25 ENUM_START_MARKER = "^enum HistogramValue {" | 27 ENUM_START_MARKER = "^enum HistogramValue {" |
| 26 ENUM_END_MARKER = "^ENUM_BOUNDARY" | 28 ENUM_END_MARKER = "^ENUM_BOUNDARY" |
| 27 | 29 |
| 28 | 30 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 Log('Reading existing histograms from "%s".' % (HISTOGRAMS_PATH)) | 131 Log('Reading existing histograms from "%s".' % (HISTOGRAMS_PATH)) |
| 130 with open(HISTOGRAMS_PATH, 'rb') as f: | 132 with open(HISTOGRAMS_PATH, 'rb') as f: |
| 131 histograms_doc = minidom.parse(f) | 133 histograms_doc = minidom.parse(f) |
| 132 f.seek(0) | 134 f.seek(0) |
| 133 xml = f.read() | 135 xml = f.read() |
| 134 | 136 |
| 135 Log('Comparing histograms enum with new enum definition.') | 137 Log('Comparing histograms enum with new enum definition.') |
| 136 UpdateHistogramDefinitions(histogram_values, histograms_doc) | 138 UpdateHistogramDefinitions(histogram_values, histograms_doc) |
| 137 | 139 |
| 138 Log('Writing out new histograms file.') | 140 Log('Writing out new histograms file.') |
| 139 new_xml = PrettyPrintNode(histograms_doc) | 141 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) |
| 142 |
| 140 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): | 143 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): |
| 141 with open(HISTOGRAMS_PATH, 'wb') as f: | 144 with open(HISTOGRAMS_PATH, 'wb') as f: |
| 142 f.write(new_xml) | 145 f.write(new_xml) |
| 143 | 146 |
| 144 Log('Done.') | 147 Log('Done.') |
| 145 | 148 |
| 146 | 149 |
| 147 if __name__ == '__main__': | 150 if __name__ == '__main__': |
| 148 main() | 151 main() |
| OLD | NEW |