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 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 |
| 11 from api_data_source import APIDataSource | 11 from api_data_source import APIDataSource |
| 12 from api_list_data_source import APIListDataSource | 12 from api_list_data_source import APIListDataSource |
| 13 from appengine_blobstore import AppEngineBlobstore | 13 from appengine_blobstore import AppEngineBlobstore |
| 14 from appengine_url_fetcher import AppEngineUrlFetcher | 14 from appengine_url_fetcher import AppEngineUrlFetcher |
| 15 from appengine_wrappers import GetAppVersion, IsDevServer | 15 from appengine_wrappers import GetAppVersion, IsDevServer |
| 16 from branch_utility import BranchUtility | 16 from branch_utility import BranchUtility |
| 17 from caching_file_system import CachingFileSystem | 17 from caching_file_system import CachingFileSystem |
| 18 from compiled_file_system import CompiledFileSystem | 18 from compiled_file_system import CompiledFileSystem |
| 19 from empty_dir_file_system import EmptyDirFileSystem | 19 from empty_dir_file_system import EmptyDirFileSystem |
| 20 from example_zipper import ExampleZipper | 20 from example_zipper import ExampleZipper |
| 21 from file_system import FileNotFoundError | 21 from file_system import FileNotFoundError |
| 22 from github_file_system import GithubFileSystem | 22 from github_file_system import GithubFileSystem |
| 23 from intro_data_source import IntroDataSource | 23 from intro_data_source import IntroDataSource |
| 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 patched_file_system import PatchedFileSystem | |
| 27 from path_canonicalizer import PathCanonicalizer | 28 from path_canonicalizer import PathCanonicalizer |
| 28 from reference_resolver import ReferenceResolver | 29 from reference_resolver import ReferenceResolver |
| 30 from rietveld_patcher import RietveldPatcher | |
| 29 from samples_data_source import SamplesDataSource | 31 from samples_data_source import SamplesDataSource |
| 30 from sidenav_data_source import SidenavDataSource | 32 from sidenav_data_source import SidenavDataSource |
| 31 from subversion_file_system import SubversionFileSystem | 33 from subversion_file_system import SubversionFileSystem |
| 32 import svn_constants | 34 import svn_constants |
| 33 from template_data_source import TemplateDataSource | 35 from template_data_source import TemplateDataSource |
| 34 from third_party.json_schema_compiler.memoize import memoize | 36 from third_party.json_schema_compiler.memoize import memoize |
| 35 from third_party.json_schema_compiler.model import UnixName | 37 from third_party.json_schema_compiler.model import UnixName |
| 36 import url_constants | 38 import url_constants |
| 37 | 39 |
| 38 def _IsSamplesDisabled(): | 40 def _IsSamplesDisabled(): |
| 39 return IsDevServer() | 41 return IsDevServer() |
| 40 | 42 |
| 41 class ServerInstance(object): | 43 class ServerInstance(object): |
| 42 # Lazily create so we don't create github file systems unnecessarily in | 44 # Lazily create so we don't create github file systems unnecessarily in |
| 43 # tests. | 45 # tests. |
| 44 branch_utility = None | 46 branch_utility = None |
| 45 github_file_system = None | 47 github_file_system = None |
| 46 | 48 |
| 47 @staticmethod | 49 @staticmethod |
| 48 @memoize | 50 @memoize |
| 49 def GetOrCreateOffline(channel): | 51 def GetOrCreateOffline(channel, static_path=None, issue=None): |
|
not at google - send to devlin
2013/05/07 05:45:40
these optional parameters won't work well with the
| |
| 50 '''Gets/creates a local ServerInstance, meaning that only resources local to | 52 '''Gets/creates a local ServerInstance, meaning that only resources local to |
| 51 the server - memcache, object store, etc, are queried. This amounts to not | 53 the server - memcache, object store, etc, are queried. This amounts to not |
| 52 setting up the subversion nor github file systems. | 54 setting up the subversion nor github file systems. |
| 53 ''' | 55 ''' |
| 54 branch_utility = ServerInstance._GetOrCreateBranchUtility() | 56 branch_utility = ServerInstance._GetOrCreateBranchUtility() |
| 55 branch = branch_utility.GetBranchNumberForChannelName(channel) | 57 branch = branch_utility.GetBranchNumberForChannelName(channel) |
| 56 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), | 58 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), |
| 57 branch) | 59 branch) |
| 58 # No svn nor github file systems. Rely on the crons to fill the caches, and | 60 # No svn nor github file systems. Rely on the crons to fill the caches, and |
| 59 # for the caches to exist. | 61 # for the caches to exist. |
| 60 return ServerInstance( | 62 return ServerInstance._CreateWithPatch( |
| 61 channel, | 63 channel, |
| 64 static_path, | |
| 62 object_store_creator_factory, | 65 object_store_creator_factory, |
| 63 CachingFileSystem(OfflineFileSystem(SubversionFileSystem), | 66 CachingFileSystem(OfflineFileSystem(SubversionFileSystem), |
| 64 object_store_creator_factory, | 67 object_store_creator_factory, |
| 65 use_existing_values=True), | 68 use_existing_values=True), |
| 66 # TODO(kalman): convert GithubFileSystem to be wrappable in a | 69 # TODO(kalman): convert GithubFileSystem to be wrappable in a |
| 67 # CachingFileSystem so that it can be replaced with an | 70 # CachingFileSystem so that it can be replaced with an |
| 68 # OfflineFileSystem. Currently GFS doesn't set the child versions of | 71 # OfflineFileSystem. Currently GFS doesn't set the child versions of |
| 69 # stat requests so it doesn't. | 72 # stat requests so it doesn't. |
| 70 ServerInstance._GetOrCreateGithubFileSystem()) | 73 ServerInstance._GetOrCreateGithubFileSystem(), |
| 74 issue) | |
| 71 | 75 |
| 72 @staticmethod | 76 @staticmethod |
| 73 def CreateOnline(channel): | 77 def CreateOnline(channel, static_path=None, issue=None): |
| 74 '''Creates/creates an online server instance, meaning that both local and | 78 '''Creates/creates an online server instance, meaning that both local and |
| 75 subversion/github resources are queried. | 79 subversion/github resources are queried. |
| 76 ''' | 80 ''' |
| 77 branch_utility = ServerInstance._GetOrCreateBranchUtility() | 81 branch_utility = ServerInstance._GetOrCreateBranchUtility() |
| 78 branch = branch_utility.GetBranchNumberForChannelName(channel) | 82 branch = branch_utility.GetBranchNumberForChannelName(channel) |
| 79 | 83 |
| 80 if branch == 'trunk': | 84 if branch == 'trunk': |
| 81 svn_url = '/'.join((url_constants.SVN_TRUNK_URL, | 85 svn_url = '/'.join((url_constants.SVN_TRUNK_URL, |
| 82 'src', | 86 'src', |
| 83 svn_constants.EXTENSIONS_PATH)) | 87 svn_constants.EXTENSIONS_PATH)) |
| 84 else: | 88 else: |
| 85 svn_url = '/'.join((url_constants.SVN_BRANCH_URL, | 89 svn_url = '/'.join((url_constants.SVN_BRANCH_URL, |
| 86 branch, | 90 branch, |
| 87 'src', | 91 'src', |
| 88 svn_constants.EXTENSIONS_PATH)) | 92 svn_constants.EXTENSIONS_PATH)) |
| 89 | 93 |
| 90 viewvc_url = svn_url.replace(url_constants.SVN_URL, | 94 viewvc_url = svn_url.replace(url_constants.SVN_URL, |
| 91 url_constants.VIEWVC_URL) | 95 url_constants.VIEWVC_URL) |
| 92 | 96 |
| 93 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), | 97 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), |
| 94 branch) | 98 branch) |
| 95 | 99 |
| 96 svn_file_system = CachingFileSystem( | 100 svn_file_system = CachingFileSystem( |
| 97 SubversionFileSystem(AppEngineUrlFetcher(svn_url), | 101 SubversionFileSystem(AppEngineUrlFetcher(svn_url), |
| 98 AppEngineUrlFetcher(viewvc_url)), | 102 AppEngineUrlFetcher(viewvc_url)), |
| 99 object_store_creator_factory) | 103 object_store_creator_factory) |
| 100 | 104 |
| 105 return ServerInstance._CreateWithPatch( | |
| 106 channel, | |
| 107 static_path, | |
| 108 object_store_creator_factory, | |
| 109 svn_file_system, | |
| 110 ServerInstance._GetOrCreateGithubFileSystem(), | |
| 111 issue) | |
| 112 | |
| 113 @staticmethod | |
| 114 def _CreateWithPatch(channel, | |
| 115 static_path, | |
| 116 object_store_creator_factory, | |
| 117 svn_file_system, | |
| 118 github_file_system, | |
| 119 issue=None): | |
| 120 if static_path is None: | |
| 121 static_path = ('/static' if channel == 'stable' else | |
| 122 '/%s/static' % channel) | |
| 123 if issue is not None: | |
| 124 original_object_store_creator_factory = object_store_creator_factory | |
| 125 original_svn_file_system = svn_file_system | |
| 126 object_store_creator_factory = ObjectStoreCreator.Factory( | |
| 127 GetAppVersion(), | |
| 128 'trunk@%s' % issue) | |
| 129 rietveld_patcher = RietveldPatcher( | |
| 130 svn_constants.EXTENSIONS_PATH, | |
| 131 issue, | |
| 132 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER), | |
| 133 object_store_creator_factory) | |
| 134 svn_file_system = PatchedFileSystem(svn_file_system, | |
| 135 rietveld_patcher) | |
| 136 compiled_fs_factory = CompiledFileSystem.Factory( | |
| 137 original_svn_file_system, | |
| 138 original_object_store_creator_factory, | |
| 139 svn_file_system, | |
| 140 object_store_creator_factory) | |
| 141 else: | |
| 142 compiled_fs_factory = None | |
| 143 | |
| 101 return ServerInstance(channel, | 144 return ServerInstance(channel, |
| 145 static_path, | |
| 102 object_store_creator_factory, | 146 object_store_creator_factory, |
| 103 svn_file_system, | 147 svn_file_system, |
| 104 ServerInstance._GetOrCreateGithubFileSystem()) | 148 github_file_system, |
| 149 compiled_fs_factory) | |
| 105 | 150 |
| 106 @staticmethod | 151 @staticmethod |
| 107 def CreateForTest(file_system): | 152 def CreateForTest(file_system): |
| 108 return ServerInstance('test', | 153 return ServerInstance('test', |
| 154 '/static', | |
| 109 ObjectStoreCreator.TestFactory(), | 155 ObjectStoreCreator.TestFactory(), |
| 110 file_system, | 156 file_system, |
| 111 None) | 157 None) |
| 112 | 158 |
| 113 @staticmethod | 159 @staticmethod |
| 114 def _GetOrCreateBranchUtility(): | 160 def _GetOrCreateBranchUtility(): |
| 115 if ServerInstance.branch_utility is None: | 161 if ServerInstance.branch_utility is None: |
| 116 ServerInstance.branch_utility = BranchUtility( | 162 ServerInstance.branch_utility = BranchUtility( |
| 117 url_constants.OMAHA_PROXY_URL, | 163 url_constants.OMAHA_PROXY_URL, |
| 118 AppEngineUrlFetcher()) | 164 AppEngineUrlFetcher()) |
| 119 return ServerInstance.branch_utility | 165 return ServerInstance.branch_utility |
| 120 | 166 |
| 121 @staticmethod | 167 @staticmethod |
| 122 def _GetOrCreateGithubFileSystem(): | 168 def _GetOrCreateGithubFileSystem(): |
| 123 # Initialising github is pointless if samples are disabled, since it's only | 169 # Initialising github is pointless if samples are disabled, since it's only |
| 124 # used for apps samples. | 170 # used for apps samples. |
| 125 if ServerInstance.github_file_system is None: | 171 if ServerInstance.github_file_system is None: |
| 126 if _IsSamplesDisabled(): | 172 if _IsSamplesDisabled(): |
| 127 ServerInstance.github_file_system = EmptyDirFileSystem() | 173 ServerInstance.github_file_system = EmptyDirFileSystem() |
| 128 else: | 174 else: |
| 129 ServerInstance.github_file_system = GithubFileSystem( | 175 ServerInstance.github_file_system = GithubFileSystem( |
| 130 AppEngineUrlFetcher(url_constants.GITHUB_URL), | 176 AppEngineUrlFetcher(url_constants.GITHUB_URL), |
| 131 AppEngineBlobstore()) | 177 AppEngineBlobstore()) |
| 132 return ServerInstance.github_file_system | 178 return ServerInstance.github_file_system |
| 133 | 179 |
| 134 def __init__(self, | 180 def __init__(self, |
| 135 channel, | 181 channel, |
| 182 static_path, | |
| 136 object_store_creator_factory, | 183 object_store_creator_factory, |
| 137 svn_file_system, | 184 svn_file_system, |
| 138 github_file_system): | 185 github_file_system, |
| 186 compiled_fs_factory=None): | |
| 139 self.svn_file_system = svn_file_system | 187 self.svn_file_system = svn_file_system |
| 140 | 188 |
| 141 self.github_file_system = github_file_system | 189 self.github_file_system = github_file_system |
| 142 | 190 |
| 143 self.compiled_fs_factory = CompiledFileSystem.Factory( | 191 if compiled_fs_factory is None: |
| 144 svn_file_system, | 192 self.compiled_fs_factory = CompiledFileSystem.Factory( |
| 145 object_store_creator_factory) | 193 svn_file_system, |
| 194 object_store_creator_factory) | |
| 195 else: | |
| 196 self.compiled_fs_factory = compiled_fs_factory | |
| 146 | 197 |
| 147 self.api_list_data_source_factory = APIListDataSource.Factory( | 198 self.api_list_data_source_factory = APIListDataSource.Factory( |
| 148 self.compiled_fs_factory, | 199 self.compiled_fs_factory, |
| 149 svn_constants.API_PATH, | 200 svn_constants.API_PATH, |
| 150 svn_constants.PUBLIC_TEMPLATE_PATH) | 201 svn_constants.PUBLIC_TEMPLATE_PATH) |
| 151 | 202 |
| 152 self.api_data_source_factory = APIDataSource.Factory( | 203 self.api_data_source_factory = APIDataSource.Factory( |
| 153 self.compiled_fs_factory, | 204 self.compiled_fs_factory, |
| 154 svn_constants.API_PATH) | 205 svn_constants.API_PATH) |
| 155 | 206 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 self.template_data_source_factory = TemplateDataSource.Factory( | 242 self.template_data_source_factory = TemplateDataSource.Factory( |
| 192 channel, | 243 channel, |
| 193 self.api_data_source_factory, | 244 self.api_data_source_factory, |
| 194 self.api_list_data_source_factory, | 245 self.api_list_data_source_factory, |
| 195 self.intro_data_source_factory, | 246 self.intro_data_source_factory, |
| 196 self.samples_data_source_factory, | 247 self.samples_data_source_factory, |
| 197 self.sidenav_data_source_factory, | 248 self.sidenav_data_source_factory, |
| 198 self.compiled_fs_factory, | 249 self.compiled_fs_factory, |
| 199 self.ref_resolver_factory, | 250 self.ref_resolver_factory, |
| 200 svn_constants.PUBLIC_TEMPLATE_PATH, | 251 svn_constants.PUBLIC_TEMPLATE_PATH, |
| 201 svn_constants.PRIVATE_TEMPLATE_PATH) | 252 svn_constants.PRIVATE_TEMPLATE_PATH, |
| 253 static_path) | |
| 202 | 254 |
| 203 self.example_zipper = ExampleZipper( | 255 self.example_zipper = ExampleZipper( |
| 204 self.compiled_fs_factory, | 256 self.compiled_fs_factory, |
| 205 svn_constants.DOCS_PATH) | 257 svn_constants.DOCS_PATH) |
| 206 | 258 |
| 207 self.path_canonicalizer = PathCanonicalizer( | 259 self.path_canonicalizer = PathCanonicalizer( |
| 208 channel, | 260 channel, |
| 209 self.compiled_fs_factory) | 261 self.compiled_fs_factory) |
| 210 | 262 |
| 211 self.content_cache = self.compiled_fs_factory.CreateIdentity(ServerInstance) | 263 self.content_cache = self.compiled_fs_factory.CreateIdentity(ServerInstance) |
| OLD | NEW |