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 import posixpath | 7 import posixpath |
| 8 | 8 |
| 9 from svn_constants import PUBLIC_TEMPLATE_PATH | 9 from svn_constants import PUBLIC_TEMPLATE_PATH |
| 10 import docs_server_utils as utils | 10 import docs_server_utils as utils |
| 11 from file_system import FileNotFoundError | |
| 12 from branch_utility import ChannelInfo | |
|
not at google - send to devlin
2013/11/10 01:39:57
sorting: branch_utility should go above svn_consta
hukun
2013/11/11 10:23:03
Done
| |
| 11 | 13 |
| 12 def _GetAPICategory(api, documented_apis): | 14 def _GetAPICategory(api, documented_apis): |
|
not at google - send to devlin
2013/11/10 01:39:57
(for comment below, change this to take api_name d
hukun
2013/11/11 10:23:03
Done
| |
| 13 name = api['name'] | 15 name = api['name'] |
| 14 if (name.endswith('Private') or | 16 if (name.endswith('Private') or |
| 15 name not in documented_apis): | 17 name not in documented_apis): |
| 16 return 'private' | 18 return 'private' |
| 17 if name.startswith('experimental.'): | 19 if name.startswith('experimental.'): |
| 18 return 'experimental' | 20 return 'experimental' |
| 19 return 'chrome' | 21 return 'chrome' |
| 20 | 22 |
| 21 | 23 |
| 22 class APIListDataSource(object): | 24 class APIListDataSource(object): |
| 23 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs | 25 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs |
| 24 for extensions and apps that are used in the api_index.html, | 26 for extensions and apps that are used in the api_index.html, |
| 25 experimental.html, and private_apis.html pages. | 27 experimental.html, and private_apis.html pages. |
| 26 | 28 |
| 27 An API is considered listable if it is listed in _api_features.json, | 29 An API is considered listable if it is listed in _api_features.json, |
| 28 it has a corresponding HTML file in the public template path, and one of | 30 it has a corresponding HTML file in the public template path, and one of |
| 29 the following conditions is met: | 31 the following conditions is met: |
| 30 - It has no "dependencies" or "extension_types" properties in _api_features | 32 - It has no "dependencies" or "extension_types" properties in _api_features |
| 31 - It has an "extension_types" property in _api_features with either/both | 33 - It has an "extension_types" property in _api_features with either/both |
| 32 "extension"/"platform_app" values present. | 34 "extension"/"platform_app" values present. |
| 33 - It has a dependency in _{api,manifest,permission}_features with an | 35 - It has a dependency in _{api,manifest,permission}_features with an |
| 34 "extension_types" property where either/both "extension"/"platform_app" | 36 "extension_types" property where either/both "extension"/"platform_app" |
| 35 values are present. | 37 values are present. |
| 36 """ | 38 """ |
| 37 class Factory(object): | 39 class Factory(object): |
| 38 def __init__(self, | 40 def __init__(self, |
| 39 compiled_fs_factory, | 41 compiled_fs_factory, |
| 40 file_system, | 42 file_system, |
| 41 features_bundle, | 43 features_bundle, |
| 42 object_store_creator): | 44 object_store_creator, |
| 45 api_models, | |
| 46 availability_finder): | |
| 43 self._file_system = file_system | 47 self._file_system = file_system |
| 44 self._cache = compiled_fs_factory.Create(file_system, | 48 self._cache = compiled_fs_factory.Create(file_system, |
| 45 self._CollectDocumentedAPIs, | 49 self._CollectDocumentedAPIs, |
| 46 APIListDataSource) | 50 APIListDataSource) |
| 47 self._features_bundle = features_bundle | 51 self._features_bundle = features_bundle |
| 48 self._object_store_creator = object_store_creator | 52 self._object_store_creator = object_store_creator |
| 53 self._api_models = api_models | |
| 54 self._availability_finder = availability_finder | |
| 55 | |
| 56 def _GetDocumentedApis(self): | |
| 57 return self._cache.GetFromFileListing(self._public_template_path).Get() | |
| 49 | 58 |
| 50 def _CollectDocumentedAPIs(self, base_dir, files): | 59 def _CollectDocumentedAPIs(self, base_dir, files): |
| 51 def GetDocumentedAPIsForPlatform(names, platform): | 60 def GetDocumentedAPIsForPlatform(names, platform): |
| 52 public_templates = [] | 61 public_templates = [] |
| 53 for root, _, files in self._file_system.Walk(posixpath.join( | 62 for root, _, files in self._file_system.Walk(posixpath.join( |
| 54 PUBLIC_TEMPLATE_PATH, platform)): | 63 PUBLIC_TEMPLATE_PATH, platform)): |
| 55 public_templates.extend( | 64 public_templates.extend( |
| 56 ('%s/%s' % (root, name)).lstrip('/') for name in files) | 65 ('%s/%s' % (root, name)).lstrip('/') for name in files) |
| 57 template_names = set(os.path.splitext(name)[0] | 66 template_names = set(os.path.splitext(name)[0] |
| 58 for name in public_templates) | 67 for name in public_templates) |
| 59 return [name.replace('_', '.') for name in template_names] | 68 return [name.replace('_', '.') for name in template_names] |
| 60 api_names = set(utils.SanitizeAPIName(name) for name in files) | 69 api_names = set(utils.SanitizeAPIName(name) for name in files) |
| 61 return { | 70 return { |
| 62 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), | 71 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), |
| 63 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') | 72 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') |
| 64 } | 73 } |
| 65 | 74 |
| 66 def _GenerateAPIDict(self): | 75 def _GenerateAPIDict(self): |
| 67 documented_apis = self._cache.GetFromFileListing( | 76 documented_apis = self._cache.GetFromFileListing( |
| 68 PUBLIC_TEMPLATE_PATH).Get() | 77 PUBLIC_TEMPLATE_PATH).Get() |
| 69 api_features = self._features_bundle.GetAPIFeatures().Get() | |
| 70 | 78 |
| 71 def FilterAPIs(platform): | 79 def FilterAPIs(platform): |
| 72 return (api for api in api_features.itervalues() | 80 return (api for api |
| 81 in self._features_bundle.GetAPIFeatures().Get().itervalues() | |
| 73 if platform in api['platforms']) | 82 if platform in api['platforms']) |
| 74 | 83 |
| 84 def GetChannelInfo(api_name): | |
| 85 return self._availability_finder.GetApiAvailability(api_name) | |
| 86 | |
| 87 def GetApiDescription(api_name): | |
| 88 try: | |
| 89 model = self._api_models.GetModel(api_name).Get() | |
| 90 return model.description if model else '' | |
| 91 except FileNotFoundError: | |
| 92 return '' | |
| 93 | |
| 75 def MakeDictForPlatform(platform): | 94 def MakeDictForPlatform(platform): |
| 76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } | 95 platform_dict = { |
| 96 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []} | |
| 97 } | |
| 98 private_apis = [] | |
| 99 experimental_apis = [] | |
| 100 all_apis = [] | |
| 101 | |
| 77 for api in FilterAPIs(platform): | 102 for api in FilterAPIs(platform): |
| 78 if api['name'] in documented_apis[platform]: | 103 category = _GetAPICategory(api, documented_apis[platform]) |
| 79 category = _GetAPICategory(api, documented_apis[platform]) | 104 api_name = api['name'] |
| 80 platform_dict[category].append(api) | 105 if api_name in self._api_models.GetNames(): |
|
not at google - send to devlin
2013/11/10 01:39:57
Instead of the above 4 lines, you can have
for ap
hukun
2013/11/11 10:23:03
Need some other properties, e.g. platform, depende
| |
| 81 for category, apis in platform_dict.iteritems(): | 106 api['description'] = GetApiDescription(api_name) |
| 82 platform_dict[category] = sorted(apis, key=itemgetter('name')) | 107 if category == 'chrome': |
| 83 utils.MarkLast(platform_dict[category]) | 108 channel_info = GetChannelInfo(api_name) |
| 109 channel = channel_info.channel | |
| 110 if channel == 'stable': | |
| 111 api['version'] = channel_info.version | |
| 112 platform_dict[category][channel].append(api) | |
| 113 all_apis.append(api) | |
| 114 elif category == 'experimental': | |
| 115 experimental_apis.append(api) | |
| 116 all_apis.append(api) | |
| 117 elif category == 'private': | |
| 118 private_apis.append(api) | |
| 119 | |
| 120 for channel, apis_by_channel in platform_dict['chrome'].iteritems(): | |
| 121 apis_by_channel = sorted(apis_by_channel, key=itemgetter('name')) | |
| 122 utils.MarkLast(apis_by_channel) | |
| 123 platform_dict['chrome'][channel] = apis_by_channel | |
| 124 | |
| 125 for key, apis in (('all', all_apis), | |
| 126 ('private', private_apis), | |
| 127 ('experimental', experimental_apis)): | |
| 128 apis = sorted(apis, key=itemgetter('name')) | |
| 129 utils.MarkLast(apis) | |
| 130 platform_dict[key] = apis | |
| 84 return platform_dict | 131 return platform_dict |
| 85 | |
| 86 return { | 132 return { |
| 87 'apps': MakeDictForPlatform('apps'), | 133 'apps': MakeDictForPlatform('apps'), |
| 88 'extensions': MakeDictForPlatform('extensions') | 134 'extensions': MakeDictForPlatform('extensions'), |
| 89 } | 135 } |
| 90 | 136 |
| 91 def Create(self): | 137 def Create(self): |
| 92 return APIListDataSource(self, self._object_store_creator) | 138 return APIListDataSource(self, self._object_store_creator) |
| 93 | 139 |
| 94 def __init__(self, factory, object_store_creator): | 140 def __init__(self, factory, object_store_creator): |
| 95 self._factory = factory | 141 self._factory = factory |
| 96 self._object_store = object_store_creator.Create(APIListDataSource) | 142 self._object_store = object_store_creator.Create(APIListDataSource) |
| 97 | 143 |
| 98 def _GetCachedAPIData(self): | 144 def _GetCachedAPIData(self): |
| 99 data = self._object_store.Get('api_data').Get() | 145 data = self._object_store.Get('api_data').Get() |
| 100 if data is None: | 146 if data is None: |
| 101 data = self._factory._GenerateAPIDict() | 147 data = self._factory._GenerateAPIDict() |
| 102 self._object_store.Set('api_data', data) | 148 self._object_store.Set('api_data', data) |
| 103 return data | 149 return data |
| 104 | 150 |
| 105 def get(self, key): | 151 def get(self, key): |
| 106 return self._GetCachedAPIData().get(key) | 152 return self._GetCachedAPIData().get(key) |
| OLD | NEW |