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..cc150e5db95ddf21fe0e85c59ab726725cd80e95 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() |
+ |
+ def _GetApiFeatures(self): |
+ return self._features_bundle.GetAPIFeatures() |
def _CollectDocumentedAPIs(self, base_dir, files): |
def GetDocumentedAPIsForPlatform(names, platform): |
@@ -67,28 +76,68 @@ class APIListDataSource(object): |
'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') |
} |
+ def GetAllNames(self): |
not at google - send to devlin
2013/11/02 00:31:48
don't worry about these GetAllNames changes, I'm g
hukun
2013/11/04 11:07:26
OK
|
+ 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() |
+ api_features = self._GetApiFeatures() |
def FilterAPIs(platform): |
return (api for api in api_features.itervalues() |
not at google - send to devlin
2013/11/02 00:31:48
I think you could even just inline the whole of ap
hukun
2013/11/04 11:07:26
Done
|
if platform in api['platforms']) |
+ def GetChannelInfo(api_name): |
+ return self._availability_finder.GetApiAvailability(api_name) |
+ |
def MakeDictForPlatform(platform): |
- platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } |
+ platform_dict = { 'chrome': {'stable': [],'beta': [], |
+ 'dev': [],'trunk': [] }, |
+ 'experimental': {'stable': [],'beta': [], |
+ 'dev': [],'trunk': [] }} |
not at google - send to devlin
2013/11/02 00:31:48
Hm, so, how about we change the way this works.
-
hukun
2013/11/04 11:07:26
This is a little big change, I guess it will influ
not at google - send to devlin
2013/11/04 18:30:49
Sure.
|
+ private_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 |
+ if category == 'chrome' or category == 'experimental': |
not at google - send to devlin
2013/11/02 00:31:48
if category in ('chrome', 'experimental'):
though
hukun
2013/11/04 11:07:26
Do you mean put "private apis" here, then put "chr
not at google - send to devlin
2013/11/04 18:30:49
Yes
|
+ api_name = api['name'] |
+ all_apis.append(api) |
+ try: |
+ model = self._api_models.GetModel(api_name) |
+ api['description'] = model.Get().description |
not at google - send to devlin
2013/11/02 00:31:48
when is there not a model? there should always be
hukun
2013/11/04 11:07:26
For some private api, e.g. extension.sendNativeMes
not at google - send to devlin
2013/11/04 18:30:49
Ah right. Yes, I just fixed a bug for that in APIM
|
+ except FileNotFoundError: |
+ api['description'] = '' |
+ |
+ channel_info = GetChannelInfo(api_name) |
+ channel = channel_info.channel |
not at google - send to devlin
2013/11/02 00:31:48
inline this
hukun
2013/11/04 11:07:26
Done
|
+ if channel == 'stable': |
+ api['version'] = channel_info.version |
+ platform_dict[category][channel].append(api) |
+ elif category == 'private': |
+ private_apis.append(api) |
+ |
not at google - send to devlin
2013/11/02 00:31:48
extra blank line
hukun
2013/11/04 11:07:26
Done
|
+ |
+ for category, apis_by_channel in platform_dict.iteritems(): |
+ for channel, apis in apis_by_channel.iteritems(): |
+ if len(apis) == 0: |
+ platform_dict[category][channel] = None |
+ continue |
not at google - send to devlin
2013/11/02 00:31:48
why do you need this? an empty list would be simpl
hukun
2013/11/04 11:07:26
I used this to check if there is some data in temp
not at google - send to devlin
2013/11/04 18:30:49
{{?empty_list}} should be false (same as None/Fals
|
+ platform_dict[category][channel] = sorted(apis, |
+ key=itemgetter('name')) |
+ utils.MarkLast(platform_dict[category][channel]) |
+ |
+ all_apis = sorted(all_apis, key=itemgetter('name')) |
not at google - send to devlin
2013/11/02 00:31:48
extra space
hukun
2013/11/04 11:07:26
Done
|
+ platform_dict['all_apis'] = all_apis |
not at google - send to devlin
2013/11/02 00:31:48
you could do just all_apis.sort(key=itemgetter('na
hukun
2013/11/04 11:07:26
Done
|
+ |
+ private_apis = sorted(private_apis, key=itemgetter('name')) |
+ platform_dict['private'] = private_apis |
+ return platform_dict |
return { |
'apps': MakeDictForPlatform('apps'), |
- 'extensions': MakeDictForPlatform('extensions') |
+ 'extensions': MakeDictForPlatform('extensions'), |
} |
def Create(self): |
@@ -99,11 +148,11 @@ class APIListDataSource(object): |
self._object_store = object_store_creator.Create(APIListDataSource) |
def GetAllNames(self): |
not at google - send to devlin
2013/11/02 00:31:48
ditto. I'm going to delete this.
hukun
2013/11/04 11:07:26
OK
|
- 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() |