2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Scans the Chromium source of UseCounter, formats the Feature enum for
7 histograms.xml and merges it. This script can also generate a python code
8 snippet to put in uma.py of Chromium Dashboard. Make sure that you review the
9 output for correctness.
17 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), '..', 'common'))
18 from update_histogram_enum
import ReadHistogramValues
19 from update_histogram_enum
import UpdateHistogramFromDict
20 from update_use_counter_feature_enum
import PrintEnumForDashboard
23 USE_COUNTER_CPP_PATH
= \
24 '../../../third_party/WebKit/Source/core/frame/UseCounter.cpp'
27 def EnumToCssProperty(enum_name
):
28 """Converts a camel cased enum name to the lower case CSS property."""
29 # The first group also searches for uppercase letters to account for single
30 # uppercase letters, such as in "ZIndex" that need to convert to "z-index".
31 return re
.sub(r
'([a-zA-Z])([A-Z])', r
'\1-\2', enum_name
).lower()
34 def ReadCssProperties(filename
):
35 # Read the file as a list of lines
36 with
open(filename
) as f
:
37 content
= f
.readlines()
39 # Looking for a line like "case CSSPropertyGrid: return 453;".
40 ENUM_REGEX
= re
.compile(r
"""CSSProperty(.*): # capture the enum name
42 ([0-9]+) # capture the id
47 enum_match
= ENUM_REGEX
.search(line
)
49 enum_name
= enum_match
.group(1)
50 property_id
= int(enum_match
.group(2))
51 properties
[property_id
] = EnumToCssProperty(enum_name
)
56 if __name__
== '__main__':
57 parser
= optparse
.OptionParser()
58 parser
.add_option('--for-dashboard', action
='store_true', dest
='dashboard',
60 help='Print enum definition formatted for use in uma.py of '
61 'Chromium dashboard developed at '
62 'https://github.com/GoogleChrome/chromium-dashboard')
63 options
, args
= parser
.parse_args()
66 enum_dict
= ReadCssProperties(USE_COUNTER_CPP_PATH
)
67 PrintEnumForDashboard(enum_dict
)
69 UpdateHistogramFromDict(
70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH
),