| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 MappedEditingCommands enum in histograms.xml file with values read | 5 """Updates MappedEditingCommands enum in histograms.xml file with values read |
| 6 from EditorCommand.cpp. | 6 from EditorCommand.cpp. |
| 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 |
| 16 | 17 |
| 17 from diffutil import PromptUserToAcceptDiff | 18 from diffutil import PromptUserToAcceptDiff |
| 18 from pretty_print import PrettyPrintNode | 19 import print_style |
| 20 |
| 21 # Import the metrics/common module. |
| 22 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
| 23 from diff_util import PromptUserToAcceptDiff |
| 19 | 24 |
| 20 HISTOGRAMS_PATH = 'histograms.xml' | 25 HISTOGRAMS_PATH = 'histograms.xml' |
| 21 ENUM_NAME = 'MappedEditingCommands' | 26 ENUM_NAME = 'MappedEditingCommands' |
| 22 | 27 |
| 23 EXTENSION_FUNCTIONS_HISTOGRAM_VALUE_PATH = \ | 28 EXTENSION_FUNCTIONS_HISTOGRAM_VALUE_PATH = \ |
| 24 '../../../third_party/WebKit/Source/core/editing/EditorCommand.cpp' | 29 '../../../third_party/WebKit/Source/core/editing/EditorCommand.cpp' |
| 25 ENUM_START_MARKER = "^ static const CommandEntry commands\[\] = {" | 30 ENUM_START_MARKER = "^ static const CommandEntry commands\[\] = {" |
| 26 ENUM_END_MARKER = "^ };" | 31 ENUM_END_MARKER = "^ };" |
| 27 | 32 |
| 28 | 33 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 Log('Reading existing histograms from "%s".' % (HISTOGRAMS_PATH)) | 125 Log('Reading existing histograms from "%s".' % (HISTOGRAMS_PATH)) |
| 121 with open(HISTOGRAMS_PATH, 'rb') as f: | 126 with open(HISTOGRAMS_PATH, 'rb') as f: |
| 122 histograms_doc = minidom.parse(f) | 127 histograms_doc = minidom.parse(f) |
| 123 f.seek(0) | 128 f.seek(0) |
| 124 xml = f.read() | 129 xml = f.read() |
| 125 | 130 |
| 126 Log('Comparing histograms enum with new enum definition.') | 131 Log('Comparing histograms enum with new enum definition.') |
| 127 UpdateHistogramDefinitions(histogram_values, histograms_doc) | 132 UpdateHistogramDefinitions(histogram_values, histograms_doc) |
| 128 | 133 |
| 129 Log('Writing out new histograms file.') | 134 Log('Writing out new histograms file.') |
| 130 new_xml = PrettyPrintNode(histograms_doc) | 135 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) |
| 131 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): | 136 if PromptUserToAcceptDiff(xml, new_xml, 'Is the updated version acceptable?'): |
| 132 with open(HISTOGRAMS_PATH, 'wb') as f: | 137 with open(HISTOGRAMS_PATH, 'wb') as f: |
| 133 f.write(new_xml) | 138 f.write(new_xml) |
| 134 | 139 |
| 135 Log('Done.') | 140 Log('Done.') |
| 136 | 141 |
| 137 | 142 |
| 138 if __name__ == '__main__': | 143 if __name__ == '__main__': |
| 139 main() | 144 main() |
| OLD | NEW |