Chromium Code Reviews| 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 | 6 from branch_utility import BranchUtility |
| 7 from caching_file_system import CachingFileSystem | 7 from caching_file_system import CachingFileSystem |
| 8 from compiled_file_system import CompiledFileSystem | 8 from compiled_file_system import CompiledFileSystem |
| 9 from empty_dir_file_system import EmptyDirFileSystem | 9 from empty_dir_file_system import EmptyDirFileSystem |
| 10 from github_file_system import GithubFileSystem | 10 from github_file_system import GithubFileSystem |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 manage to catch everything - uhoh. On the other hand, we'll figure it out | 30 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 | 31 pretty soon, and it also means that legitimate 404s are caught before a round |
| 32 trip to SVN. | 32 trip to SVN. |
| 33 ''' | 33 ''' |
| 34 def __init__(self, delegate): | 34 def __init__(self, delegate): |
| 35 self._delegate = delegate | 35 self._delegate = delegate |
| 36 | 36 |
| 37 @memoize | 37 @memoize |
| 38 def CreateServerInstanceForChannel(self, channel): | 38 def CreateServerInstanceForChannel(self, channel): |
| 39 object_store_creator = ObjectStoreCreator(channel, start_empty=False) | 39 object_store_creator = ObjectStoreCreator(channel, start_empty=False) |
| 40 branch = (self._delegate.CreateBranchUtility(object_store_creator) | 40 branch_utility = self._delegate.CreateBranchUtility(object_store_creator) |
| 41 .GetChannelInfo(channel).branch) | 41 branch = branch_utility.GetChannelInfo(channel).branch |
| 42 host_file_system = CachingFileSystem( | 42 host_file_system = CachingFileSystem( |
| 43 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch(branch)), | 43 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch(branch)), |
| 44 object_store_creator) | 44 object_store_creator) |
| 45 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem( | 45 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem( |
| 46 object_store_creator) | 46 object_store_creator) |
| 47 def create_file_system(version): | |
| 48 return CachingFileSystem( | |
| 49 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch( | |
|
not at google - send to devlin
2013/07/03 19:54:56
HostFileSystemCreator would need an offline= flag
epeterson
2013/07/09 20:51:18
Done.
| |
| 50 branch_utility.GetBranchForVersion(version))), | |
| 51 object_store_creator) | |
| 47 compiled_host_fs_factory = CompiledFileSystem.Factory( | 52 compiled_host_fs_factory = CompiledFileSystem.Factory( |
| 48 host_file_system, | 53 host_file_system, |
| 49 object_store_creator) | 54 object_store_creator) |
| 50 return ServerInstance(channel, | 55 return ServerInstance(channel, |
| 51 object_store_creator, | 56 object_store_creator, |
| 52 host_file_system, | 57 host_file_system, |
| 53 app_samples_file_system, | 58 app_samples_file_system, |
| 54 '' if channel == 'stable' else '/%s' % channel, | 59 '' if channel == 'stable' else '/%s' % channel, |
| 55 compiled_host_fs_factory) | 60 compiled_host_fs_factory, |
| 61 branch_utility, | |
| 62 create_file_system) | |
| 56 | 63 |
| 57 class InstanceServlet(object): | 64 class InstanceServlet(object): |
| 58 '''Servlet for running on normal AppEngine instances. | 65 '''Servlet for running on normal AppEngine instances. |
| 59 Create this via GetConstructor() so that cache state can be shared amongst | 66 Create this via GetConstructor() so that cache state can be shared amongst |
| 60 them via the memoizing Delegate. | 67 them via the memoizing Delegate. |
| 61 ''' | 68 ''' |
| 62 class Delegate(object): | 69 class Delegate(object): |
| 63 '''Allow runtime dependencies to be overriden for testing. | 70 '''Allow runtime dependencies to be overriden for testing. |
| 64 ''' | 71 ''' |
| 65 def CreateBranchUtility(self, object_store_creator): | 72 def CreateBranchUtility(self, object_store_creator): |
| 66 return BranchUtility.Create(object_store_creator) | 73 return BranchUtility.Create(object_store_creator) |
| 67 | 74 |
| 68 def CreateHostFileSystemForBranch(self, branch): | 75 def CreateHostFileSystemForBranch(self, branch): |
| 69 return SubversionFileSystem.Create(branch) | 76 return SubversionFileSystem.Create(branch) |
| 70 | 77 |
| 71 def CreateAppSamplesFileSystem(self, object_store_creator): | 78 def CreateAppSamplesFileSystem(self, object_store_creator): |
| 72 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but | 79 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but |
| 73 # the cron job doesn't crawl the samples yet. | 80 # the cron job doesn't crawl the samples yet. |
| 74 return (EmptyDirFileSystem() if IsDevServer() else | 81 return (EmptyDirFileSystem() if IsDevServer() else |
| 75 GithubFileSystem.Create(object_store_creator)) | 82 GithubFileSystem.Create(object_store_creator)) |
| 76 | 83 |
| 77 @staticmethod | 84 @staticmethod |
| 78 def GetConstructor(delegate_for_test=None): | 85 def GetConstructor(delegate_for_test=None): |
| 79 render_servlet_delegate = _OfflineRenderServletDelegate( | 86 render_servlet_delegate = _OfflineRenderServletDelegate( |
| 80 delegate_for_test or InstanceServlet.Delegate()) | 87 delegate_for_test or InstanceServlet.Delegate()) |
| 81 return lambda request: RenderServlet(request, render_servlet_delegate) | 88 return lambda request: RenderServlet(request, render_servlet_delegate) |
| 82 | 89 |
| 83 # NOTE: if this were a real Servlet it would implement a Get() method, but | 90 # NOTE: if this were a real Servlet it would implement a Get() method, but |
| 84 # GetConstructor returns an appropriate lambda function (Request -> Servlet). | 91 # GetConstructor returns an appropriate lambda function (Request -> Servlet). |
| OLD | NEW |