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 """ |
(...skipping 18 matching lines...) Expand all Loading... | |
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(path_util.GetInputFile(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 pair of lines like "case CSSPropertyGrid:\n 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 previous_line = '' | |
46 for line in content: | 47 for line in content: |
47 enum_match = ENUM_REGEX.search(line) | 48 enum_match = ENUM_REGEX.search(previous_line + '\n' + line) |
48 if enum_match: | 49 if enum_match: |
49 enum_name = enum_match.group(1) | 50 enum_name = enum_match.group(1) |
50 property_id = int(enum_match.group(2)) | 51 property_id = int(enum_match.group(2)) |
51 properties[property_id] = EnumToCssProperty(enum_name) | 52 properties[property_id] = EnumToCssProperty(enum_name) |
53 previous_line = '' | |
54 else: | |
55 previous_line = line | |
Ilya Sherman
2016/12/08 04:52:33
Hmm, odd. Did the structure of the file recently
Eric Willigers
2016/12/08 05:03:56
clang-format was run across Blink on Sep 30:
1c8e1
Ilya Sherman
2016/12/08 05:04:33
Okay, that makes sense. Thanks!
| |
52 | 56 |
53 return properties | 57 return properties |
54 | 58 |
55 | 59 |
56 if __name__ == '__main__': | 60 if __name__ == '__main__': |
57 parser = optparse.OptionParser() | 61 parser = optparse.OptionParser() |
58 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', | 62 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', |
59 default=False, | 63 default=False, |
60 help='Print enum definition formatted for use in uma.py of ' | 64 help='Print enum definition formatted for use in uma.py of ' |
61 'Chromium dashboard developed at ' | 65 'Chromium dashboard developed at ' |
62 'https://github.com/GoogleChrome/chromium-dashboard') | 66 'https://github.com/GoogleChrome/chromium-dashboard') |
63 options, args = parser.parse_args() | 67 options, args = parser.parse_args() |
64 | 68 |
65 if options.dashboard: | 69 if options.dashboard: |
66 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) | 70 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) |
67 update_use_counter_feature_enum.PrintEnumForDashboard(enum_dict) | 71 update_use_counter_feature_enum.PrintEnumForDashboard(enum_dict) |
68 else: | 72 else: |
69 update_histogram_enum.UpdateHistogramFromDict( | 73 update_histogram_enum.UpdateHistogramFromDict( |
70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), | 74 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), |
71 USE_COUNTER_CPP_PATH) | 75 USE_COUNTER_CPP_PATH) |
OLD | NEW |