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 from copy import deepcopy | 5 from copy import deepcopy |
6 import json | 6 import json |
7 | 7 |
8 from data_source import DataSource | 8 from data_source import DataSource |
9 from features_utility import Filtered | |
10 from future import Future | 9 from future import Future |
11 from manifest_features import ConvertDottedKeysToNested | 10 from manifest_features import ConvertDottedKeysToNested |
| 11 from platform_util import GetPlatforms, PluralToSingular |
| 12 |
12 | 13 |
13 def _ListifyAndSortDocs(features, app_name): | 14 def _ListifyAndSortDocs(features, app_name): |
14 '''Convert a |feautres| dictionary, and all 'children' dictionaries, into | 15 '''Convert a |feautres| dictionary, and all 'children' dictionaries, into |
15 lists recursively. Sort lists first by 'level' then by name. | 16 lists recursively. Sort lists first by 'level' then by name. |
16 ''' | 17 ''' |
17 def sort_key(item): | 18 def sort_key(item): |
18 '''Key function to sort items primarily by level (according to index into | 19 '''Key function to sort items primarily by level (according to index into |
19 levels) then subsort by name. | 20 levels) then subsort by name. |
20 ''' | 21 ''' |
21 levels = ('required', 'recommended', 'only_one', 'optional') | 22 levels = ('required', 'recommended', 'only_one', 'optional') |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if features: | 99 if features: |
99 features[-1]['is_last'] = True | 100 features[-1]['is_last'] = True |
100 | 101 |
101 annotate('required', features) | 102 annotate('required', features) |
102 return features | 103 return features |
103 | 104 |
104 class ManifestDataSource(DataSource): | 105 class ManifestDataSource(DataSource): |
105 '''Provides access to the properties in manifest features. | 106 '''Provides access to the properties in manifest features. |
106 ''' | 107 ''' |
107 def __init__(self, server_instance, _): | 108 def __init__(self, server_instance, _): |
108 self._features_bundle = server_instance.features_bundle | 109 self._platform_bundle = server_instance.platform_bundle |
109 self._object_store = server_instance.object_store_creator.Create( | 110 self._object_store = server_instance.object_store_creator.Create( |
110 ManifestDataSource) | 111 ManifestDataSource) |
111 | 112 |
112 def _CreateManifestData(self): | 113 def _CreateManifestDataForPlatform(self, platform): |
113 future_manifest_features = self._features_bundle.GetManifestFeatures() | 114 future_manifest_features = self._platform_bundle.GetFeaturesBundle( |
| 115 platform).GetManifestFeatures() |
114 def resolve(): | 116 def resolve(): |
115 manifest_features = future_manifest_features.Get() | 117 manifest_features = future_manifest_features.Get() |
116 def for_templates(manifest_features, platform): | 118 return _AddLevelAnnotations(_ListifyAndSortDocs( |
117 return _AddLevelAnnotations(_ListifyAndSortDocs( | 119 ConvertDottedKeysToNested(deepcopy(manifest_features)), |
118 ConvertDottedKeysToNested( | 120 app_name=PluralToSingular(platform).capitalize())) |
119 deepcopy(Filtered(manifest_features, platform + 's'))), | 121 return Future(callback=resolve) |
120 app_name=platform.capitalize())) | 122 |
121 return { | 123 def _CreateManifestData(self): |
122 'apps': for_templates(manifest_features, 'app'), | 124 manifest_data_futures = dict((p, self._CreateManifestDataForPlatform(p)) |
123 'extensions': for_templates(manifest_features, 'extension') | 125 for p in GetPlatforms()) |
124 } | 126 def resolve(): |
| 127 return dict((platform, future.Get()) |
| 128 for platform, future in manifest_data_futures.iteritems()) |
125 return Future(callback=resolve) | 129 return Future(callback=resolve) |
126 | 130 |
127 def _GetCachedManifestData(self): | 131 def _GetCachedManifestData(self): |
128 data = self._object_store.Get('manifest_data').Get() | 132 data = self._object_store.Get('manifest_data').Get() |
129 if data is None: | 133 if data is None: |
130 data = self._CreateManifestData().Get() | 134 data = self._CreateManifestData().Get() |
131 self._object_store.Set('manifest_data', data) | 135 self._object_store.Set('manifest_data', data) |
132 return data | 136 return data |
133 | 137 |
134 def Cron(self): | 138 def Cron(self): |
135 return self._CreateManifestData() | 139 return self._CreateManifestData() |
136 | 140 |
137 def get(self, key): | 141 def get(self, key): |
138 return self._GetCachedManifestData().get(key) | 142 return self._GetCachedManifestData().get(key) |
OLD | NEW |