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 """Holds the constants for pretty printing histograms.xml.""" | 5 """Holds the constants for pretty printing histograms.xml.""" |
6 | 6 |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 | 9 |
10 # Import the metrics/common module for pretty print xml. | 10 # Import the metrics/common module for pretty print xml. |
11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) | 11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
12 import pretty_print_xml | 12 import pretty_print_xml |
13 | 13 |
14 # Desired order for tag attributes; attributes listed here will appear first, | 14 # Desired order for tag attributes; attributes listed here will appear first, |
15 # and in the same order as in these lists. | 15 # and in the same order as in these lists. |
16 # { tag_name: [attribute_name, ...] } | 16 # { tag_name: [attribute_name, ...] } |
17 ATTRIBUTE_ORDER = { | 17 ATTRIBUTE_ORDER = { |
18 'enum': ['name', 'type'], | 18 'enum': ['name', 'type'], |
19 'histogram': ['name', 'enum', 'units'], | 19 'histogram': ['name', 'enum', 'units'], |
20 'int': ['value', 'label'], | 20 'int': ['value', 'label'], |
21 'histogram_suffixes': ['name', 'separator', 'ordering'], | 21 'histogram_suffixes': ['name', 'separator', 'ordering'], |
22 'suffix': ['name', 'label'], | 22 'suffix': ['name', 'label'], |
23 # TODO(yiyaoliu): Remove fieldtrial related pieces when it is not used. | |
24 'fieldtrial': ['name', 'separator', 'ordering'], | |
25 'group': ['name', 'label'], | |
26 'affected-histogram': ['name'], | 23 'affected-histogram': ['name'], |
27 'with-group': ['name'], | |
28 'with-suffix': ['name'], | 24 'with-suffix': ['name'], |
29 } | 25 } |
30 | 26 |
31 # Tag names for top-level nodes whose children we don't want to indent. | 27 # Tag names for top-level nodes whose children we don't want to indent. |
32 TAGS_THAT_DONT_INDENT = [ | 28 TAGS_THAT_DONT_INDENT = [ |
33 'histogram-configuration', | 29 'histogram-configuration', |
34 'histograms', | 30 'histograms', |
35 'histogram_suffixes_list', | 31 'histogram_suffixes_list', |
36 # TODO(yiyaoliu): Remove fieldtrial related pieces when it is not used. | |
37 'fieldtrials', | |
38 'enums' | 32 'enums' |
39 ] | 33 ] |
40 | 34 |
41 # Extra vertical spacing rules for special tag names. | 35 # Extra vertical spacing rules for special tag names. |
42 # {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)} | 36 # {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)} |
43 TAGS_THAT_HAVE_EXTRA_NEWLINE = { | 37 TAGS_THAT_HAVE_EXTRA_NEWLINE = { |
44 'histogram-configuration': (2, 1, 1), | 38 'histogram-configuration': (2, 1, 1), |
45 'histograms': (2, 1, 1), | 39 'histograms': (2, 1, 1), |
46 # TODO(yiyaoliu): Remove fieldtrial related pieces when it is not used. | 40 'histogram': (1, 1, 1), |
47 'fieldtrials': (2, 1, 1), | |
48 'histogram_suffixes_list': (2, 1, 1), | 41 'histogram_suffixes_list': (2, 1, 1), |
49 'histogram_suffixes': (1, 1, 1), | 42 'histogram_suffixes': (1, 1, 1), |
50 'enums': (2, 1, 1), | 43 'enums': (2, 1, 1), |
51 'histogram': (1, 1, 1), | |
52 'enum': (1, 1, 1), | 44 'enum': (1, 1, 1), |
53 'fieldtrial': (1, 1, 1), | |
54 } | 45 } |
55 | 46 |
56 # Tags that we allow to be squished into a single line for brevity. | 47 # Tags that we allow to be squished into a single line for brevity. |
57 TAGS_THAT_ALLOW_SINGLE_LINE = [ | 48 TAGS_THAT_ALLOW_SINGLE_LINE = [ |
58 'summary', | 49 'summary', |
59 'int', | 50 'int', |
60 'owner', | 51 'owner', |
61 ] | 52 ] |
62 | 53 |
63 | 54 |
64 def GetPrintStyle(): | 55 def GetPrintStyle(): |
65 """Returns an XmlStyle object for pretty printing histograms.""" | 56 """Returns an XmlStyle object for pretty printing histograms.""" |
66 return pretty_print_xml.XmlStyle(ATTRIBUTE_ORDER, | 57 return pretty_print_xml.XmlStyle(ATTRIBUTE_ORDER, |
67 TAGS_THAT_HAVE_EXTRA_NEWLINE, | 58 TAGS_THAT_HAVE_EXTRA_NEWLINE, |
68 TAGS_THAT_DONT_INDENT, | 59 TAGS_THAT_DONT_INDENT, |
69 TAGS_THAT_ALLOW_SINGLE_LINE) | 60 TAGS_THAT_ALLOW_SINGLE_LINE) |
OLD | NEW |