Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: tools/metrics/histograms/pretty_print.py

Issue 509923003: about_flags::ReportCustomFlags() should use signed 32-bit IDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Pretty-prints the histograms.xml file, alphabetizing tags, wrapping text 6 """Pretty-prints the histograms.xml file, alphabetizing tags, wrapping text
7 at 80 chars, enforcing standard attribute ordering, and standardizing 7 at 80 chars, enforcing standard attribute ordering, and standardizing
8 indentation. 8 indentation.
9 9
10 This is quite a bit more complicated than just calling tree.toprettyxml(); 10 This is quite a bit more complicated than just calling tree.toprettyxml();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 """ 73 """
74 if node.nodeType != xml.dom.minidom.Node.ELEMENT_NODE: 74 if node.nodeType != xml.dom.minidom.Node.ELEMENT_NODE:
75 for c in node.childNodes: TransformByAlphabetizing(c) 75 for c in node.childNodes: TransformByAlphabetizing(c)
76 return node 76 return node
77 77
78 # Element node with a tag name that we alphabetize the children of? 78 # Element node with a tag name that we alphabetize the children of?
79 if node.tagName in ALPHABETIZATION_RULES: 79 if node.tagName in ALPHABETIZATION_RULES:
80 # Put subnodes in a list of node,key pairs to allow for custom sorting. 80 # Put subnodes in a list of node,key pairs to allow for custom sorting.
81 subtag, key_function = ALPHABETIZATION_RULES[node.tagName] 81 subtag, key_function = ALPHABETIZATION_RULES[node.tagName]
82 subnodes = [] 82 subnodes = []
83 last_key = -1 83 sort_key = -1
84 unset_node_keys_indexes = []
Ilya Sherman 2014/09/02 22:29:48 nit: Perhaps something like "pending_node_indices"
Alexander Alekseev 2014/09/02 23:53:28 Done.
84 for c in node.childNodes: 85 for c in node.childNodes:
85 if (c.nodeType == xml.dom.minidom.Node.ELEMENT_NODE and 86 if (c.nodeType == xml.dom.minidom.Node.ELEMENT_NODE and
86 c.tagName == subtag): 87 c.tagName == subtag):
87 last_key = key_function(c) 88 sort_key = key_function(c)
88 # Subnodes that we don't want to rearrange use the last node's key, 89 # Replace sort keys for delayed nodes.
89 # so they stay in the same relative position. 90 for idx in unset_node_keys_indexes:
90 subnodes.append( (c, last_key) ) 91 subnodes[idx][1] = sort_key
92 unset_node_keys_indexes = []
93 else:
94 # Subnodes that we don't want to rearrange use the next node's key,
95 # so they stay in the same relative position.
96 # Therefore we delay setting key before next node is found.
Ilya Sherman 2014/09/02 22:29:48 nit: "before next node is found" -> "until the nex
Alexander Alekseev 2014/09/02 23:53:28 Done.
97 unset_node_keys_indexes.append(len(subnodes))
98
99 subnodes.append( [c, sort_key] )
100
101 # Use last sort key for trailing unknown nodes.
102 for idx in unset_node_keys_indexes:
103 subnodes[idx][1] = sort_key
91 104
92 # Sort the subnode list. 105 # Sort the subnode list.
93 subnodes.sort(key=lambda pair: pair[1]) 106 subnodes.sort(key=lambda pair: pair[1])
94 107
95 # Re-add the subnodes, transforming each recursively. 108 # Re-add the subnodes, transforming each recursively.
96 while node.firstChild: 109 while node.firstChild:
97 node.removeChild(node.firstChild) 110 node.removeChild(node.firstChild)
98 for (c, _) in subnodes: 111 for (c, _) in subnodes:
99 unsafeAppendChild(node, TransformByAlphabetizing(c)) 112 unsafeAppendChild(node, TransformByAlphabetizing(c))
100 return node 113 return node
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 logging.info('Creating backup file %s' % histograms_backup_filename) 182 logging.info('Creating backup file %s' % histograms_backup_filename)
170 shutil.move(histograms_pathname, histograms_backup_pathname) 183 shutil.move(histograms_pathname, histograms_backup_pathname)
171 184
172 logging.info('Writing new %s file' % histograms_filename) 185 logging.info('Writing new %s file' % histograms_filename)
173 with open(histograms_pathname, 'wb') as f: 186 with open(histograms_pathname, 'wb') as f:
174 f.write(pretty) 187 f.write(pretty)
175 188
176 189
177 if __name__ == '__main__': 190 if __name__ == '__main__':
178 main() 191 main()
OLDNEW
« no previous file with comments | « tools/metrics/histograms/histograms.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698