| 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 8d00f6652f85647264d06e885a79cf72b6a886b9..484122c62ece9d84f1626ecb26b3de1a1eb425bd 100644
|
| --- a/chrome/common/extensions/docs/server2/api_list_data_source.py
|
| +++ b/chrome/common/extensions/docs/server2/api_list_data_source.py
|
| @@ -4,6 +4,7 @@
|
|
|
| import logging
|
| import os
|
| +import time
|
|
|
| from file_system import FileNotFoundError
|
| import third_party.json_schema_compiler.model as model
|
| @@ -15,51 +16,68 @@ IGNORED_FILES = [
|
| ]
|
|
|
| class APIListDataSource(object):
|
| + class Factory(object):
|
| + def __init__(self, cache_builder, file_system, api_path, public_path):
|
| + self._cache = cache_builder.build(self._ListAPIs)
|
| + self._file_system = file_system
|
| + def Normalize(string):
|
| + return string if string.endswith('/') else (string + '/')
|
| + self._api_path = Normalize(api_path)
|
| + self._public_path = Normalize(public_path)
|
| +
|
| + def _GetAPIsInSubdirectory(self, api_names, doc_type):
|
| + public_templates = self._file_system.ReadSingle(
|
| + self._public_path + doc_type + '/')
|
| + template_names = [os.path.splitext(name)[0]
|
| + for name in public_templates]
|
| + experimental_apis = []
|
| + chrome_apis = []
|
| + for template_name in sorted(template_names):
|
| + if template_name in IGNORED_FILES:
|
| + continue
|
| + if model.UnixName(template_name) in api_names:
|
| + if template_name.startswith('experimental'):
|
| + experimental_apis.append({
|
| + 'name': template_name.replace('_', '.')
|
| + })
|
| + else:
|
| + chrome_apis.append({ 'name': template_name.replace('_', '.') })
|
| + chrome_apis[-1]['last'] = True
|
| + experimental_apis[-1]['last'] = True
|
| + return {
|
| + 'chrome': chrome_apis,
|
| + 'experimental': experimental_apis
|
| + }
|
| +
|
| + def _ListAPIs(self, apis):
|
| + api_names = set(SanitizeAPIName(name, self._api_path) for name in apis)
|
| + return {
|
| + 'apps': self._GetAPIsInSubdirectory(api_names, 'apps'),
|
| + 'extensions': self._GetAPIsInSubdirectory(api_names, 'extensions')
|
| + }
|
| +
|
| + def Create(self):
|
| + return APIListDataSource(self._cache.ScopeToRequest(), self._api_path)
|
| +
|
| """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs
|
| that are used in the api_index.html and experimental.html pages.
|
| """
|
| - def __init__(self, cache_builder, file_system, api_path, public_path):
|
| - self._cache = cache_builder.build(self._ListAPIs)
|
| - self._file_system = file_system
|
| - self._api_path = api_path + '/'
|
| - self._public_path = public_path + '/'
|
| -
|
| - def _GetAPIsInSubdirectory(self, api_names, doc_type):
|
| - public_templates = self._file_system.ReadSingle(
|
| - self._public_path + doc_type + '/')
|
| - template_names = [os.path.splitext(name)[0]
|
| - for name in public_templates]
|
| - experimental_apis = []
|
| - chrome_apis = []
|
| - for template_name in sorted(template_names):
|
| - if template_name in IGNORED_FILES:
|
| - continue
|
| - if model.UnixName(template_name) in api_names:
|
| - if template_name.startswith('experimental'):
|
| - experimental_apis.append({
|
| - 'name': template_name.replace('_', '.')
|
| - })
|
| - else:
|
| - chrome_apis.append({ 'name': template_name.replace('_', '.') })
|
| - chrome_apis[-1]['last'] = True
|
| - experimental_apis[-1]['last'] = True
|
| - return {
|
| - 'chrome': chrome_apis,
|
| - 'experimental': experimental_apis
|
| - }
|
| -
|
| - def _ListAPIs(self, apis):
|
| - api_names = set(SanitizeAPIName(name, self._api_path) for name in apis)
|
| - return {
|
| - 'apps': self._GetAPIsInSubdirectory(api_names, 'apps'),
|
| - 'extensions': self._GetAPIsInSubdirectory(api_names, 'extensions')
|
| - }
|
| + def __init__(self, cache, api_path):
|
| + self._cache = cache
|
| + self._api_path = api_path
|
|
|
| def __getitem__(self, key):
|
| return self.get(key)
|
|
|
| def get(self, key):
|
| + start_time = time.time()
|
| + try:
|
| + return self._do_get(key)
|
| + finally:
|
| + logging.info("ApiListDataSource: %sms", (time.time() - start_time) * 1000)
|
| +
|
| + def _do_get(self, key):
|
| try:
|
| return self._cache.GetFromFileListing(self._api_path)[key]
|
| except FileNotFoundError as e:
|
| - raise ValueError(str(e) + ': Error listing files for "%s".' % key)
|
| + raise ValueError('%s: Error listing files for "%s".' % (e, key))
|
|
|