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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 135 |
136 # Add comments at the top. | 136 # Add comments at the top. |
137 for comment in new_comments: | 137 for comment in new_comments: |
138 enum_node.appendChild(comment) | 138 enum_node.appendChild(comment) |
139 | 139 |
140 # Add in the new enums. | 140 # Add in the new enums. |
141 for value in sorted(new_item_nodes.iterkeys()): | 141 for value in sorted(new_item_nodes.iterkeys()): |
142 enum_node.appendChild(new_item_nodes[value]) | 142 enum_node.appendChild(new_item_nodes[value]) |
143 | 143 |
144 | 144 |
145 def HistogramNeedsUpdate(histogram_enum_name, source_enum_path, start_marker, | |
146 end_marker): | |
147 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path)) | |
148 source_enum_values = ReadHistogramValues(source_enum_path, start_marker, | |
149 end_marker) | |
150 | |
151 HISTOGRAMS_PATH = path_util.GetHistogramsFile() | |
152 | |
153 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) | |
154 with open(HISTOGRAMS_PATH, 'rb') as f: | |
155 histograms_doc = minidom.parse(f) | |
156 f.seek(0) | |
157 xml = f.read() | |
158 | |
159 Log('Comparing histograms enum with new enum definition.') | |
160 UpdateHistogramDefinitions(histogram_enum_name, source_enum_values, | |
161 source_enum_path, histograms_doc) | |
162 | |
163 new_xml = print_style.GetPrintStyle().PrettyPrintNode(histograms_doc) | |
Ilya Sherman
2016/03/02 00:59:29
It looks like you copy/pasted lines 151-163 here.
suzyh_UTC10 (ex-contributor)
2016/03/02 03:23:49
Done. It's a bit messy, but I haven't been able to
Ilya Sherman
2016/03/02 23:18:46
Thanks! This is the structure that I was thinking
| |
164 | |
165 return xml != new_xml | |
166 | |
167 | |
145 def UpdateHistogramFromDict(histogram_enum_name, source_enum_values, | 168 def UpdateHistogramFromDict(histogram_enum_name, source_enum_values, |
146 source_enum_path): | 169 source_enum_path): |
147 """Updates |histogram_enum_name| enum in histograms.xml file with values | 170 """Updates |histogram_enum_name| enum in histograms.xml file with values |
148 from the {value: 'key'} dictionary |source_enum_values|. A comment is added | 171 from the {value: 'key'} dictionary |source_enum_values|. A comment is added |
149 to histograms.xml citing that the values in |histogram_enum_name| were | 172 to histograms.xml citing that the values in |histogram_enum_name| were |
150 sourced from |source_enum_path|. | 173 sourced from |source_enum_path|. |
151 """ | 174 """ |
152 HISTOGRAMS_PATH = path_util.GetHistogramsFile() | 175 HISTOGRAMS_PATH = path_util.GetHistogramsFile() |
153 | 176 |
154 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) | 177 Log('Reading existing histograms from "{0}".'.format(HISTOGRAMS_PATH)) |
(...skipping 30 matching lines...) Expand all Loading... | |
185 start_marker: A regular expression that matches the start of the C++ enum. | 208 start_marker: A regular expression that matches the start of the C++ enum. |
186 end_marker: A regular expression that matches the end of the C++ enum. | 209 end_marker: A regular expression that matches the end of the C++ enum. |
187 """ | 210 """ |
188 | 211 |
189 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path)) | 212 Log('Reading histogram enum definition from "{0}".'.format(source_enum_path)) |
190 source_enum_values = ReadHistogramValues(source_enum_path, start_marker, | 213 source_enum_values = ReadHistogramValues(source_enum_path, start_marker, |
191 end_marker) | 214 end_marker) |
192 | 215 |
193 UpdateHistogramFromDict(histogram_enum_name, source_enum_values, | 216 UpdateHistogramFromDict(histogram_enum_name, source_enum_values, |
194 source_enum_path) | 217 source_enum_path) |
OLD | NEW |