Revert of Remove OneClickSigninHelper since it is no longer used. (patchset #5 id...
[chromium-blink-merge.git] / tools / metrics / histograms / update_use_counter_css.py
blobd95e259c4bb36b17197a19e140d879823997fb4d
1 #!/usr/bin/env python
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.
10 """
12 import optparse
13 import os
14 import re
15 import sys
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
41 \s*return\s*
42 ([0-9]+) # capture the id
43 """, re.VERBOSE)
45 properties = {}
46 for line in content:
47 enum_match = ENUM_REGEX.search(line)
48 if enum_match:
49 enum_name = enum_match.group(1)
50 property_id = int(enum_match.group(2))
51 properties[property_id] = EnumToCssProperty(enum_name)
53 return properties
56 if __name__ == '__main__':
57 parser = optparse.OptionParser()
58 parser.add_option('--for-dashboard', action='store_true', dest='dashboard',
59 default=False,
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()
65 if options.dashboard:
66 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH)
67 PrintEnumForDashboard(enum_dict)
68 else:
69 UpdateHistogramFromDict(
70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH),
71 USE_COUNTER_CPP_PATH)