| 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 9f108aa46b309eb22b6eddf610238c4cd4b82d99..7c1c65a09f316723c9a74a5c79cde89cd136d5dd 100644
|
| --- a/chrome/common/extensions/docs/server2/api_list_data_source.py
|
| +++ b/chrome/common/extensions/docs/server2/api_list_data_source.py
|
| @@ -6,9 +6,11 @@ import logging
|
| import os
|
|
|
| from file_system import FileNotFoundError
|
| -import compiled_file_system as compiled_fs
|
| import third_party.json_schema_compiler.model as model
|
| -from docs_server_utils import SanitizeAPIName
|
| +import docs_server_utils as utils
|
| +
|
| +# Increment this if the data model changes for APIDataSource.
|
| +_VERSION = 1
|
|
|
| # These files are special cases that shouldn't be in the API list.
|
| IGNORED_FILES = [
|
| @@ -17,22 +19,29 @@ IGNORED_FILES = [
|
|
|
| class APIListDataSource(object):
|
| """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs
|
| - that are used in the api_index.html and experimental.html pages.
|
| + for extensions and apps that are used in the api_index.html and
|
| + experimental.html pages.
|
| + |api_path| is the path to the API schemas.
|
| + |public_path| is the path to the public HTML templates.
|
| + An API is considered listable if it's in both |api_path| and |public_path| -
|
| + the API schemas may contain undocumentable APIs, and the public HTML templates
|
| + will contain non-API articles.
|
| """
|
| class Factory(object):
|
| - def __init__(self, cache_factory, file_system, api_path, public_path):
|
| - self._cache = cache_factory.Create(self._ListAPIs, compiled_fs.LIST)
|
| - self._file_system = file_system
|
| + def __init__(self, compiled_fs_factory, api_path, public_path):
|
| + self._compiled_fs = compiled_fs_factory.Create(
|
| + self._ListAPIs, APIListDataSource, version=_VERSION)
|
| + self._identity_fs = compiled_fs_factory.GetOrCreateIdentity()
|
| 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]
|
| + public_templates = self._identity_fs.GetFromFileListing(
|
| + '%s%s/' % (self._public_path, doc_type))
|
| + template_names = set(os.path.splitext(name)[0]
|
| + for name in public_templates)
|
| experimental_apis = []
|
| chrome_apis = []
|
| for template_name in sorted(template_names):
|
| @@ -55,28 +64,28 @@ class APIListDataSource(object):
|
| }
|
|
|
| def _ListAPIs(self, base_dir, apis):
|
| - api_names = set(SanitizeAPIName(name, self._api_path) for name in apis)
|
| + api_names = set(utils.SanitizeAPIName(name) for name in apis)
|
| return {
|
| 'apps': self._GetAPIsInSubdirectory(api_names, 'apps'),
|
| 'extensions': self._GetAPIsInSubdirectory(api_names, 'extensions')
|
| }
|
|
|
| def Create(self):
|
| - return APIListDataSource(self._cache, self._api_path)
|
| + return APIListDataSource(self._compiled_fs, self._api_path)
|
|
|
| - def __init__(self, cache, api_path):
|
| - self._cache = cache
|
| + def __init__(self, compiled_fs, api_path):
|
| + self._compiled_fs = compiled_fs
|
| self._api_path = api_path
|
|
|
| def GetAllNames(self):
|
| names = []
|
| - for i in ['apps', 'extensions']:
|
| - for j in ['chrome', 'experimental']:
|
| - names.extend(self.get(i).get(j))
|
| + for platform in ['apps', 'extensions']:
|
| + for category in ['chrome', 'experimental']:
|
| + names.extend(self.get(platform).get(category))
|
| return [api_name['name'] for api_name in names]
|
|
|
| def get(self, key):
|
| try:
|
| - return self._cache.GetFromFileListing(self._api_path)[key]
|
| + return self._compiled_fs.GetFromFileListing(self._api_path)[key]
|
| except FileNotFoundError as e:
|
| raise ValueError('%s: Error listing files for "%s".' % (e, key))
|
|
|