OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 """Scans the Chromium source of UseCounter, formats the Feature enum for | 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 | 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 | 8 snippet to put in uma.py of Chromium Dashboard. Make sure that you review the |
9 output for correctness. | 9 output for correctness. |
10 """ | 10 """ |
11 | 11 |
12 import optparse | 12 import optparse |
13 import os | 13 import os |
14 import re | 14 import re |
15 import sys | 15 import sys |
16 | 16 |
17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) | 17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
18 from update_histogram_enum import ReadHistogramValues | 18 import path_util |
19 from update_histogram_enum import UpdateHistogramFromDict | 19 |
20 from update_use_counter_feature_enum import PrintEnumForDashboard | 20 import update_histogram_enum |
| 21 import update_use_counter_feature_enum |
21 | 22 |
22 | 23 |
23 USE_COUNTER_CPP_PATH = \ | 24 USE_COUNTER_CPP_PATH = 'third_party/WebKit/Source/core/frame/UseCounter.cpp' |
24 '../../../third_party/WebKit/Source/core/frame/UseCounter.cpp' | |
25 | 25 |
26 | 26 |
27 def EnumToCssProperty(enum_name): | 27 def EnumToCssProperty(enum_name): |
28 """Converts a camel cased enum name to the lower case CSS property.""" | 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 | 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". | 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() | 31 return re.sub(r'([a-zA-Z])([A-Z])', r'\1-\2', enum_name).lower() |
32 | 32 |
33 | 33 |
34 def ReadCssProperties(filename): | 34 def ReadCssProperties(filename): |
35 # Read the file as a list of lines | 35 # Read the file as a list of lines |
36 with open(filename) as f: | 36 with open(path_util.GetInputFile(filename)) as f: |
37 content = f.readlines() | 37 content = f.readlines() |
38 | 38 |
39 # Looking for a line like "case CSSPropertyGrid: return 453;". | 39 # Looking for a line like "case CSSPropertyGrid: return 453;". |
40 ENUM_REGEX = re.compile(r"""CSSProperty(.*): # capture the enum name | 40 ENUM_REGEX = re.compile(r"""CSSProperty(.*): # capture the enum name |
41 \s*return\s* | 41 \s*return\s* |
42 ([0-9]+) # capture the id | 42 ([0-9]+) # capture the id |
43 """, re.VERBOSE) | 43 """, re.VERBOSE) |
44 | 44 |
45 properties = {} | 45 properties = {} |
46 for line in content: | 46 for line in content: |
(...skipping 10 matching lines...) Expand all Loading... |
57 parser = optparse.OptionParser() | 57 parser = optparse.OptionParser() |
58 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', | 58 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', |
59 default=False, | 59 default=False, |
60 help='Print enum definition formatted for use in uma.py of ' | 60 help='Print enum definition formatted for use in uma.py of ' |
61 'Chromium dashboard developed at ' | 61 'Chromium dashboard developed at ' |
62 'https://github.com/GoogleChrome/chromium-dashboard') | 62 'https://github.com/GoogleChrome/chromium-dashboard') |
63 options, args = parser.parse_args() | 63 options, args = parser.parse_args() |
64 | 64 |
65 if options.dashboard: | 65 if options.dashboard: |
66 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) | 66 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) |
67 PrintEnumForDashboard(enum_dict) | 67 update_use_counter_feature_enum.PrintEnumForDashboard(enum_dict) |
68 else: | 68 else: |
69 UpdateHistogramFromDict( | 69 update_histogram_enum.UpdateHistogramFromDict( |
70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), | 70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), |
71 USE_COUNTER_CPP_PATH) | 71 USE_COUNTER_CPP_PATH) |
OLD | NEW |