Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 import third_party.json_schema_compiler.model as model | 8 import third_party.json_schema_compiler.model as model |
| 9 import docs_server_utils as utils | 9 import docs_server_utils as utils |
| 10 | 10 |
| 11 # Increment this if the data model changes for APIDataSource. | |
| 12 _VERSION = 1 | |
| 13 | |
| 14 # These files are special cases that shouldn't be in the API list. | |
| 15 IGNORED_FILES = [ | |
| 16 'devtools' | |
| 17 ] | |
|
not at google - send to devlin
2013/04/22 16:43:37
devtools got deleted a while ago, cleanup
| |
| 18 | |
| 19 class APIListDataSource(object): | 11 class APIListDataSource(object): |
| 20 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs | 12 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs |
| 21 for extensions and apps that are used in the api_index.html and | 13 for extensions and apps that are used in the api_index.html and |
| 22 experimental.html pages. | 14 experimental.html pages. |
| 23 |api_path| is the path to the API schemas. | 15 |api_path| is the path to the API schemas. |
| 24 |public_path| is the path to the public HTML templates. | 16 |public_path| is the path to the public HTML templates. |
| 25 An API is considered listable if it's in both |api_path| and |public_path| - | 17 An API is considered listable if it's in both |api_path| and |public_path| - |
| 26 the API schemas may contain undocumentable APIs, and the public HTML templates | 18 the API schemas may contain undocumentable APIs, and the public HTML templates |
| 27 will contain non-API articles. | 19 will contain non-API articles. |
| 28 """ | 20 """ |
| 29 class Factory(object): | 21 class Factory(object): |
| 30 def __init__(self, compiled_fs_factory, api_path, public_path): | 22 def __init__(self, compiled_fs_factory, api_path, public_path): |
| 31 self._compiled_fs = compiled_fs_factory.Create( | 23 self._compiled_fs = compiled_fs_factory.Create(self._ListAPIs, |
| 32 self._ListAPIs, APIListDataSource, version=_VERSION) | 24 APIListDataSource) |
| 33 self._identity_fs = compiled_fs_factory.GetOrCreateIdentity() | 25 self._identity_fs = compiled_fs_factory.GetOrCreateIdentity() |
| 34 def Normalize(string): | 26 def Normalize(string): |
| 35 return string if string.endswith('/') else (string + '/') | 27 return string if string.endswith('/') else (string + '/') |
| 36 self._api_path = Normalize(api_path) | 28 self._api_path = Normalize(api_path) |
| 37 self._public_path = Normalize(public_path) | 29 self._public_path = Normalize(public_path) |
| 38 | 30 |
| 39 def _GetAPIsInSubdirectory(self, api_names, doc_type): | 31 def _GetAPIsInSubdirectory(self, api_names, doc_type): |
| 40 public_templates = self._identity_fs.GetFromFileListing( | 32 public_templates = self._identity_fs.GetFromFileListing( |
| 41 '%s%s/' % (self._public_path, doc_type)) | 33 '%s%s/' % (self._public_path, doc_type)) |
| 42 template_names = set(os.path.splitext(name)[0] | 34 template_names = set(os.path.splitext(name)[0] |
| 43 for name in public_templates) | 35 for name in public_templates) |
| 44 experimental_apis = [] | 36 experimental_apis = [] |
| 45 chrome_apis = [] | 37 chrome_apis = [] |
| 46 for template_name in sorted(template_names): | 38 for template_name in sorted(template_names): |
| 47 if template_name in IGNORED_FILES: | 39 if model.UnixName(template_name) not in api_names: |
| 48 continue | 40 continue |
| 49 if model.UnixName(template_name) in api_names: | 41 entry = {'name': template_name.replace('_', '.')} |
| 50 if template_name.startswith('experimental'): | 42 if template_name.startswith('experimental'): |
| 51 experimental_apis.append({ | 43 experimental_apis.append(entry) |
| 52 'name': template_name.replace('_', '.') | 44 else: |
| 53 }) | 45 chrome_apis.append(entry) |
| 54 else: | |
| 55 chrome_apis.append({ 'name': template_name.replace('_', '.') }) | |
| 56 if len(chrome_apis): | 46 if len(chrome_apis): |
| 57 chrome_apis[-1]['last'] = True | 47 chrome_apis[-1]['last'] = True |
| 58 if len(experimental_apis): | 48 if len(experimental_apis): |
| 59 experimental_apis[-1]['last'] = True | 49 experimental_apis[-1]['last'] = True |
| 60 return { | 50 return { |
| 61 'chrome': chrome_apis, | 51 'chrome': chrome_apis, |
| 62 'experimental': experimental_apis | 52 'experimental': experimental_apis |
| 63 } | 53 } |
| 64 | 54 |
| 65 def _ListAPIs(self, base_dir, apis): | 55 def _ListAPIs(self, base_dir, apis): |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 78 | 68 |
| 79 def GetAllNames(self): | 69 def GetAllNames(self): |
| 80 names = [] | 70 names = [] |
| 81 for platform in ['apps', 'extensions']: | 71 for platform in ['apps', 'extensions']: |
| 82 for category in ['chrome', 'experimental']: | 72 for category in ['chrome', 'experimental']: |
| 83 names.extend(self.get(platform).get(category)) | 73 names.extend(self.get(platform).get(category)) |
| 84 return [api_name['name'] for api_name in names] | 74 return [api_name['name'] for api_name in names] |
| 85 | 75 |
| 86 def get(self, key): | 76 def get(self, key): |
| 87 return self._compiled_fs.GetFromFileListing(self._api_path)[key] | 77 return self._compiled_fs.GetFromFileListing(self._api_path)[key] |
| OLD | NEW |