| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from caching_file_system import CachingFileSystem | |
| 6 from local_file_system import LocalFileSystem | |
| 7 from offline_file_system import OfflineFileSystem | |
| 8 from subversion_file_system import SubversionFileSystem | |
| 9 | |
| 10 class HostFileSystemCreator(object): | |
| 11 '''Creates host file systems with configuration information. By default, SVN | |
| 12 file systems are created, although a constructor method can be passed in to | |
| 13 override this behavior (likely for testing purposes). | |
| 14 ''' | |
| 15 def __init__(self, | |
| 16 object_store_creator, | |
| 17 offline=False, | |
| 18 constructor_for_test=None): | |
| 19 self._object_store_creator = object_store_creator | |
| 20 # Determines whether or not created file systems will be wrapped in an | |
| 21 # OfflineFileSystem. | |
| 22 self._offline = offline | |
| 23 # Provides custom create behavior, useful in tests. | |
| 24 self._constructor_for_test = constructor_for_test | |
| 25 | |
| 26 def Create(self, branch='trunk', revision=None, offline=None): | |
| 27 '''Creates either SVN file systems or specialized file systems from the | |
| 28 constructor passed into this instance. Wraps the resulting file system in | |
| 29 an Offline file system if the offline flag is set, and finally wraps it in a | |
| 30 Caching file system. | |
| 31 ''' | |
| 32 if self._constructor_for_test is not None: | |
| 33 file_system = self._constructor_for_test(branch=branch, revision=revision) | |
| 34 else: | |
| 35 file_system = SubversionFileSystem.Create(branch=branch, | |
| 36 revision=revision) | |
| 37 if offline or (offline is None and self._offline): | |
| 38 file_system = OfflineFileSystem(file_system) | |
| 39 return CachingFileSystem(file_system, self._object_store_creator) | |
| 40 | |
| 41 @staticmethod | |
| 42 def ForLocal(object_store_creator): | |
| 43 '''Used in creating a server instance on localhost. | |
| 44 ''' | |
| 45 return HostFileSystemCreator( | |
| 46 object_store_creator, | |
| 47 constructor_for_test=lambda **_: LocalFileSystem.Create()) | |
| 48 | |
| 49 @staticmethod | |
| 50 def ForTest(file_system, object_store_creator): | |
| 51 '''Used in creating a test server instance. The HostFileSystemCreator | |
| 52 returned here will always return |file_system| when its Create() method is | |
| 53 called. | |
| 54 ''' | |
| 55 return HostFileSystemCreator( | |
| 56 object_store_creator, | |
| 57 constructor_for_test=lambda **_: file_system) | |
| OLD | NEW |