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