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 c84a34b88c2b63fd12658f6dc58592f87cd2d39d..358c19ec488d667eff4b9cc91898afcc7cb1152d 100644 |
| --- a/chrome/common/extensions/docs/server2/api_list_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/api_list_data_source.py |
| @@ -5,9 +5,8 @@ |
| from operator import itemgetter |
| import os |
| -from third_party.json_schema_compiler.json_parse import Parse |
| -import third_party.json_schema_compiler.model as model |
| import docs_server_utils as utils |
| +from file_system import FileNotFoundError |
| def _GetAPICategory(api, documented_apis): |
| name = api['name'] |
| @@ -40,7 +39,9 @@ class APIListDataSource(object): |
| file_system, |
| public_template_path, |
| features_bundle, |
| - object_store_creator): |
| + object_store_creator, |
| + api_models, |
| + availability_finder): |
| self._file_system = file_system |
| def NormalizePath(string): |
| return string if string.endswith('/') else (string + '/') |
| @@ -50,6 +51,14 @@ class APIListDataSource(object): |
| 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() |
|
not at google - send to devlin
2013/11/05 01:02:02
there is an extra space after the "return" here.
hukun
2013/11/06 08:56:19
Done
|
| + |
| + def _GetApiFeatures(self): |
| + return self._features_bundle.GetAPIFeatures() |
| def _CollectDocumentedAPIs(self, base_dir, files): |
| def GetDocumentedAPIsForPlatform(names, platform): |
| @@ -67,28 +76,76 @@ class APIListDataSource(object): |
| 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') |
| } |
| + def GetAllNames(self): |
| + api_features = self._GetApiFeatures().itervalues() |
| + return [api['name'] for api in api_features] |
| + |
| def _GenerateAPIDict(self): |
| - documented_apis = self._cache.GetFromFileListing( |
| - self._public_template_path).Get() |
| - api_features = self._features_bundle.GetAPIFeatures() |
| + documented_apis = self._GetDocumentedApis() |
| def FilterAPIs(platform): |
| - return (api for api in api_features.itervalues() |
| + return (api for api |
| + in self._features_bundle.GetAPIFeatures().itervalues() |
| if platform in api['platforms']) |
| + def GetChannelInfo(api_name): |
| + return self._availability_finder.GetApiAvailability(api_name) |
| + |
| + def GetApiDescription(api_name): |
| + try: |
| + model = self._api_models.GetModel(api_name) |
| + return model.Get().description |
|
not at google - send to devlin
2013/11/05 01:02:02
likewise
hukun
2013/11/06 08:56:19
Done
|
| + except FileNotFoundError: |
| + return '' |
| + |
| def MakeDictForPlatform(platform): |
| - platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } |
| + platform_dict = { 'chrome': {'stable': [],'beta': [], |
| + 'dev': [],'trunk': [] }} |
|
not at google - send to devlin
2013/11/05 01:02:02
I would prefer this be formatted like:
platform_d
hukun
2013/11/06 08:56:19
Done
|
| + private_apis = [] |
| + experimental_apis = [] |
| + all_apis = [] |
| + |
| for api in FilterAPIs(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 |
| + api_name = api['name'] |
| + if category == 'chrome': |
| + all_apis.append(api) |
| + api['description'] = GetApiDescription(api_name) |
| + channel = GetChannelInfo(api_name).channel |
| + if channel == 'stable': |
| + api['version'] = GetChannelInfo(api_name).version |
|
not at google - send to devlin
2013/11/05 01:02:02
hold onto a reference to GetChannelInfo(api_name)
hukun
2013/11/06 08:56:19
Done
|
| + platform_dict[category][channel].append(api) |
| + elif category == 'experimental': |
| + api['description'] = GetApiDescription(api_name) |
|
not at google - send to devlin
2013/11/05 01:02:02
you might as well just always assign api['descript
hukun
2013/11/06 08:56:19
E.g. musicManagerPrivate will be None returned by
|
| + experimental_apis.append(api) |
| + all_apis.append(api) |
| + elif category == 'private': |
| + private_apis.append(api) |
| + |
| + for category, apis_by_channel in platform_dict.iteritems(): |
|
not at google - send to devlin
2013/11/05 01:02:02
the only key in platform_dict at this point is 'ch
hukun
2013/11/06 08:56:19
Done
|
| + for channel, apis in apis_by_channel.iteritems(): |
| + if len(apis) == 0: |
| + platform_dict[category][channel] = None |
| + continue |
| + platform_dict[category][channel] = sorted(apis, |
| + key=itemgetter('name')) |
| + utils.MarkLast(platform_dict[category][channel]) |
| + |
| + platform_dict.update({ |
| + 'all_apis': sorted(all_apis, key=itemgetter('name')), |
|
not at google - send to devlin
2013/11/05 01:02:02
just 'all'.
hukun
2013/11/06 08:56:19
Done
|
| + 'private': sorted(private_apis, |
| + key=itemgetter('name')), |
| + 'experimental': sorted(experimental_apis, |
| + key=itemgetter('name')), |
| + }) |
| + utils.MarkLast(platform_dict['all_apis']) |
| + utils.MarkLast(platform_dict['private']) |
| + utils.MarkLast(platform_dict['experimental']) |
|
not at google - send to devlin
2013/11/05 01:02:02
And come to think of it, you should be able to wri
hukun
2013/11/06 08:56:19
Done
|
| + return platform_dict |
| return { |
| 'apps': MakeDictForPlatform('apps'), |
| - 'extensions': MakeDictForPlatform('extensions') |
| + 'extensions': MakeDictForPlatform('extensions'), |
| } |
| def Create(self): |
| @@ -99,11 +156,11 @@ class APIListDataSource(object): |
| self._object_store = object_store_creator.Create(APIListDataSource) |
| def GetAllNames(self): |
| - apis = [] |
| - for platform in ['apps', 'extensions']: |
| - for category in ['chrome', 'experimental', 'private']: |
| - apis.extend(self.get(platform).get(category)) |
| - return [api['name'] for api in apis] |
| + data = self._object_store.Get('all_names').Get() |
| + if data is None: |
| + data = self._factory.GetAllNames() |
| + self._object_store.Set('all_names', data) |
| + return data |
| def _GetCachedAPIData(self): |
| data = self._object_store.Get('api_data').Get() |