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 manifest_features import CreateManifestFeatures, ConvertDottedKeysToNested | 9 from manifest_features import ConvertDottedKeysToNested |
10 from third_party.json_schema_compiler.json_parse import Parse | 10 from third_party.json_schema_compiler.json_parse import Parse |
11 | 11 |
12 def _ListifyAndSortDocs(features, app_name): | 12 def _ListifyAndSortDocs(features, app_name): |
13 '''Convert a |feautres| dictionary, and all 'children' dictionaries, into | 13 '''Convert a |feautres| dictionary, and all 'children' dictionaries, into |
14 lists recursively. Sort lists first by 'level' then by name. | 14 lists recursively. Sort lists first by 'level' then by name. |
15 ''' | 15 ''' |
16 def sort_key(item): | 16 def sort_key(item): |
17 '''Key function to sort items primarily by level (according to index into | 17 '''Key function to sort items primarily by level (according to index into |
18 levels) then subsort by name. | 18 levels) then subsort by name. |
19 ''' | 19 ''' |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 if features: | 93 if features: |
94 features[-1]['is_last'] = True | 94 features[-1]['is_last'] = True |
95 | 95 |
96 annotate('required', features) | 96 annotate('required', features) |
97 return features | 97 return features |
98 | 98 |
99 class ManifestDataSource(DataSource): | 99 class ManifestDataSource(DataSource): |
100 '''Provides access to the properties in manifest features. | 100 '''Provides access to the properties in manifest features. |
101 ''' | 101 ''' |
102 def __init__(self, server_instance, _): | 102 def __init__(self, server_instance, _): |
103 self._manifest_path = server_instance.manifest_json_path | 103 self._features_bundle = server_instance.features_bundle |
104 self._features_path = server_instance.manifest_features_path | 104 self._cache = None |
105 self._file_system = server_instance.host_file_system | |
106 self._cache = server_instance.compiled_host_fs_factory.Create( | |
107 self._CreateManifestData, ManifestDataSource) | |
108 | 105 |
109 def _CreateManifestData(self, _, content): | 106 def _CreateCache(self): |
110 '''Combine the contents of |_manifest_path| and |_features_path| and filter | |
111 the results into lists specific to apps or extensions for templates. Marks | |
112 up features with annotations. | |
113 ''' | |
114 def for_templates(manifest_features, platform): | 107 def for_templates(manifest_features, platform): |
115 return _AddLevelAnnotations( | 108 return _AddLevelAnnotations( |
116 _ListifyAndSortDocs( | 109 _ListifyAndSortDocs( |
117 ConvertDottedKeysToNested( | 110 ConvertDottedKeysToNested( |
118 features_utility.Filtered(manifest_features, platform)), | 111 features_utility.Filtered(manifest_features, platform)), |
119 app_name=platform.capitalize())) | 112 app_name=platform.capitalize())) |
120 | 113 manifest_features = self._features_bundle.GetManifestFeatures() |
121 manifest_json = Parse(self._file_system.ReadSingle(self._manifest_path)) | |
122 manifest_features = CreateManifestFeatures( | |
123 features_json=Parse(content), manifest_json=manifest_json) | |
124 | |
125 return { | 114 return { |
126 'apps': for_templates(manifest_features, 'app'), | 115 'apps': for_templates(manifest_features, 'apps'), |
127 'extensions': for_templates(manifest_features, 'extension') | 116 'extensions': for_templates(manifest_features, 'extensions') |
128 } | 117 } |
129 | 118 |
130 def Cron(self): | 119 def Cron(self): |
131 self._cache.GetFromFile(self._features_path) | 120 self._cache = self._CreateCache() |
132 self._file_system.ReadSingle(self._manifest_path) | |
133 | 121 |
134 def get(self, key): | 122 def get(self, key): |
135 return self._cache.GetFromFile(self._features_path)[key] | 123 if self._cache is None: |
124 self._cache = self._CreateCache() | |
125 return self._cache.get(key) | |
not at google - send to devlin
2013/10/01 16:34:34
you could also consider doing this with an ObjectS
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Done, minus fine-grained caching.
| |
OLD | NEW |