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 | 6 |
7 from data_source import DataSource | 7 from data_source import DataSource |
8 from docs_server_utils import StringIdentity | 8 from docs_server_utils import StringIdentity |
9 from environment import IsPreviewServer | 9 from environment import IsPreviewServer |
10 from file_system import FileNotFoundError | 10 from file_system import FileNotFoundError |
11 from future import Future, All | 11 from future import Future, All |
12 from jsc_view import CreateJSCView, GetEventByNameFromEvents | 12 from jsc_view import CreateJSCView, GetEventByNameFromEvents |
13 from platform_util import GetPlatforms | 13 from platform_util import GetPlatforms |
| 14 from third_party.json_schema_compiler.model import UnixName |
14 | 15 |
15 | 16 |
16 class APIDataSource(DataSource): | 17 class APIDataSource(DataSource): |
17 '''This class fetches and loads JSON APIs from the FileSystem passed in with | 18 '''This class fetches and loads JSON APIs from the FileSystem passed in with |
18 |compiled_fs_factory|, so the APIs can be plugged into templates. | 19 |compiled_fs_factory|, so the APIs can be plugged into templates. |
19 ''' | 20 ''' |
20 def __init__(self, server_instance, request): | 21 def __init__(self, server_instance, request): |
21 file_system = server_instance.host_file_system_provider.GetMaster() | 22 file_system = server_instance.host_file_system_provider.GetMaster() |
22 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) | 23 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) |
23 self._template_cache = server_instance.compiled_fs_factory.ForTemplates( | 24 self._template_cache = server_instance.compiled_fs_factory.ForTemplates( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 '''Return a getter object so that templates can perform lookups such | 81 '''Return a getter object so that templates can perform lookups such |
81 as apis.extensions.runtime. | 82 as apis.extensions.runtime. |
82 ''' | 83 ''' |
83 getter = lambda: 0 | 84 getter = lambda: 0 |
84 getter.get = lambda api_name: self._GetSchemaView(platform, api_name).Get() | 85 getter.get = lambda api_name: self._GetSchemaView(platform, api_name).Get() |
85 return getter | 86 return getter |
86 | 87 |
87 def GetRefreshPaths(self): | 88 def GetRefreshPaths(self): |
88 tasks = [] | 89 tasks = [] |
89 for platform in GetPlatforms(): | 90 for platform in GetPlatforms(): |
90 tasks += ['%s/%s' % (platform, api) | 91 tasks += ['%s/%s' % (platform, UnixName(api)) |
91 for api in | 92 for api in |
92 self._platform_bundle.GetAPIModels(platform).GetNames()] | 93 self._platform_bundle.GetAPIModels(platform).GetNames()] |
93 return tasks | 94 return tasks |
94 | 95 |
95 def Refresh(self, path): | 96 def Refresh(self, path): |
96 platform, api = path.split('/') | 97 platform, api = path.split('/') |
97 logging.info('Refreshing %s/%s' % (platform, api)) | 98 logging.info('Refreshing %s/%s' % (platform, api)) |
98 future = self._GetSchemaView(platform, api) | 99 future = self._GetSchemaView(platform, api) |
99 return All([future], except_pass=FileNotFoundError) | 100 return All([future], except_pass=FileNotFoundError) |
OLD | NEW |