| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 appengine_wrappers import IsDevServer | 5 from appengine_wrappers import IsDevServer |
| 6 from branch_utility import BranchUtility | |
| 7 from caching_file_system import CachingFileSystem | 6 from caching_file_system import CachingFileSystem |
| 8 from compiled_file_system import CompiledFileSystem | 7 from compiled_file_system import CompiledFileSystem |
| 9 from empty_dir_file_system import EmptyDirFileSystem | 8 from empty_dir_file_system import EmptyDirFileSystem |
| 10 from github_file_system import GithubFileSystem | 9 from github_file_system import GithubFileSystem |
| 11 from third_party.json_schema_compiler.memoize import memoize | 10 from third_party.json_schema_compiler.memoize import memoize |
| 12 from offline_file_system import OfflineFileSystem | 11 from offline_file_system import OfflineFileSystem |
| 13 from render_servlet import RenderServlet | 12 from render_servlet import RenderServlet |
| 14 from subversion_file_system import SubversionFileSystem | 13 from subversion_file_system import SubversionFileSystem |
| 15 from object_store_creator import ObjectStoreCreator | 14 from object_store_creator import ObjectStoreCreator |
| 16 from server_instance import ServerInstance | 15 from server_instance import ServerInstance |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 Anyway - to enforce this, we actually don't give instances access to SVN. If | 27 Anyway - to enforce this, we actually don't give instances access to SVN. If |
| 29 anything is missing from datastore, it'll be a 404. If the cronjobs don't | 28 anything is missing from datastore, it'll be a 404. If the cronjobs don't |
| 30 manage to catch everything - uhoh. On the other hand, we'll figure it out | 29 manage to catch everything - uhoh. On the other hand, we'll figure it out |
| 31 pretty soon, and it also means that legitimate 404s are caught before a round | 30 pretty soon, and it also means that legitimate 404s are caught before a round |
| 32 trip to SVN. | 31 trip to SVN. |
| 33 ''' | 32 ''' |
| 34 def __init__(self, delegate): | 33 def __init__(self, delegate): |
| 35 self._delegate = delegate | 34 self._delegate = delegate |
| 36 | 35 |
| 37 @memoize | 36 @memoize |
| 38 def CreateServerInstanceForChannel(self, channel): | 37 def CreateServerInstance(self): |
| 39 object_store_creator = ObjectStoreCreator(channel, start_empty=False) | 38 object_store_creator = ObjectStoreCreator(start_empty=False) |
| 40 branch = (self._delegate.CreateBranchUtility(object_store_creator) | |
| 41 .GetBranchForChannel(channel)) | |
| 42 host_file_system = CachingFileSystem( | 39 host_file_system = CachingFileSystem( |
| 43 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch(branch)), | 40 OfflineFileSystem(self._delegate.CreateHostFileSystem()), |
| 44 object_store_creator) | 41 object_store_creator) |
| 45 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem( | 42 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem( |
| 46 object_store_creator) | 43 object_store_creator) |
| 47 compiled_host_fs_factory = CompiledFileSystem.Factory( | 44 compiled_host_fs_factory = CompiledFileSystem.Factory( |
| 48 host_file_system, | 45 host_file_system, |
| 49 object_store_creator) | 46 object_store_creator) |
| 50 return ServerInstance(channel, | 47 return ServerInstance(object_store_creator, |
| 51 object_store_creator, | |
| 52 host_file_system, | 48 host_file_system, |
| 53 app_samples_file_system, | 49 app_samples_file_system, |
| 54 '/static' if channel == 'stable' else | 50 compiled_host_fs_factory, |
| 55 '/%s/static' % channel, | 51 '/static') |
| 56 compiled_host_fs_factory) | |
| 57 | 52 |
| 58 class InstanceServlet(object): | 53 class InstanceServlet(object): |
| 59 '''Servlet for running on normal AppEngine instances. | 54 '''Servlet for running on normal AppEngine instances. |
| 60 Create this via GetConstructor() so that cache state can be shared amongst | 55 Create this via GetConstructor() so that cache state can be shared amongst |
| 61 them via the memoizing Delegate. | 56 them via the memoizing Delegate. |
| 62 ''' | 57 ''' |
| 63 class Delegate(object): | 58 class Delegate(object): |
| 64 '''Allow runtime dependencies to be overriden for testing. | 59 '''Allow runtime dependencies to be overriden for testing. |
| 65 ''' | 60 ''' |
| 66 def CreateBranchUtility(self, object_store_creator): | 61 def CreateHostFileSystem(self): |
| 67 return BranchUtility.Create(object_store_creator) | 62 return SubversionFileSystem.Create('trunk') |
| 68 | |
| 69 def CreateHostFileSystemForBranch(self, branch): | |
| 70 return SubversionFileSystem.Create(branch) | |
| 71 | 63 |
| 72 def CreateAppSamplesFileSystem(self, object_store_creator): | 64 def CreateAppSamplesFileSystem(self, object_store_creator): |
| 73 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but | 65 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but |
| 74 # the cron job doesn't crawl the samples yet. | 66 # the cron job doesn't crawl the samples yet. |
| 75 return (EmptyDirFileSystem() if IsDevServer() else | 67 return (EmptyDirFileSystem() if IsDevServer() else |
| 76 GithubFileSystem.Create(object_store_creator)) | 68 GithubFileSystem.Create(object_store_creator)) |
| 77 | 69 |
| 78 @staticmethod | 70 @staticmethod |
| 79 def GetConstructor(delegate_for_test=None): | 71 def GetConstructor(delegate_for_test=None): |
| 80 render_servlet_delegate = _OfflineRenderServletDelegate( | 72 render_servlet_delegate = _OfflineRenderServletDelegate( |
| 81 delegate_for_test or InstanceServlet.Delegate()) | 73 delegate_for_test or InstanceServlet.Delegate()) |
| 82 return lambda request: RenderServlet(request, render_servlet_delegate) | 74 return lambda request: RenderServlet(request, render_servlet_delegate) |
| 83 | 75 |
| 84 # NOTE: if this were a real Servlet it would implement a Get() method, but | 76 # NOTE: if this were a real Servlet it would implement a Get() method, but |
| 85 # GetConstructor returns an appropriate lambda function (Request -> Servlet). | 77 # GetConstructor returns an appropriate lambda function (Request -> Servlet). |
| OLD | NEW |