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 import json | 5 import json |
6 | 6 |
7 from data_source import DataSource | 7 from data_source import DataSource |
8 import features_utility | 8 import features_utility |
9 from future import Gettable, Future | 9 from future import Gettable, Future |
10 from manifest_features import ConvertDottedKeysToNested | 10 from manifest_features import ConvertDottedKeysToNested |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 elif example == '[]': | 49 elif example == '[]': |
50 value['example'] = '[...]' | 50 value['example'] = '[...]' |
51 elif example == '[{}]': | 51 elif example == '[{}]': |
52 value['example'] = '[{...}]' | 52 value['example'] = '[{...}]' |
53 else: | 53 else: |
54 coerce_example_to_feature(value) | 54 coerce_example_to_feature(value) |
55 if 'children' in value: | 55 if 'children' in value: |
56 features[key]['children'] = convert_and_sort(value['children']) | 56 features[key]['children'] = convert_and_sort(value['children']) |
57 return sorted(features.values(), key=sort_key) | 57 return sorted(features.values(), key=sort_key) |
58 | 58 |
59 # Replace {{title}} in the 'name' manifest property example with |app_name| | 59 # Replace {{platform}} in the 'name' manifest property example with |
| 60 # |app_name|, the convention that the normal template rendering uses. |
| 61 # TODO(kalman): Make the example a template and pass this through there. |
60 if 'name' in features: | 62 if 'name' in features: |
61 name = features['name'] | 63 name = features['name'] |
62 name['example'] = name['example'].replace('{{title}}', app_name) | 64 name['example'] = name['example'].replace('{{platform}}', app_name) |
63 | 65 |
64 features = convert_and_sort(features) | 66 features = convert_and_sort(features) |
65 | 67 |
66 return features | 68 return features |
67 | 69 |
68 def _AddLevelAnnotations(features): | 70 def _AddLevelAnnotations(features): |
69 '''Add level annotations to |features|. |features| and children lists must be | 71 '''Add level annotations to |features|. |features| and children lists must be |
70 sorted by 'level'. Annotations are added to the first item in a group of | 72 sorted by 'level'. Annotations are added to the first item in a group of |
71 features of the same 'level'. | 73 features of the same 'level'. |
72 | 74 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 self._object_store = server_instance.object_store_creator.Create( | 109 self._object_store = server_instance.object_store_creator.Create( |
108 ManifestDataSource) | 110 ManifestDataSource) |
109 | 111 |
110 def _CreateManifestData(self): | 112 def _CreateManifestData(self): |
111 future_manifest_features = self._features_bundle.GetManifestFeatures() | 113 future_manifest_features = self._features_bundle.GetManifestFeatures() |
112 def resolve(): | 114 def resolve(): |
113 manifest_features = future_manifest_features.Get() | 115 manifest_features = future_manifest_features.Get() |
114 def for_templates(manifest_features, platform): | 116 def for_templates(manifest_features, platform): |
115 return _AddLevelAnnotations(_ListifyAndSortDocs( | 117 return _AddLevelAnnotations(_ListifyAndSortDocs( |
116 ConvertDottedKeysToNested( | 118 ConvertDottedKeysToNested( |
117 features_utility.Filtered(manifest_features, platform)), | 119 features_utility.Filtered(manifest_features, platform + 's')), |
118 app_name=platform.capitalize())) | 120 app_name=platform.capitalize())) |
119 return { | 121 return { |
120 'apps': for_templates(manifest_features, 'apps'), | 122 'apps': for_templates(manifest_features, 'app'), |
121 'extensions': for_templates(manifest_features, 'extensions') | 123 'extensions': for_templates(manifest_features, 'extension') |
122 } | 124 } |
123 return Future(delegate=Gettable(resolve)) | 125 return Future(delegate=Gettable(resolve)) |
124 | 126 |
125 def _GetCachedManifestData(self): | 127 def _GetCachedManifestData(self): |
126 data = self._object_store.Get('manifest_data').Get() | 128 data = self._object_store.Get('manifest_data').Get() |
127 if data is None: | 129 if data is None: |
128 data = self._CreateManifestData().Get() | 130 data = self._CreateManifestData().Get() |
129 self._object_store.Set('manifest_data', data) | 131 self._object_store.Set('manifest_data', data) |
130 return data | 132 return data |
131 | 133 |
132 def Cron(self): | 134 def Cron(self): |
133 return self._CreateManifestData() | 135 return self._CreateManifestData() |
134 | 136 |
135 def get(self, key): | 137 def get(self, key): |
136 return self._GetCachedManifestData().get(key) | 138 return self._GetCachedManifestData().get(key) |
OLD | NEW |