Chromium Code Reviews| 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 enums in histograms.xml file with values read from provided C++ enum. | 5 """Updates enums in histograms.xml file with values read from provided C++ enum. |
| 6 | 6 |
| 7 If the file was pretty-printed, the updated version is pretty-printed too. | 7 If the file was pretty-printed, the updated version is pretty-printed too. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import logging | 10 import logging |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 new_children.append( | 129 new_children.append( |
| 130 CreateEnumItemNode(document, value, source_enum_values[value])) | 130 CreateEnumItemNode(document, value, source_enum_values[value])) |
| 131 | 131 |
| 132 # Update |enum_node|. | 132 # Update |enum_node|. |
| 133 while enum_node.hasChildNodes(): | 133 while enum_node.hasChildNodes(): |
| 134 enum_node.removeChild(enum_node.lastChild) | 134 enum_node.removeChild(enum_node.lastChild) |
| 135 for child in new_children: | 135 for child in new_children: |
| 136 enum_node.appendChild(child) | 136 enum_node.appendChild(child) |
| 137 | 137 |
| 138 | 138 |
| 139 def UpdateHistogramEnum(histogram_enum_name, source_enum_path, | 139 def UpdateHistogramFromDict(histogram_enum_name, source_enum_values, |
| 140 start_marker, end_marker): | 140 source_enum_path): |
| 141 """Updates |histogram_enum_name| enum in histograms.xml file with values | 141 """Updates |histogram_enum_name| enum in histograms.xml file with values |
| 142 read from |source_enum_path|, where |start_marker| and |end_marker| indicate | 142 from the {value: 'key'} dictionary |source_enum_values| |
| 143 the beginning and end of the source enum definition, respectively. | |
| 144 """ | 143 """ |
| 145 # TODO(ahernandez.miralles): The line below is present in nearly every | 144 # TODO(ahernandez.miralles): The line below is present in nearly every |
| 146 # file in this directory; factor out into a central location | 145 # file in this directory; factor out into a central location |
| 147 HISTOGRAMS_PATH = 'histograms.xml' | 146 HISTOGRAMS_PATH = 'histograms.xml' |
| 148 | 147 |
| 149 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path)) | |
| 150 source_enum_values = ReadHistogramValues(source_enum_path, start_marker, | |
| 151 end_marker) | |
| 152 | |
| 153 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) | 148 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) |
| 154 with open(HISTOGRAMS_PATH, 'rb') as f: | 149 with open(HISTOGRAMS_PATH, 'rb') as f: |
| 155 histograms_doc = minidom.parse(f) | 150 histograms_doc = minidom.parse(f) |
| 156 f.seek(0) | 151 f.seek(0) |
| 157 xml = f.read() | 152 xml = f.read() |
| 158 | 153 |
| 159 Log('Comparing histograms enum with new enum definition.') | 154 Log('Comparing histograms enum with new enum definition.') |
| 160 UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, | 155 UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, |
| 161 source_enum_path, histograms_doc) | 156 source_enum_path, histograms_doc) |
| 162 | 157 |
| 163 Log('Writing out new histograms file.') | 158 Log('Writing out new histograms file.') |
| 164 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) | 159 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) |
| 165 if not PromptUserToAcceptDiff( | 160 if not PromptUserToAcceptDiff( |
| 166 xml, new_xml, 'Is the updated version acceptable?'): | 161 xml, new_xml, 'Is the updated version acceptable?'): |
| 167 Log('Cancelled.') | 162 Log('Cancelled.') |
| 168 return | 163 return |
| 169 | 164 |
| 170 with open(HISTOGRAMS_PATH, 'wb') as f: | 165 with open(HISTOGRAMS_PATH, 'wb') as f: |
| 171 f.write(new_xml) | 166 f.write(new_xml) |
| 172 | 167 |
| 173 Log('Done.') | 168 Log('Done.') |
| 169 | |
| 170 | |
| 171 def UpdateHistogramEnum(histogram_enum_name, source_enum_path, | |
| 172 start_marker, end_marker): | |
| 173 """Updates |histogram_enum_name| enum in histograms.xml file with values | |
| 174 read from |source_enum_path|, where |start_marker| and |end_marker| indicate | |
| 175 the beginning and end of the source enum definition, respectively. | |
| 176 """ | |
| 177 | |
| 178 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path)) | |
| 179 source_enum_values = ReadHistogramValues(source_enum_path, start_marker, | |
| 180 end_marker) | |
| 181 | |
| 182 UpdateHistogramFromDict(histogram_enum_name, source_enum_values, | |
| 183 source_enum_path) | |
|
tyoshino (SeeGerritForStatus)
2014/05/08 08:06:53
4 space indent plz
http://google-styleguide.googl
Mike Lawther (Google)
2014/05/09 01:11:03
Done.
| |
| OLD | NEW |