| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 # and the value is a pair of the tag name of the children we want to sort, | 33 # and the value is a pair of the tag name of the children we want to sort, |
| 34 # and a key function that maps each child node to the desired sort key. | 34 # and a key function that maps each child node to the desired sort key. |
| 35 ALPHABETIZATION_RULES = { | 35 ALPHABETIZATION_RULES = { |
| 36 'histograms': ('histogram', lambda n: n.attributes['name'].value.lower()), | 36 'histograms': ('histogram', lambda n: n.attributes['name'].value.lower()), |
| 37 'enums': ('enum', lambda n: n.attributes['name'].value.lower()), | 37 'enums': ('enum', lambda n: n.attributes['name'].value.lower()), |
| 38 'enum': ('int', lambda n: int(n.attributes['value'].value)), | 38 'enum': ('int', lambda n: int(n.attributes['value'].value)), |
| 39 'histogram_suffixes_list': ( | 39 'histogram_suffixes_list': ( |
| 40 'histogram_suffixes', lambda n: n.attributes['name'].value.lower()), | 40 'histogram_suffixes', lambda n: n.attributes['name'].value.lower()), |
| 41 'histogram_suffixes': ('affected-histogram', | 41 'histogram_suffixes': ('affected-histogram', |
| 42 lambda n: n.attributes['name'].value.lower()), | 42 lambda n: n.attributes['name'].value.lower()), |
| 43 # TODO(yiyaoliu): Remove fieldtrial related pieces when it is not used. | |
| 44 'fieldtrials': ('fieldtrial', lambda n: n.attributes['name'].value.lower()), | |
| 45 'fieldtrial': ('affected-histogram', | |
| 46 lambda n: n.attributes['name'].value.lower()), | |
| 47 } | 43 } |
| 48 | 44 |
| 49 | 45 |
| 50 class Error(Exception): | 46 class Error(Exception): |
| 51 pass | 47 pass |
| 52 | 48 |
| 53 | 49 |
| 54 def unsafeAppendChild(parent, child): | 50 def unsafeAppendChild(parent, child): |
| 55 """Append child to parent's list of children, ignoring the possibility that it | 51 """Append child to parent's list of children, ignoring the possibility that it |
| 56 is already in another node's childNodes list. Requires that the previous | 52 is already in another node's childNodes list. Requires that the previous |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 logging.info('Creating backup file %s' % histograms_backup_filename) | 169 logging.info('Creating backup file %s' % histograms_backup_filename) |
| 174 shutil.move(histograms_pathname, histograms_backup_pathname) | 170 shutil.move(histograms_pathname, histograms_backup_pathname) |
| 175 | 171 |
| 176 logging.info('Writing new %s file' % histograms_filename) | 172 logging.info('Writing new %s file' % histograms_filename) |
| 177 with open(histograms_pathname, 'wb') as f: | 173 with open(histograms_pathname, 'wb') as f: |
| 178 f.write(pretty) | 174 f.write(pretty) |
| 179 | 175 |
| 180 | 176 |
| 181 if __name__ == '__main__': | 177 if __name__ == '__main__': |
| 182 main() | 178 main() |
| OLD | NEW |