OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 |
| 7 import third_party.json_schema_compiler.model as model |
| 8 |
| 9 class APIListDataSource(object): |
| 10 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs |
| 11 that are used in the api_index.html and experimental.html pages. |
| 12 """ |
| 13 def __init__(self, cache_builder, file_system, api_path, public_path): |
| 14 self._cache = cache_builder.build(self._ListAPIs) |
| 15 self._file_system = file_system |
| 16 self._api_path = api_path + '/' |
| 17 self._public_path = public_path + '/' |
| 18 |
| 19 def _ListAPIs(self, apis): |
| 20 api_names = set(os.path.splitext(name)[0] for name in apis) |
| 21 public_templates = self._file_system.ReadSingle(self._public_path) |
| 22 template_names = [os.path.splitext(name)[0] for name in public_templates] |
| 23 experimental_apis = [] |
| 24 chrome_apis = [] |
| 25 for i, template_name in enumerate(template_names): |
| 26 if model.UnixName(template_name) in api_names: |
| 27 if template_name.startswith('experimental'): |
| 28 experimental_apis.append(template_name.replace('_', '.')) |
| 29 else: |
| 30 chrome_apis.append(template_name.replace('_', '.')) |
| 31 return { |
| 32 'chrome': sorted(chrome_apis), |
| 33 'experimental': sorted(experimental_apis) |
| 34 } |
| 35 |
| 36 def __getitem__(self, key): |
| 37 return self.get(key) |
| 38 |
| 39 def get(self, key): |
| 40 try: |
| 41 return self._cache.GetFromFile(self._api_path)[key] |
| 42 except Exception as e: |
| 43 return None |
OLD | NEW |