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 gitiles_file_system import GitilesFileSystem | |
7 from local_file_system import LocalFileSystem | 6 from local_file_system import LocalFileSystem |
| 7 from local_git_file_system import LocalGitFileSystem |
8 from offline_file_system import OfflineFileSystem | 8 from offline_file_system import OfflineFileSystem |
9 from third_party.json_schema_compiler.memoize import memoize | 9 from third_party.json_schema_compiler.memoize import memoize |
10 | 10 |
11 | 11 |
12 class HostFileSystemProvider(object): | 12 class HostFileSystemProvider(object): |
13 '''Provides host file systems ("host" meaning the file system that hosts the | 13 '''Provides host file systems ("host" meaning the file system that hosts the |
14 server's source code and templates) tracking master, or any branch. | 14 server's source code and templates) tracking master, or any branch. |
15 | 15 |
16 File system instances are memoized to maintain the in-memory caches across | 16 File system instances are memoized to maintain the in-memory caches across |
17 multiple callers. | 17 multiple callers. |
(...skipping 10 matching lines...) Expand all Loading... |
28 Provides caches for file systems that need one. | 28 Provides caches for file systems that need one. |
29 |pinned_commit| | 29 |pinned_commit| |
30 If not None, the commit at which a 'master' file system will be created. | 30 If not None, the commit at which a 'master' file system will be created. |
31 If None, 'master' file systems will use HEAD. | 31 If None, 'master' file systems will use HEAD. |
32 |default_master_instance| | 32 |default_master_instance| |
33 If not None, 'master' file systems provided by this class without a | 33 If not None, 'master' file systems provided by this class without a |
34 specific commit will return |default_master_instance| instead. | 34 specific commit will return |default_master_instance| instead. |
35 |offline| | 35 |offline| |
36 If True all provided file systems will be wrapped in an OfflineFileSystem. | 36 If True all provided file systems will be wrapped in an OfflineFileSystem. |
37 |constructor_for_test| | 37 |constructor_for_test| |
38 Provides a custom constructor rather than creating GitilesFileSystems. | 38 Provides a custom constructor rather than creating LocalGitFileSystems. |
39 |cache_only| | 39 |cache_only| |
40 If True, all provided file systems will be cache-only, meaning that cache | 40 If True, all provided file systems will be cache-only, meaning that cache |
41 misses will result in errors rather than cache updates. | 41 misses will result in errors rather than cache updates. |
42 ''' | 42 ''' |
43 self._object_store_creator = object_store_creator | 43 self._object_store_creator = object_store_creator |
44 self._pinned_commit = pinned_commit | 44 self._pinned_commit = pinned_commit |
45 self._default_master_instance = default_master_instance | 45 self._default_master_instance = default_master_instance |
46 self._offline = offline | 46 self._offline = offline |
47 self._constructor_for_test = constructor_for_test | 47 self._constructor_for_test = constructor_for_test |
48 self._cache_only = cache_only | 48 self._cache_only = cache_only |
(...skipping 25 matching lines...) Expand all Loading... |
74 Note: Unlike GetMaster this function doesn't take a |commit| argument | 74 Note: Unlike GetMaster this function doesn't take a |commit| argument |
75 since we assume that branches hardly ever change, while master frequently | 75 since we assume that branches hardly ever change, while master frequently |
76 changes. | 76 changes. |
77 ''' | 77 ''' |
78 assert isinstance(branch, basestring), 'Branch %s must be a string' % branch | 78 assert isinstance(branch, basestring), 'Branch %s must be a string' % branch |
79 assert branch != 'master', ( | 79 assert branch != 'master', ( |
80 'Cannot specify branch=\'master\', use GetMaster()') | 80 'Cannot specify branch=\'master\', use GetMaster()') |
81 return self._Create(branch) | 81 return self._Create(branch) |
82 | 82 |
83 def _Create(self, branch, commit=None): | 83 def _Create(self, branch, commit=None): |
84 '''Creates Gitiles file systems (or if in a test, potentially whatever | 84 '''Creates local git file systems (or if in a test, potentially whatever |
85 |self._constructor_for_test specifies). Wraps the resulting file system in | 85 |self._constructor_for_test specifies). Wraps the resulting file system in |
86 an Offline file system if the offline flag is set, and finally wraps it in | 86 an Offline file system if the offline flag is set, and finally wraps it in |
87 a Caching file system. | 87 a Caching file system. |
88 ''' | 88 ''' |
89 if self._constructor_for_test is not None: | 89 if self._constructor_for_test is not None: |
90 file_system = self._constructor_for_test(branch=branch, commit=commit) | 90 file_system = self._constructor_for_test(branch=branch, commit=commit) |
91 else: | 91 else: |
92 file_system = GitilesFileSystem.Create(branch=branch, commit=commit) | 92 file_system = LocalGitFileSystem.Create(branch=branch, commit=commit) |
93 if self._offline: | 93 if self._offline: |
94 file_system = OfflineFileSystem(file_system) | 94 file_system = OfflineFileSystem(file_system) |
95 return CachingFileSystem(file_system, self._object_store_creator, | 95 return CachingFileSystem(file_system, self._object_store_creator, |
96 fail_on_miss=self._cache_only) | 96 fail_on_miss=self._cache_only) |
97 | 97 |
98 @staticmethod | 98 @staticmethod |
99 def ForLocal(object_store_creator, **optargs): | 99 def ForLocal(object_store_creator, **optargs): |
100 '''Used in creating a server instance on localhost. | 100 '''Used in creating a server instance on localhost. |
101 ''' | 101 ''' |
102 return HostFileSystemProvider( | 102 return HostFileSystemProvider( |
103 object_store_creator, | 103 object_store_creator, |
104 constructor_for_test=lambda **_: LocalFileSystem.Create(), | 104 constructor_for_test=lambda **_: LocalFileSystem.Create(), |
105 **optargs) | 105 **optargs) |
106 | 106 |
107 @staticmethod | 107 @staticmethod |
108 def ForTest(file_system, object_store_creator, **optargs): | 108 def ForTest(file_system, object_store_creator, **optargs): |
109 '''Used in creating a test server instance. The HostFileSystemProvider | 109 '''Used in creating a test server instance. The HostFileSystemProvider |
110 returned here will always return |file_system| when its Create() method is | 110 returned here will always return |file_system| when its Create() method is |
111 called. | 111 called. |
112 ''' | 112 ''' |
113 return HostFileSystemProvider( | 113 return HostFileSystemProvider( |
114 object_store_creator, | 114 object_store_creator, |
115 constructor_for_test=lambda **_: file_system, | 115 constructor_for_test=lambda **_: file_system, |
116 **optargs) | 116 **optargs) |
OLD | NEW |