| 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 import histograms_path |
| 18 from update_histogram_enum import ReadHistogramValues | 18 import update_histogram_enum |
| 19 from update_histogram_enum import UpdateHistogramFromDict | 19 import update_use_counter_feature_enum |
| 20 from update_use_counter_feature_enum import PrintEnumForDashboard | |
| 21 | 20 |
| 22 | 21 |
| 23 USE_COUNTER_CPP_PATH = \ | 22 USE_COUNTER_CPP_PATH = 'third_party/WebKit/Source/core/frame/UseCounter.cpp' |
| 24 '../../../third_party/WebKit/Source/core/frame/UseCounter.cpp' | |
| 25 | 23 |
| 26 | 24 |
| 27 def EnumToCssProperty(enum_name): | 25 def EnumToCssProperty(enum_name): |
| 28 """Converts a camel cased enum name to the lower case CSS property.""" | 26 """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 | 27 # 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". | 28 # 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() | 29 return re.sub(r'([a-zA-Z])([A-Z])', r'\1-\2', enum_name).lower() |
| 32 | 30 |
| 33 | 31 |
| 34 def ReadCssProperties(filename): | 32 def ReadCssProperties(filename): |
| 35 # Read the file as a list of lines | 33 # Read the file as a list of lines |
| 36 with open(filename) as f: | 34 with open(histograms_path.GetInputFile(filename)) as f: |
| 37 content = f.readlines() | 35 content = f.readlines() |
| 38 | 36 |
| 39 # Looking for a line like "case CSSPropertyGrid: return 453;". | 37 # Looking for a line like "case CSSPropertyGrid: return 453;". |
| 40 ENUM_REGEX = re.compile(r"""CSSProperty(.*): # capture the enum name | 38 ENUM_REGEX = re.compile(r"""CSSProperty(.*): # capture the enum name |
| 41 \s*return\s* | 39 \s*return\s* |
| 42 ([0-9]+) # capture the id | 40 ([0-9]+) # capture the id |
| 43 """, re.VERBOSE) | 41 """, re.VERBOSE) |
| 44 | 42 |
| 45 properties = {} | 43 properties = {} |
| 46 for line in content: | 44 for line in content: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 parser = optparse.OptionParser() | 55 parser = optparse.OptionParser() |
| 58 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', | 56 parser.add_option('--for-dashboard', action='store_true', dest='dashboard', |
| 59 default=False, | 57 default=False, |
| 60 help='Print enum definition formatted for use in uma.py of ' | 58 help='Print enum definition formatted for use in uma.py of ' |
| 61 'Chromium dashboard developed at ' | 59 'Chromium dashboard developed at ' |
| 62 'https://github.com/GoogleChrome/chromium-dashboard') | 60 'https://github.com/GoogleChrome/chromium-dashboard') |
| 63 options, args = parser.parse_args() | 61 options, args = parser.parse_args() |
| 64 | 62 |
| 65 if options.dashboard: | 63 if options.dashboard: |
| 66 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) | 64 enum_dict = ReadCssProperties(USE_COUNTER_CPP_PATH) |
| 67 PrintEnumForDashboard(enum_dict) | 65 update_use_counter_feature_enum.PrintEnumForDashboard(enum_dict) |
| 68 else: | 66 else: |
| 69 UpdateHistogramFromDict( | 67 update_histogram_enum.UpdateHistogramFromDict( |
| 70 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), | 68 'MappedCSSProperties', ReadCssProperties(USE_COUNTER_CPP_PATH), |
| 71 USE_COUNTER_CPP_PATH) | 69 USE_COUNTER_CPP_PATH) |
| OLD | NEW |