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..e2aa5ed7827d05b08a01ce1d0a40b2ff5e56cf92 100644 |
--- a/chrome/common/extensions/docs/server2/api_list_data_source.py |
+++ b/chrome/common/extensions/docs/server2/api_list_data_source.py |
@@ -6,6 +6,7 @@ import logging |
import os |
from file_system import FileNotFoundError |
+import file_system_cache as fs_cache |
import third_party.json_schema_compiler.model as model |
from docs_server_utils import SanitizeAPIName |
@@ -15,45 +16,55 @@ 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, fs_cache.LIST) |
+ 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, 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) |
@@ -62,4 +73,4 @@ class APIListDataSource(object): |
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)) |