| 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 from fnmatch import fnmatch | 5 from fnmatch import fnmatch |
| 6 import logging | 6 import logging |
| 7 import mimetypes | 7 import mimetypes |
| 8 import traceback | 8 import traceback |
| 9 import os | 9 import os |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 from local_file_system import LocalFileSystem | 24 from local_file_system import LocalFileSystem |
| 25 from object_store_creator import ObjectStoreCreator | 25 from object_store_creator import ObjectStoreCreator |
| 26 from offline_file_system import OfflineFileSystem | 26 from offline_file_system import OfflineFileSystem |
| 27 from path_canonicalizer import PathCanonicalizer | 27 from path_canonicalizer import PathCanonicalizer |
| 28 from reference_resolver import ReferenceResolver | 28 from reference_resolver import ReferenceResolver |
| 29 from samples_data_source import SamplesDataSource | 29 from samples_data_source import SamplesDataSource |
| 30 from sidenav_data_source import SidenavDataSource | 30 from sidenav_data_source import SidenavDataSource |
| 31 from subversion_file_system import SubversionFileSystem | 31 from subversion_file_system import SubversionFileSystem |
| 32 import svn_constants | 32 import svn_constants |
| 33 from template_data_source import TemplateDataSource | 33 from template_data_source import TemplateDataSource |
| 34 from third_party.json_schema_compiler.memoize import memoize | |
| 35 from third_party.json_schema_compiler.model import UnixName | 34 from third_party.json_schema_compiler.model import UnixName |
| 36 import url_constants | 35 import url_constants |
| 37 | 36 |
| 38 def _IsSamplesDisabled(): | 37 def _IsSamplesDisabled(): |
| 39 return IsDevServer() | 38 return IsDevServer() |
| 40 | 39 |
| 40 def _CreateBranchUtility(start_configuration): |
| 41 return BranchUtility( |
| 42 url_constants.OMAHA_PROXY_URL, |
| 43 AppEngineUrlFetcher(), |
| 44 ObjectStoreCreator.SharedFactory(GetAppVersion(), |
| 45 start_configuration)) |
| 46 |
| 47 def _CreateGithubFileSystem(start_configuration): |
| 48 # Slight hack: creating a github file system is pointless if samples are |
| 49 # disabled, since it's only used for apps samples. |
| 50 if _IsSamplesDisabled(): |
| 51 return EmptyDirFileSystem() |
| 52 return GithubFileSystem( |
| 53 AppEngineUrlFetcher(url_constants.GITHUB_URL), |
| 54 AppEngineBlobstore(), |
| 55 ObjectStoreCreator.SharedFactory(GetAppVersion(), |
| 56 start_configuration)) |
| 57 |
| 41 class ServerInstance(object): | 58 class ServerInstance(object): |
| 42 # Lazily create so we don't create github file systems unnecessarily in | |
| 43 # tests. | |
| 44 branch_utility = None | |
| 45 github_file_system = None | |
| 46 | |
| 47 @staticmethod | 59 @staticmethod |
| 48 @memoize | 60 def CreateOffline(channel, |
| 49 def GetOrCreateOffline(channel): | 61 host_file_system_type=SubversionFileSystem, |
| 50 '''Gets/creates a local ServerInstance, meaning that only resources local to | 62 app_samples_file_system=None): |
| 63 '''Creates a local ServerInstance, meaning that only resources local to |
| 51 the server - memcache, object store, etc, are queried. This amounts to not | 64 the server - memcache, object store, etc, are queried. This amounts to not |
| 52 setting up the subversion nor github file systems. | 65 setting up the subversion nor github file systems. |
| 53 ''' | 66 ''' |
| 54 branch_utility = ServerInstance._GetOrCreateBranchUtility() | 67 start_configuration = ObjectStoreCreator.START_POPULATED |
| 68 |
| 69 branch_utility = _CreateBranchUtility(start_configuration) |
| 55 branch = branch_utility.GetBranchNumberForChannelName(channel) | 70 branch = branch_utility.GetBranchNumberForChannelName(channel) |
| 56 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), | 71 object_store_creator_factory = ObjectStoreCreator.Factory( |
| 57 branch) | 72 GetAppVersion(), |
| 73 branch, |
| 74 start_configuration) |
| 75 |
| 76 if app_samples_file_system is None: |
| 77 app_samples_file_system = _CreateGithubFileSystem(start_configuration) |
| 78 |
| 58 # No svn nor github file systems. Rely on the crons to fill the caches, and | 79 # No svn nor github file systems. Rely on the crons to fill the caches, and |
| 59 # for the caches to exist. | 80 # for the caches to exist. |
| 60 return ServerInstance( | 81 return ServerInstance( |
| 61 channel, | 82 channel, |
| 62 object_store_creator_factory, | 83 object_store_creator_factory, |
| 63 CachingFileSystem(OfflineFileSystem(SubversionFileSystem), | 84 CachingFileSystem(OfflineFileSystem(host_file_system_type), |
| 64 object_store_creator_factory, | 85 object_store_creator_factory), |
| 65 use_existing_values=True), | 86 app_samples_file_system) |
| 66 # TODO(kalman): convert GithubFileSystem to be wrappable in a | |
| 67 # CachingFileSystem so that it can be replaced with an | |
| 68 # OfflineFileSystem. Currently GFS doesn't set the child versions of | |
| 69 # stat requests so it doesn't. | |
| 70 ServerInstance._GetOrCreateGithubFileSystem()) | |
| 71 | 87 |
| 72 @staticmethod | 88 @staticmethod |
| 73 def CreateOnline(channel): | 89 def CreateOnline(channel, |
| 90 host_file_system=None, |
| 91 app_samples_file_system=None): |
| 74 '''Creates/creates an online server instance, meaning that both local and | 92 '''Creates/creates an online server instance, meaning that both local and |
| 75 subversion/github resources are queried. | 93 subversion/github resources are queried. |
| 76 ''' | 94 ''' |
| 77 branch_utility = ServerInstance._GetOrCreateBranchUtility() | 95 start_configuration = ObjectStoreCreator.START_EMPTY |
| 96 |
| 97 branch_utility = _CreateBranchUtility(start_configuration) |
| 78 branch = branch_utility.GetBranchNumberForChannelName(channel) | 98 branch = branch_utility.GetBranchNumberForChannelName(channel) |
| 79 | 99 |
| 80 if branch == 'trunk': | 100 if branch == 'trunk': |
| 81 svn_url = '/'.join((url_constants.SVN_TRUNK_URL, | 101 svn_url = '/'.join((url_constants.SVN_TRUNK_URL, |
| 82 'src', | 102 'src', |
| 83 svn_constants.EXTENSIONS_PATH)) | 103 svn_constants.EXTENSIONS_PATH)) |
| 84 else: | 104 else: |
| 85 svn_url = '/'.join((url_constants.SVN_BRANCH_URL, | 105 svn_url = '/'.join((url_constants.SVN_BRANCH_URL, |
| 86 branch, | 106 branch, |
| 87 'src', | 107 'src', |
| 88 svn_constants.EXTENSIONS_PATH)) | 108 svn_constants.EXTENSIONS_PATH)) |
| 89 | 109 |
| 90 viewvc_url = svn_url.replace(url_constants.SVN_URL, | 110 viewvc_url = svn_url.replace(url_constants.SVN_URL, |
| 91 url_constants.VIEWVC_URL) | 111 url_constants.VIEWVC_URL) |
| 92 | 112 |
| 93 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), | 113 object_store_creator_factory = ObjectStoreCreator.Factory( |
| 94 branch) | 114 GetAppVersion(), |
| 115 branch, |
| 116 start_configuration) |
| 95 | 117 |
| 96 svn_file_system = CachingFileSystem( | 118 if host_file_system is None: |
| 97 SubversionFileSystem(AppEngineUrlFetcher(svn_url), | 119 host_file_system = SubversionFileSystem(AppEngineUrlFetcher(svn_url), |
| 98 AppEngineUrlFetcher(viewvc_url)), | 120 AppEngineUrlFetcher(viewvc_url)) |
| 99 object_store_creator_factory) | 121 cached_host_file_system = CachingFileSystem(host_file_system, |
| 122 object_store_creator_factory) |
| 123 |
| 124 if app_samples_file_system is None: |
| 125 app_samples_file_system = _CreateGithubFileSystem(start_configuration) |
| 100 | 126 |
| 101 return ServerInstance(channel, | 127 return ServerInstance(channel, |
| 102 object_store_creator_factory, | 128 object_store_creator_factory, |
| 103 svn_file_system, | 129 cached_host_file_system, |
| 104 ServerInstance._GetOrCreateGithubFileSystem()) | 130 app_samples_file_system) |
| 105 | 131 |
| 106 @staticmethod | 132 @staticmethod |
| 107 def CreateForTest(file_system): | 133 def CreateForTest(host_file_system): |
| 108 return ServerInstance('test', | 134 return ServerInstance('test', |
| 109 ObjectStoreCreator.TestFactory(), | 135 ObjectStoreCreator.TestFactory(), |
| 110 file_system, | 136 host_file_system, |
| 111 None) | 137 EmptyDirFileSystem()) |
| 112 | |
| 113 @staticmethod | |
| 114 def _GetOrCreateBranchUtility(): | |
| 115 if ServerInstance.branch_utility is None: | |
| 116 ServerInstance.branch_utility = BranchUtility( | |
| 117 url_constants.OMAHA_PROXY_URL, | |
| 118 AppEngineUrlFetcher()) | |
| 119 return ServerInstance.branch_utility | |
| 120 | |
| 121 @staticmethod | |
| 122 def _GetOrCreateGithubFileSystem(): | |
| 123 # Initialising github is pointless if samples are disabled, since it's only | |
| 124 # used for apps samples. | |
| 125 if ServerInstance.github_file_system is None: | |
| 126 if _IsSamplesDisabled(): | |
| 127 ServerInstance.github_file_system = EmptyDirFileSystem() | |
| 128 else: | |
| 129 ServerInstance.github_file_system = GithubFileSystem( | |
| 130 AppEngineUrlFetcher(url_constants.GITHUB_URL), | |
| 131 AppEngineBlobstore()) | |
| 132 return ServerInstance.github_file_system | |
| 133 | 138 |
| 134 def __init__(self, | 139 def __init__(self, |
| 135 channel, | 140 channel, |
| 136 object_store_creator_factory, | 141 object_store_creator_factory, |
| 137 svn_file_system, | 142 host_file_system, |
| 138 github_file_system): | 143 app_samples_file_system): |
| 139 self.svn_file_system = svn_file_system | 144 self.host_file_system = host_file_system |
| 140 | 145 |
| 141 self.github_file_system = github_file_system | 146 self.app_samples_file_system = app_samples_file_system |
| 142 | 147 |
| 143 self.compiled_fs_factory = CompiledFileSystem.Factory( | 148 self.compiled_fs_factory = CompiledFileSystem.Factory( |
| 144 svn_file_system, | 149 host_file_system, |
| 145 object_store_creator_factory) | 150 object_store_creator_factory) |
| 146 | 151 |
| 147 self.api_list_data_source_factory = APIListDataSource.Factory( | 152 self.api_list_data_source_factory = APIListDataSource.Factory( |
| 148 self.compiled_fs_factory, | 153 self.compiled_fs_factory, |
| 149 svn_constants.API_PATH, | 154 svn_constants.API_PATH, |
| 150 svn_constants.PUBLIC_TEMPLATE_PATH) | 155 svn_constants.PUBLIC_TEMPLATE_PATH) |
| 151 | 156 |
| 152 self.api_data_source_factory = APIDataSource.Factory( | 157 self.api_data_source_factory = APIDataSource.Factory( |
| 153 self.compiled_fs_factory, | 158 self.compiled_fs_factory, |
| 154 svn_constants.API_PATH) | 159 svn_constants.API_PATH) |
| 155 | 160 |
| 156 self.ref_resolver_factory = ReferenceResolver.Factory( | 161 self.ref_resolver_factory = ReferenceResolver.Factory( |
| 157 self.api_data_source_factory, | 162 self.api_data_source_factory, |
| 158 self.api_list_data_source_factory, | 163 self.api_list_data_source_factory, |
| 159 object_store_creator_factory) | 164 object_store_creator_factory) |
| 160 | 165 |
| 161 self.api_data_source_factory.SetReferenceResolverFactory( | 166 self.api_data_source_factory.SetReferenceResolverFactory( |
| 162 self.ref_resolver_factory) | 167 self.ref_resolver_factory) |
| 163 | 168 |
| 164 # Note: samples are super slow in the dev server because it doesn't support | 169 # Note: samples are super slow in the dev server because it doesn't support |
| 165 # async fetch, so disable them. If you actually want to test samples, then | 170 # async fetch, so disable them. If you actually want to test samples, then |
| 166 # good luck, and modify _IsSamplesDisabled at the top. | 171 # good luck, and modify _IsSamplesDisabled at the top. |
| 167 if _IsSamplesDisabled(): | 172 if _IsSamplesDisabled(): |
| 168 svn_fs_for_samples = EmptyDirFileSystem() | 173 extension_samples_fs = EmptyDirFileSystem() |
| 169 else: | 174 else: |
| 170 svn_fs_for_samples = self.svn_file_system | 175 extension_samples_fs = self.host_file_system |
| 171 self.samples_data_source_factory = SamplesDataSource.Factory( | 176 self.samples_data_source_factory = SamplesDataSource.Factory( |
| 172 channel, | 177 channel, |
| 173 svn_fs_for_samples, | 178 extension_samples_fs, |
| 174 self.github_file_system, | 179 self.app_samples_file_system, |
| 175 self.ref_resolver_factory, | 180 self.ref_resolver_factory, |
| 176 object_store_creator_factory, | 181 object_store_creator_factory, |
| 177 svn_constants.EXAMPLES_PATH) | 182 svn_constants.EXAMPLES_PATH) |
| 178 | 183 |
| 179 self.api_data_source_factory.SetSamplesDataSourceFactory( | 184 self.api_data_source_factory.SetSamplesDataSourceFactory( |
| 180 self.samples_data_source_factory) | 185 self.samples_data_source_factory) |
| 181 | 186 |
| 182 self.intro_data_source_factory = IntroDataSource.Factory( | 187 self.intro_data_source_factory = IntroDataSource.Factory( |
| 183 self.compiled_fs_factory, | 188 self.compiled_fs_factory, |
| 184 self.ref_resolver_factory, | 189 self.ref_resolver_factory, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 202 | 207 |
| 203 self.example_zipper = ExampleZipper( | 208 self.example_zipper = ExampleZipper( |
| 204 self.compiled_fs_factory, | 209 self.compiled_fs_factory, |
| 205 svn_constants.DOCS_PATH) | 210 svn_constants.DOCS_PATH) |
| 206 | 211 |
| 207 self.path_canonicalizer = PathCanonicalizer( | 212 self.path_canonicalizer = PathCanonicalizer( |
| 208 channel, | 213 channel, |
| 209 self.compiled_fs_factory) | 214 self.compiled_fs_factory) |
| 210 | 215 |
| 211 self.content_cache = self.compiled_fs_factory.CreateIdentity(ServerInstance) | 216 self.content_cache = self.compiled_fs_factory.CreateIdentity(ServerInstance) |
| OLD | NEW |