| 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 api_data_source import APIDataSource | 5 from api_data_source import APIDataSource |
| 6 from api_list_data_source import APIListDataSource | 6 from api_list_data_source import APIListDataSource |
| 7 from appengine_wrappers import IsDevServer | 7 from appengine_wrappers import IsDevServer |
| 8 from availability_finder import AvailabilityFinder | 8 from availability_finder import AvailabilityFinder |
| 9 from compiled_file_system import CompiledFileSystem | 9 from compiled_file_system import CompiledFileSystem |
| 10 from empty_dir_file_system import EmptyDirFileSystem | 10 from empty_dir_file_system import EmptyDirFileSystem |
| 11 from example_zipper import ExampleZipper | 11 from example_zipper import ExampleZipper |
| 12 from features_bundle import FeaturesBundle | 12 from features_bundle import FeaturesBundle |
| 13 from host_file_system_creator import HostFileSystemCreator | 13 from host_file_system_provider import HostFileSystemProvider |
| 14 from host_file_system_iterator import HostFileSystemIterator | 14 from host_file_system_iterator import HostFileSystemIterator |
| 15 from intro_data_source import IntroDataSource | 15 from intro_data_source import IntroDataSource |
| 16 from object_store_creator import ObjectStoreCreator | 16 from object_store_creator import ObjectStoreCreator |
| 17 from path_canonicalizer import PathCanonicalizer | 17 from path_canonicalizer import PathCanonicalizer |
| 18 from redirector import Redirector | 18 from redirector import Redirector |
| 19 from reference_resolver import ReferenceResolver | 19 from reference_resolver import ReferenceResolver |
| 20 from samples_data_source import SamplesDataSource | 20 from samples_data_source import SamplesDataSource |
| 21 import svn_constants | 21 import svn_constants |
| 22 from template_data_source import TemplateDataSource | 22 from template_data_source import TemplateDataSource |
| 23 from test_branch_utility import TestBranchUtility | 23 from test_branch_utility import TestBranchUtility |
| 24 from test_object_store import TestObjectStore | 24 from test_object_store import TestObjectStore |
| 25 | 25 |
| 26 class ServerInstance(object): | 26 class ServerInstance(object): |
| 27 | 27 |
| 28 def __init__(self, | 28 def __init__(self, |
| 29 object_store_creator, | 29 object_store_creator, |
| 30 host_file_system, | |
| 31 app_samples_file_system, | 30 app_samples_file_system, |
| 32 compiled_fs_factory, | 31 compiled_fs_factory, |
| 33 branch_utility, | 32 branch_utility, |
| 34 host_file_system_creator, | 33 host_file_system_provider, |
| 35 base_path='/'): | 34 base_path='/'): |
| 36 ''' | 35 ''' |
| 37 |object_store_creator| | 36 |object_store_creator| |
| 38 The ObjectStoreCreator used to create almost all caches. | 37 The ObjectStoreCreator used to create almost all caches. |
| 39 |host_file_system| | |
| 40 The main FileSystem instance which hosts the server, its templates, and | |
| 41 most App/Extension content. Probably a SubversionFileSystem. | |
| 42 |app_samples_file_system| | 38 |app_samples_file_system| |
| 43 The FileSystem instance which hosts the App samples. | 39 The FileSystem instance which hosts the App samples. |
| 44 |compiled_fs_factory| | 40 |compiled_fs_factory| |
| 45 Factory used to create CompiledFileSystems, a higher-level cache type | 41 Factory used to create CompiledFileSystems, a higher-level cache type |
| 46 than ObjectStores. This can usually be derived from | 42 than ObjectStores. This can usually be derived from |
| 47 |object_store_creator| and |host_file_system| but under special | 43 |object_store_creator| and |host_file_system_provider| but under special |
| 48 circumstances a different implementation needs to be passed in. | 44 circumstances a different implementation needs to be passed in. |
| 49 |branch_utility| | 45 |branch_utility| |
| 50 Has knowledge of Chrome branches, channels, and versions. | 46 Has knowledge of Chrome branches, channels, and versions. |
| 51 |host_file_system_creator| | 47 |host_file_system_provider| |
| 52 Creates FileSystem instances which host the server at alternative | 48 Creates FileSystem instances which host the server at alternative |
| 53 revisions. | 49 revisions. |
| 54 |base_path| | 50 |base_path| |
| 55 The path which all HTML is generated relative to. Usually this is / | 51 The path which all HTML is generated relative to. Usually this is / |
| 56 but some servlets need to override this. | 52 but some servlets need to override this. |
| 57 ''' | 53 ''' |
| 58 self.object_store_creator = object_store_creator | 54 self.object_store_creator = object_store_creator |
| 59 | 55 |
| 60 self.host_file_system = host_file_system | |
| 61 | |
| 62 self.app_samples_file_system = app_samples_file_system | 56 self.app_samples_file_system = app_samples_file_system |
| 63 | 57 |
| 64 self.compiled_host_fs_factory = compiled_fs_factory | 58 self.compiled_host_fs_factory = compiled_fs_factory |
| 65 | 59 |
| 66 self.host_file_system_creator = host_file_system_creator | 60 self.host_file_system_provider = host_file_system_provider |
| 61 host_fs_at_trunk = host_file_system_provider.GetTrunk() |
| 67 | 62 |
| 68 assert base_path.startswith('/') and base_path.endswith('/') | 63 assert base_path.startswith('/') and base_path.endswith('/') |
| 69 self.base_path = base_path | 64 self.base_path = base_path |
| 70 | 65 |
| 71 self.host_file_system_iterator = HostFileSystemIterator( | 66 self.host_file_system_iterator = HostFileSystemIterator( |
| 72 host_file_system_creator, | 67 host_file_system_provider, |
| 73 host_file_system, | |
| 74 branch_utility) | 68 branch_utility) |
| 75 | 69 |
| 76 self.features_bundle = FeaturesBundle( | 70 self.features_bundle = FeaturesBundle( |
| 77 self.host_file_system, | 71 host_fs_at_trunk, |
| 78 self.compiled_host_fs_factory, | 72 self.compiled_host_fs_factory, |
| 79 self.object_store_creator) | 73 self.object_store_creator) |
| 80 | 74 |
| 81 self.availability_finder = AvailabilityFinder( | 75 self.availability_finder = AvailabilityFinder( |
| 82 self.host_file_system_iterator, | 76 self.host_file_system_iterator, |
| 83 object_store_creator, | 77 object_store_creator, |
| 84 branch_utility, | 78 branch_utility, |
| 85 host_file_system) | 79 host_fs_at_trunk) |
| 86 | 80 |
| 87 self.api_list_data_source_factory = APIListDataSource.Factory( | 81 self.api_list_data_source_factory = APIListDataSource.Factory( |
| 88 self.compiled_host_fs_factory, | 82 self.compiled_host_fs_factory, |
| 89 self.host_file_system, | 83 host_fs_at_trunk, |
| 90 svn_constants.PUBLIC_TEMPLATE_PATH, | 84 svn_constants.PUBLIC_TEMPLATE_PATH, |
| 91 self.features_bundle, | 85 self.features_bundle, |
| 92 self.object_store_creator) | 86 self.object_store_creator) |
| 93 | 87 |
| 94 self.api_data_source_factory = APIDataSource.Factory( | 88 self.api_data_source_factory = APIDataSource.Factory( |
| 95 self.compiled_host_fs_factory, | 89 self.compiled_host_fs_factory, |
| 96 svn_constants.API_PATH, | 90 svn_constants.API_PATH, |
| 97 self.availability_finder, | 91 self.availability_finder, |
| 98 branch_utility) | 92 branch_utility) |
| 99 | 93 |
| 100 self.ref_resolver_factory = ReferenceResolver.Factory( | 94 self.ref_resolver_factory = ReferenceResolver.Factory( |
| 101 self.api_data_source_factory, | 95 self.api_data_source_factory, |
| 102 self.api_list_data_source_factory, | 96 self.api_list_data_source_factory, |
| 103 object_store_creator) | 97 object_store_creator) |
| 104 | 98 |
| 105 self.api_data_source_factory.SetReferenceResolverFactory( | 99 self.api_data_source_factory.SetReferenceResolverFactory( |
| 106 self.ref_resolver_factory) | 100 self.ref_resolver_factory) |
| 107 | 101 |
| 108 # Note: samples are super slow in the dev server because it doesn't support | 102 # Note: samples are super slow in the dev server because it doesn't support |
| 109 # async fetch, so disable them. | 103 # async fetch, so disable them. |
| 110 if IsDevServer(): | 104 if IsDevServer(): |
| 111 extension_samples_fs = EmptyDirFileSystem() | 105 extension_samples_fs = EmptyDirFileSystem() |
| 112 else: | 106 else: |
| 113 extension_samples_fs = self.host_file_system | 107 extension_samples_fs = host_fs_at_trunk |
| 114 self.samples_data_source_factory = SamplesDataSource.Factory( | 108 self.samples_data_source_factory = SamplesDataSource.Factory( |
| 115 extension_samples_fs, | 109 extension_samples_fs, |
| 116 CompiledFileSystem.Factory(extension_samples_fs, object_store_creator), | 110 CompiledFileSystem.Factory(extension_samples_fs, object_store_creator), |
| 117 self.app_samples_file_system, | 111 self.app_samples_file_system, |
| 118 CompiledFileSystem.Factory(self.app_samples_file_system, | 112 CompiledFileSystem.Factory(self.app_samples_file_system, |
| 119 object_store_creator), | 113 object_store_creator), |
| 120 self.ref_resolver_factory, | 114 self.ref_resolver_factory, |
| 121 svn_constants.EXAMPLES_PATH, | 115 svn_constants.EXAMPLES_PATH, |
| 122 base_path) | 116 base_path) |
| 123 | 117 |
| 124 self.api_data_source_factory.SetSamplesDataSourceFactory( | 118 self.api_data_source_factory.SetSamplesDataSourceFactory( |
| 125 self.samples_data_source_factory) | 119 self.samples_data_source_factory) |
| 126 | 120 |
| 127 self.intro_data_source_factory = IntroDataSource.Factory( | 121 self.intro_data_source_factory = IntroDataSource.Factory( |
| 128 self.compiled_host_fs_factory, | 122 self.compiled_host_fs_factory, |
| 129 self.ref_resolver_factory, | 123 self.ref_resolver_factory, |
| 130 [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) | 124 [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) |
| 131 | 125 |
| 132 self.example_zipper = ExampleZipper( | 126 self.example_zipper = ExampleZipper( |
| 133 self.compiled_host_fs_factory, | 127 self.compiled_host_fs_factory, |
| 134 self.host_file_system, | 128 host_fs_at_trunk, |
| 135 svn_constants.DOCS_PATH) | 129 svn_constants.DOCS_PATH) |
| 136 | 130 |
| 137 self.path_canonicalizer = PathCanonicalizer(self.compiled_host_fs_factory) | 131 self.path_canonicalizer = PathCanonicalizer(self.compiled_host_fs_factory) |
| 138 | 132 |
| 139 self.redirector = Redirector( | 133 self.redirector = Redirector( |
| 140 self.compiled_host_fs_factory, | 134 self.compiled_host_fs_factory, |
| 141 self.host_file_system, | 135 host_fs_at_trunk, |
| 142 svn_constants.PUBLIC_TEMPLATE_PATH) | 136 svn_constants.PUBLIC_TEMPLATE_PATH) |
| 143 | 137 |
| 144 self.strings_json_path = svn_constants.STRINGS_JSON_PATH | 138 self.strings_json_path = svn_constants.STRINGS_JSON_PATH |
| 145 self.manifest_json_path = svn_constants.MANIFEST_JSON_PATH | 139 self.manifest_json_path = svn_constants.MANIFEST_JSON_PATH |
| 146 self.manifest_features_path = svn_constants.MANIFEST_FEATURES_PATH | 140 self.manifest_features_path = svn_constants.MANIFEST_FEATURES_PATH |
| 147 | 141 |
| 148 self.template_data_source_factory = TemplateDataSource.Factory( | 142 self.template_data_source_factory = TemplateDataSource.Factory( |
| 149 self.api_data_source_factory, | 143 self.api_data_source_factory, |
| 150 self.api_list_data_source_factory, | 144 self.api_list_data_source_factory, |
| 151 self.intro_data_source_factory, | 145 self.intro_data_source_factory, |
| 152 self.samples_data_source_factory, | 146 self.samples_data_source_factory, |
| 153 self.compiled_host_fs_factory, | 147 self.compiled_host_fs_factory, |
| 154 self.ref_resolver_factory, | 148 self.ref_resolver_factory, |
| 155 svn_constants.PUBLIC_TEMPLATE_PATH, | 149 svn_constants.PUBLIC_TEMPLATE_PATH, |
| 156 svn_constants.PRIVATE_TEMPLATE_PATH, | 150 svn_constants.PRIVATE_TEMPLATE_PATH, |
| 157 base_path) | 151 base_path) |
| 158 | 152 |
| 159 self.api_data_source_factory.SetTemplateDataSource( | 153 self.api_data_source_factory.SetTemplateDataSource( |
| 160 self.template_data_source_factory) | 154 self.template_data_source_factory) |
| 161 | 155 |
| 162 @staticmethod | 156 @staticmethod |
| 163 def ForTest(file_system, base_path='/'): | 157 def ForTest(file_system, base_path='/'): |
| 164 object_store_creator = ObjectStoreCreator.ForTest() | 158 object_store_creator = ObjectStoreCreator.ForTest() |
| 165 return ServerInstance(object_store_creator, | 159 return ServerInstance(object_store_creator, |
| 166 file_system, | |
| 167 EmptyDirFileSystem(), | 160 EmptyDirFileSystem(), |
| 168 CompiledFileSystem.Factory(file_system, | 161 CompiledFileSystem.Factory(file_system, |
| 169 object_store_creator), | 162 object_store_creator), |
| 170 TestBranchUtility.CreateWithCannedData(), | 163 TestBranchUtility.CreateWithCannedData(), |
| 171 HostFileSystemCreator.ForTest(file_system, | 164 HostFileSystemProvider.ForTest(file_system, |
| 172 object_store_creator), | 165 object_store_creator), |
| 173 base_path=base_path) | 166 base_path=base_path) |
| 174 | 167 |
| 175 @staticmethod | 168 @staticmethod |
| 176 def ForLocal(): | 169 def ForLocal(): |
| 177 object_store_creator = ObjectStoreCreator(start_empty=False, | 170 object_store_creator = ObjectStoreCreator(start_empty=False, |
| 178 store_type=TestObjectStore) | 171 store_type=TestObjectStore) |
| 179 host_file_system_creator = HostFileSystemCreator.ForLocal( | 172 host_file_system_provider = HostFileSystemProvider.ForLocal( |
| 180 object_store_creator) | 173 object_store_creator) |
| 181 trunk_file_system = host_file_system_creator.Create() | |
| 182 return ServerInstance( | 174 return ServerInstance( |
| 183 object_store_creator, | 175 object_store_creator, |
| 184 trunk_file_system, | |
| 185 EmptyDirFileSystem(), | 176 EmptyDirFileSystem(), |
| 186 CompiledFileSystem.Factory(trunk_file_system, object_store_creator), | 177 CompiledFileSystem.Factory(host_file_system_provider.GetTrunk(), |
| 178 object_store_creator), |
| 187 TestBranchUtility.CreateWithCannedData(), | 179 TestBranchUtility.CreateWithCannedData(), |
| 188 host_file_system_creator) | 180 host_file_system_provider) |
| OLD | NEW |