Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 operator import itemgetter | 5 from operator import itemgetter |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 from third_party.json_schema_compiler.json_parse import Parse | |
| 9 import third_party.json_schema_compiler.model as model | |
| 10 import docs_server_utils as utils | 8 import docs_server_utils as utils |
| 11 | 9 |
| 12 def _GetAPICategory(api, documented_apis): | 10 def _GetAPICategory(api, documented_apis): |
| 13 name = api['name'] | 11 name = api['name'] |
| 14 if (name.endswith('Private') or | 12 if (name.endswith('Private') or |
| 15 name not in documented_apis): | 13 name not in documented_apis): |
| 16 return 'private' | 14 return 'private' |
| 17 if name.startswith('experimental.'): | 15 if name.startswith('experimental.'): |
| 18 return 'experimental' | 16 return 'experimental' |
| 19 return 'chrome' | 17 return 'chrome' |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 33 - It has a dependency in _{api,manifest,permission}_features with an | 31 - It has a dependency in _{api,manifest,permission}_features with an |
| 34 "extension_types" property where either/both "extension"/"platform_app" | 32 "extension_types" property where either/both "extension"/"platform_app" |
| 35 values are present. | 33 values are present. |
| 36 """ | 34 """ |
| 37 class Factory(object): | 35 class Factory(object): |
| 38 def __init__(self, | 36 def __init__(self, |
| 39 compiled_fs_factory, | 37 compiled_fs_factory, |
| 40 file_system, | 38 file_system, |
| 41 public_template_path, | 39 public_template_path, |
| 42 features_bundle, | 40 features_bundle, |
| 43 object_store_creator): | 41 object_store_creator, |
| 42 api_data_source_factory, | |
|
not at google - send to devlin
2013/10/31 00:05:26
I don't want to introduce a dependency on api_data
hukun
2013/11/01 09:31:52
Done. Remove dependency of api_data_source_factory
| |
| 43 availability_finder): | |
| 44 self._file_system = file_system | 44 self._file_system = file_system |
| 45 def NormalizePath(string): | 45 def NormalizePath(string): |
| 46 return string if string.endswith('/') else (string + '/') | 46 return string if string.endswith('/') else (string + '/') |
| 47 self._public_template_path = NormalizePath(public_template_path) | 47 self._public_template_path = NormalizePath(public_template_path) |
| 48 self._cache = compiled_fs_factory.Create(file_system, | 48 self._cache = compiled_fs_factory.Create(file_system, |
| 49 self._CollectDocumentedAPIs, | 49 self._CollectDocumentedAPIs, |
| 50 APIListDataSource) | 50 APIListDataSource) |
| 51 self._features_bundle = features_bundle | 51 self._features_bundle = features_bundle |
| 52 self._object_store_creator = object_store_creator | 52 self._object_store_creator = object_store_creator |
| 53 self._api_data_source = api_data_source_factory.Create(None, | |
| 54 disable_refs=True) | |
| 55 self._availability_finder = availability_finder | |
| 56 self._cached_documented_apis = None | |
| 57 self._cachhed_api_features = None | |
|
not at google - send to devlin
2013/10/31 00:05:26
the places you get these from do their own caching
hukun
2013/11/01 09:31:52
Done.remove the cache.
| |
| 58 | |
| 59 def _GetDocumentedApis(self): | |
| 60 if (not self._cached_documented_apis): | |
| 61 self._cached_documented_apis = self._cache.GetFromFileListing( | |
| 62 self._public_template_path).Get() | |
| 63 return self._cached_documented_apis | |
| 64 | |
| 65 def _GetApiFeatures(self): | |
| 66 if (not self._cachhed_api_features) : | |
| 67 self._cachhed_api_features = self._features_bundle.GetAPIFeatures() | |
| 68 return self._cachhed_api_features | |
| 53 | 69 |
| 54 def _CollectDocumentedAPIs(self, base_dir, files): | 70 def _CollectDocumentedAPIs(self, base_dir, files): |
| 55 def GetDocumentedAPIsForPlatform(names, platform): | 71 def GetDocumentedAPIsForPlatform(names, platform): |
| 56 public_templates = [] | 72 public_templates = [] |
| 57 for root, _, files in self._file_system.Walk( | 73 for root, _, files in self._file_system.Walk( |
| 58 self._public_template_path + platform): | 74 self._public_template_path + platform): |
| 59 public_templates.extend( | 75 public_templates.extend( |
| 60 ('%s/%s' % (root, name)).lstrip('/') for name in files) | 76 ('%s/%s' % (root, name)).lstrip('/') for name in files) |
| 61 template_names = set(os.path.splitext(name)[0] | 77 template_names = set(os.path.splitext(name)[0] |
| 62 for name in public_templates) | 78 for name in public_templates) |
| 63 return [name.replace('_', '.') for name in template_names] | 79 return [name.replace('_', '.') for name in template_names] |
| 64 api_names = set(utils.SanitizeAPIName(name) for name in files) | 80 api_names = set(utils.SanitizeAPIName(name) for name in files) |
| 65 return { | 81 return { |
| 66 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), | 82 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), |
| 67 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') | 83 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') |
| 68 } | 84 } |
| 69 | 85 |
| 86 def GetAllNames(self): | |
| 87 api_features = self._GetApiFeatures().itervalues() | |
| 88 return [api['name'] for api in api_features] | |
| 89 | |
| 70 def _GenerateAPIDict(self): | 90 def _GenerateAPIDict(self): |
| 71 documented_apis = self._cache.GetFromFileListing( | 91 documented_apis = self._GetDocumentedApis() |
| 72 self._public_template_path).Get() | 92 api_features = self._GetApiFeatures() |
| 73 api_features = self._features_bundle.GetAPIFeatures() | |
| 74 | 93 |
| 75 def FilterAPIs(platform): | 94 def FilterAPIs(platform): |
| 76 return (api for api in api_features.itervalues() | 95 return (api for api in api_features.itervalues() |
| 77 if platform in api['platforms']) | 96 if platform in api['platforms']) |
| 78 | 97 |
| 79 def MakeDictForPlatform(platform): | 98 def MakeDictForPlatform(platform): |
| 80 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } | 99 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } |
| 81 for api in FilterAPIs(platform): | 100 for api in FilterAPIs(platform): |
| 82 category = _GetAPICategory(api, documented_apis[platform]) | 101 category = _GetAPICategory(api, documented_apis[platform]) |
| 83 platform_dict[category].append(api) | 102 platform_dict[category].append(api) |
| 84 for category, apis in platform_dict.iteritems(): | 103 for category, apis in platform_dict.iteritems(): |
| 85 platform_dict[category] = sorted(apis, key=itemgetter('name')) | 104 platform_dict[category] = sorted(apis, key=itemgetter('name')) |
| 86 utils.MarkLast(platform_dict[category]) | 105 utils.MarkLast(platform_dict[category]) |
| 87 return platform_dict | 106 return platform_dict |
| 88 | 107 |
| 108 def MakeDictForChannel(dict_for_platform, availability_finder, | |
| 109 api_data_source): | |
|
not at google - send to devlin
2013/10/31 00:05:26
this should still [be able to be arranged to] have
hukun
2013/11/01 09:31:52
Done. Use self' point directly.
| |
| 110 platform_list = [ 'chrome', 'experimental'] | |
| 111 | |
| 112 for platform in platform_list: | |
| 113 platform_dict = dict_for_platform[platform] | |
| 114 channel_dict = { 'stable': [], 'beta': [], 'dev': [], 'trunk': [] } | |
| 115 for api in platform_dict: | |
| 116 api_name = api['name'] | |
| 117 description_list = api_data_source.get(api_name)["introList"]; | |
| 118 for description in description_list: | |
| 119 if description["title"] == 'Description': | |
| 120 api['description'] = description['content'][0]['text'] | |
| 121 break | |
| 122 channel_info = availability_finder.GetApiAvailability(api_name) | |
| 123 channel = channel_info.channel | |
| 124 if channel == 'stable': | |
| 125 api['version'] = channel_info.version | |
| 126 channel_dict[channel].append(api) | |
| 127 | |
|
not at google - send to devlin
2013/10/31 00:05:26
I'm finding this sa bit hard to follow, can you br
hukun
2013/11/01 09:31:52
Done. Remove my func.
| |
| 128 for channel, apis in channel_dict.iteritems(): | |
| 129 channel_dict[channel] = sorted(apis, key=itemgetter('name')) | |
| 130 utils.MarkLast(channel_dict[channel]) | |
| 131 dict_for_platform[platform] = channel_dict | |
| 132 return dict_for_platform | |
| 133 | |
| 89 return { | 134 return { |
| 90 'apps': MakeDictForPlatform('apps'), | 135 'apps': MakeDictForChannel(MakeDictForPlatform('apps'), |
|
not at google - send to devlin
2013/10/31 00:05:26
MakeDictForPlatform('apps') here was right. MakeDi
hukun
2013/11/01 09:31:52
Done. Still use MakeDictForPlatform
| |
| 91 'extensions': MakeDictForPlatform('extensions') | 136 self._availability_finder, |
| 137 self._api_data_source), | |
| 138 'extensions': MakeDictForChannel(MakeDictForPlatform('extensions'), | |
| 139 self._availability_finder, | |
| 140 self._api_data_source) | |
| 92 } | 141 } |
| 93 | 142 |
| 94 def Create(self): | 143 def Create(self): |
| 95 return APIListDataSource(self, self._object_store_creator) | 144 return APIListDataSource(self, self._object_store_creator) |
| 96 | 145 |
| 97 def __init__(self, factory, object_store_creator): | 146 def __init__(self, factory, object_store_creator): |
| 98 self._factory = factory | 147 self._factory = factory |
| 99 self._object_store = object_store_creator.Create(APIListDataSource) | 148 self._object_store = object_store_creator.Create(APIListDataSource) |
| 100 | 149 |
| 101 def GetAllNames(self): | 150 def GetAllNames(self): |
| 102 apis = [] | 151 data = self._object_store.Get('all_names').Get() |
| 103 for platform in ['apps', 'extensions']: | 152 if data is None: |
| 104 for category in ['chrome', 'experimental', 'private']: | 153 data = self._factory.GetAllNames() |
| 105 apis.extend(self.get(platform).get(category)) | 154 self._object_store.Set('all_names', data) |
| 106 return [api['name'] for api in apis] | 155 return data |
| 107 | 156 |
| 108 def _GetCachedAPIData(self): | 157 def _GetCachedAPIData(self): |
| 109 data = self._object_store.Get('api_data').Get() | 158 data = self._object_store.Get('api_data').Get() |
| 110 if data is None: | 159 if data is None: |
| 111 data = self._factory._GenerateAPIDict() | 160 data = self._factory._GenerateAPIDict() |
| 112 self._object_store.Set('api_data', data) | 161 self._object_store.Set('api_data', data) |
| 113 return data | 162 return data |
| 114 | 163 |
| 115 def get(self, key): | 164 def get(self, key): |
| 116 return self._GetCachedAPIData().get(key) | 165 return self._GetCachedAPIData().get(key) |
| OLD | NEW |