| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 ''' | 5 ''' |
| 6 Utility functions for working with the Feature abstraction. Features are grouped | 6 Utility functions for working with the Feature abstraction. Features are grouped |
| 7 into a dictionary by name. Each Feature is guaranteed to have the following two | 7 into a dictionary by name. Each Feature is guaranteed to have the following two |
| 8 keys: | 8 keys: |
| 9 name - a string, the name of the feature | 9 name - a string, the name of the feature |
| 10 platform - a list containing 'apps' or 'extensions', both, or neither. | 10 platform - a list containing 'apps' or 'extensions', both, or neither. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 extension_types = set() | 58 extension_types = set() |
| 59 for value in available_values: | 59 for value in available_values: |
| 60 extension_types.update(value['extension_types']) | 60 extension_types.update(value['extension_types']) |
| 61 value = [subvalue for subvalue in available_values | 61 value = [subvalue for subvalue in available_values |
| 62 if subvalue['channel'] == 'stable'][0] | 62 if subvalue['channel'] == 'stable'][0] |
| 63 value['extension_types'] = list(extension_types) | 63 value['extension_types'] = list(extension_types) |
| 64 | 64 |
| 65 if ignore_feature(name, value): | 65 if ignore_feature(name, value): |
| 66 continue | 66 continue |
| 67 | 67 |
| 68 features[name] = { 'platforms': [] } | 68 # Now we transform 'extension_types' into the more useful 'platforms'. |
| 69 # |
| 70 # But first, note that 'platforms' has a double meaning. In the docserver |
| 71 # model (what we're in the process of generating) it means 'apps' vs |
| 72 # 'extensions'. In the JSON features as read from Chrome it means 'win' vs |
| 73 # 'mac'. Ignore the latter. |
| 74 value.pop('platforms', None) |
| 75 extension_types = value.pop('extension_types', None) |
| 69 | 76 |
| 70 extension_types = value.pop('extension_types', None) | 77 platforms = [] |
| 71 if extension_types is not None: | 78 if extension_types is not None: |
| 72 features[name]['platforms'] = _GetPlatformsForExtensionTypes( | 79 platforms = _GetPlatformsForExtensionTypes(extension_types) |
| 73 extension_types) | |
| 74 | 80 |
| 75 features[name]['name'] = name | 81 features[name] = { |
| 82 'name': name, |
| 83 'platforms': platforms, |
| 84 } |
| 76 features[name].update(value) | 85 features[name].update(value) |
| 77 | 86 |
| 78 return features | 87 return features |
| 79 | 88 |
| 80 def Filtered(features, platform=None): | 89 def Filtered(features, platform=None): |
| 81 '''Create a new Features dictionary from |features| that contains only items | 90 '''Create a new Features dictionary from |features| that contains only items |
| 82 relevant to |platform|. Items retained are deepcopied. Returns new features | 91 relevant to |platform|. Items retained are deepcopied. Returns new features |
| 83 dictionary. | 92 dictionary. |
| 84 ''' | 93 ''' |
| 85 filtered_features = {} | 94 filtered_features = {} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 102 else: | 111 else: |
| 103 features[key] = value | 112 features[key] = value |
| 104 | 113 |
| 105 # Ensure the Feature schema is enforced for all added items. | 114 # Ensure the Feature schema is enforced for all added items. |
| 106 if not 'name' in features[key]: | 115 if not 'name' in features[key]: |
| 107 features[key]['name'] = key | 116 features[key]['name'] = key |
| 108 if not 'platforms' in features[key]: | 117 if not 'platforms' in features[key]: |
| 109 features[key]['platforms'] = [] | 118 features[key]['platforms'] = [] |
| 110 | 119 |
| 111 return features | 120 return features |
| OLD | NEW |