Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/api_list_data_source.py |
| diff --git a/chrome/common/extensions/docs/server2/api_list_data_source.py b/chrome/common/extensions/docs/server2/api_list_data_source.py |
| index 59f62d1549e00c8c578dec26e90a0a8f3bc2d137..e517960cb4655531bdd8a7dce8fa9fddf25c6020 100644 |
| --- a/chrome/common/extensions/docs/server2/api_list_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/api_list_data_source.py |
| @@ -6,15 +6,16 @@ from operator import itemgetter |
| import os |
| import posixpath |
| +from branch_utility import ChannelInfo |
| from svn_constants import PUBLIC_TEMPLATE_PATH |
| import docs_server_utils as utils |
| +from file_system import FileNotFoundError |
| -def _GetAPICategory(api, documented_apis): |
| - name = api['name'] |
| - if (name.endswith('Private') or |
| - name not in documented_apis): |
| +def _GetAPICategory(api_name, documented_apis): |
| + if (api_name.endswith('Private') or |
| + api_name not in documented_apis): |
| return 'private' |
| - if name.startswith('experimental.'): |
| + if api_name.startswith('experimental.'): |
| return 'experimental' |
| return 'chrome' |
| @@ -39,13 +40,20 @@ class APIListDataSource(object): |
| compiled_fs_factory, |
| file_system, |
| features_bundle, |
| - object_store_creator): |
| + object_store_creator, |
| + api_models, |
| + availability_finder): |
| self._file_system = file_system |
| self._cache = compiled_fs_factory.Create(file_system, |
| self._CollectDocumentedAPIs, |
| APIListDataSource) |
| self._features_bundle = features_bundle |
| self._object_store_creator = object_store_creator |
| + self._api_models = api_models |
| + self._availability_finder = availability_finder |
| + |
| + def _GetDocumentedApis(self): |
| + return self._cache.GetFromFileListing(self._public_template_path).Get() |
| def _CollectDocumentedAPIs(self, base_dir, files): |
| def GetDocumentedAPIsForPlatform(names, platform): |
| @@ -66,26 +74,60 @@ class APIListDataSource(object): |
| def _GenerateAPIDict(self): |
| documented_apis = self._cache.GetFromFileListing( |
| PUBLIC_TEMPLATE_PATH).Get() |
| - api_features = self._features_bundle.GetAPIFeatures().Get() |
| - def FilterAPIs(platform): |
| - return (api for api in api_features.itervalues() |
| - if platform in api['platforms']) |
| + def GetChannelInfo(api_name): |
| + return self._availability_finder.GetApiAvailability(api_name) |
| + |
| + def GetApiDescription(model): |
| + try: |
| + return model.Get().description if model.Get() else '' |
| + except FileNotFoundError: |
| + return '' |
| + |
| + def GetApiPlatform(api_name): |
| + feature = self._features_bundle.GetAPIFeatures().Get()[api_name] |
| + return feature['platforms'] |
| def MakeDictForPlatform(platform): |
| - platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } |
| - for api in FilterAPIs(platform): |
| - if api['name'] in documented_apis[platform]: |
| - category = _GetAPICategory(api, documented_apis[platform]) |
| - platform_dict[category].append(api) |
| - for category, apis in platform_dict.iteritems(): |
| - platform_dict[category] = sorted(apis, key=itemgetter('name')) |
| - utils.MarkLast(platform_dict[category]) |
| - return platform_dict |
| + platform_dict = { |
| + 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []} |
| + } |
| + private_apis = [] |
| + experimental_apis = [] |
| + all_apis = [] |
| + for api_name, api_model in self._api_models.IterModels(): |
| + api = {'name': api_name} |
| + api['description'] = GetApiDescription(api_model) |
| + api['platforms'] = GetApiPlatform(api_name) |
|
not at google - send to devlin
2013/11/13 17:43:30
you can write this slightly nicer like
api = {
hukun
2013/11/13 18:04:00
Done
|
| + category = _GetAPICategory(api_name, documented_apis[platform]) |
| + if category == 'chrome': |
| + channel_info = GetChannelInfo(api_name) |
| + channel = channel_info.channel |
| + if channel == 'stable': |
| + api['version'] = channel_info.version |
| + platform_dict[category][channel].append(api) |
| + all_apis.append(api) |
| + elif category == 'experimental': |
| + experimental_apis.append(api) |
| + all_apis.append(api) |
| + elif category == 'private': |
| + private_apis.append(api) |
| + |
| + for channel, apis_by_channel in platform_dict['chrome'].iteritems(): |
| + apis_by_channel = sorted(apis_by_channel, key=itemgetter('name')) |
| + utils.MarkLast(apis_by_channel) |
| + platform_dict['chrome'][channel] = apis_by_channel |
| + for key, apis in (('all', all_apis), |
| + ('private', private_apis), |
| + ('experimental', experimental_apis)): |
| + apis = sorted(apis, key=itemgetter('name')) |
| + utils.MarkLast(apis) |
| + platform_dict[key] = apis |
| + return platform_dict |
| return { |
| 'apps': MakeDictForPlatform('apps'), |
| - 'extensions': MakeDictForPlatform('extensions') |
| + 'extensions': MakeDictForPlatform('extensions'), |
| } |
| def Create(self): |