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