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 from gitiles_file_system import GitilesFileSystem |
9 from third_party.json_schema_compiler.memoize import memoize | 10 from third_party.json_schema_compiler.memoize import memoize |
10 | 11 |
11 | 12 |
12 class HostFileSystemProvider(object): | 13 class HostFileSystemProvider(object): |
13 '''Provides host file systems ("host" meaning the file system that hosts the | 14 '''Provides host file systems ("host" meaning the file system that hosts the |
14 server's source code and templates) tracking trunk, or any branch. | 15 server's source code and templates) tracking master, or any branch. |
15 | 16 |
16 File system instances are memoized to maintain the in-memory caches across | 17 File system instances are memoized to maintain the in-memory caches across |
17 multiple callers. | 18 multiple callers. |
18 ''' | 19 ''' |
19 def __init__(self, | 20 def __init__(self, |
20 object_store_creator, | 21 object_store_creator, |
21 max_trunk_revision=None, | 22 pinned_commit=None, |
22 default_trunk_instance=None, | 23 default_master_instance=None, |
23 offline=False, | 24 offline=False, |
24 constructor_for_test=None): | 25 constructor_for_test=None): |
25 ''' | 26 ''' |
26 |object_store_creator| | 27 |object_store_creator| |
27 Provides caches for file systems that need one. | 28 Provides caches for file systems that need one. |
28 |max_trunk_revision| | 29 |pinned_commit| |
29 If not None, the maximum revision that a 'trunk' file system will be | 30 If not None, the commit at which a 'master' file system will be created. |
30 created at. If None, 'trunk' file systems will use HEAD. | 31 If None, 'master' file systems will use HEAD. |
31 |default_trunk_instance| | 32 |default_master_instance| |
32 If not None, 'trunk' file systems provided by this class without a | 33 If not None, 'master' file systems provided by this class without a |
33 specific revision will return |default_trunk_instance| instead. | 34 specific commit will return |default_master_instance| instead. |
34 |offline| | 35 |offline| |
35 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. |
36 |constructor_for_test| | 37 |constructor_for_test| |
37 Provides a custom constructor rather than creating SubversionFileSystems. | 38 Provides a custom constructor rather than creating GitilesFileSystems. |
38 ''' | 39 ''' |
39 self._object_store_creator = object_store_creator | 40 self._object_store_creator = object_store_creator |
40 self._max_trunk_revision = max_trunk_revision | 41 self._pinned_commit = pinned_commit |
41 self._default_trunk_instance = default_trunk_instance | 42 self._default_master_instance = default_master_instance |
42 self._offline = offline | 43 self._offline = offline |
43 self._constructor_for_test = constructor_for_test | 44 self._constructor_for_test = constructor_for_test |
44 | 45 |
45 @memoize | 46 @memoize |
46 def GetTrunk(self, revision=None): | 47 def GetMaster(self, commit=None): |
47 '''Gets a file system tracking 'trunk'. Use this method rather than | 48 '''Gets a file system tracking 'master'. Use this method rather than |
48 GetBranch('trunk') because the behaviour is subtly different; 'trunk' can | 49 GetBranch('master') because the behaviour is subtly different; 'master' can |
49 be pinned to a max revision (|max_trunk_revision| in constructor) and can | 50 be pinned to a specific commit (|pinned_commit| in constructor) and can have |
50 have its default instance overridden (|default_trunk_instance| in | 51 its default instance overridden (|default_master_instance| in the |
51 constructor). | 52 constructor). |
52 | 53 |
53 |revision| if non-None determines a specific revision to pin the host file | 54 |commit| if non-None determines a specific commit to pin the host file |
54 system at, though it will be ignored if it exceeds |max_trunk_revision|. | 55 system at, though it will be ignored if it's newer than |pinned_commit|. |
55 If None then |revision| will track |max_trunk_revision| if is has been | 56 If None then |commit| will track |pinned_commit| if is has been |
56 set, or just HEAD (which might change during server runtime!). | 57 set, or just HEAD (which might change during server runtime!). |
57 ''' | 58 ''' |
58 if revision is None: | 59 if commit is None: |
59 if self._default_trunk_instance is not None: | 60 if self._default_master_instance is not None: |
60 return self._default_trunk_instance | 61 return self._default_master_instance |
61 return self._Create('trunk', revision=self._max_trunk_revision) | 62 return self._Create('master', commit=self._pinned_commit) |
62 if self._max_trunk_revision is not None: | 63 if self._pinned_commit is not None: |
63 revision = min(revision, self._max_trunk_revision) | 64 # XXX(rockot): THIS IS WRONG. Should be |
64 return self._Create('trunk', revision=revision) | 65 # commit = Oldest(commit, pinned_commit). |
| 66 # Need this imaginary Oldest() to be synchronous. |
| 67 commit = self._pinned_commit |
| 68 return self._Create('master', commit=commit) |
65 | 69 |
66 @memoize | 70 @memoize |
67 def GetBranch(self, branch): | 71 def GetBranch(self, branch): |
68 '''Gets a file system tracking |branch|, for example '1150' - anything other | 72 '''Gets a file system tracking |branch|, for example '1150' - anything other |
69 than 'trunk', which must be constructed via the GetTrunk() method. | 73 than 'master', which must be constructed via the GetMaster() method. |
70 | 74 |
71 Note: Unlike GetTrunk this function doesn't take a |revision| argument | 75 Note: Unlike GetMaster this function doesn't take a |commit| argument |
72 since we assume that branches hardly ever change, while trunk frequently | 76 since we assume that branches hardly ever change, while master frequently |
73 changes. | 77 changes. |
74 ''' | 78 ''' |
75 assert isinstance(branch, basestring), 'Branch %s must be a string' % branch | 79 assert isinstance(branch, basestring), 'Branch %s must be a string' % branch |
76 assert branch != 'trunk', 'Cannot specify branch=\'trunk\', use GetTrunk()' | 80 assert branch != 'master', ( |
| 81 'Cannot specify branch=\'master\', use GetMaster()') |
77 return self._Create(branch) | 82 return self._Create(branch) |
78 | 83 |
79 def _Create(self, branch, revision=None): | 84 def _Create(self, branch, commit=None): |
80 '''Creates SVN file systems (or if in a test, potentially whatever | 85 '''Creates Gitiles file systems (or if in a test, potentially whatever |
81 |self._constructor_for_test specifies). Wraps the resulting file system in | 86 |self._constructor_for_test specifies). Wraps the resulting file system in |
82 an Offline file system if the offline flag is set, and finally wraps it in | 87 an Offline file system if the offline flag is set, and finally wraps it in |
83 a Caching file system. | 88 a Caching file system. |
84 ''' | 89 ''' |
85 if self._constructor_for_test is not None: | 90 if self._constructor_for_test is not None: |
86 file_system = self._constructor_for_test(branch=branch, revision=revision) | 91 file_system = self._constructor_for_test(branch=branch, commit=commit) |
87 else: | 92 else: |
88 file_system = SubversionFileSystem.Create(branch=branch, | 93 file_system = GitilesFileSystem.Create(branch=branch, commit=commit) |
89 revision=revision) | |
90 if self._offline: | 94 if self._offline: |
91 file_system = OfflineFileSystem(file_system) | 95 file_system = OfflineFileSystem(file_system) |
92 return CachingFileSystem(file_system, self._object_store_creator) | 96 return CachingFileSystem(file_system, self._object_store_creator) |
93 | 97 |
94 @staticmethod | 98 @staticmethod |
95 def ForLocal(object_store_creator, **optargs): | 99 def ForLocal(object_store_creator, **optargs): |
96 '''Used in creating a server instance on localhost. | 100 '''Used in creating a server instance on localhost. |
97 ''' | 101 ''' |
98 return HostFileSystemProvider( | 102 return HostFileSystemProvider( |
99 object_store_creator, | 103 object_store_creator, |
100 constructor_for_test=lambda **_: LocalFileSystem.Create(), | 104 constructor_for_test=lambda **_: LocalFileSystem.Create(), |
101 **optargs) | 105 **optargs) |
102 | 106 |
103 @staticmethod | 107 @staticmethod |
104 def ForTest(file_system, object_store_creator, **optargs): | 108 def ForTest(file_system, object_store_creator, **optargs): |
105 '''Used in creating a test server instance. The HostFileSystemProvider | 109 '''Used in creating a test server instance. The HostFileSystemProvider |
106 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 |
107 called. | 111 called. |
108 ''' | 112 ''' |
109 return HostFileSystemProvider( | 113 return HostFileSystemProvider( |
110 object_store_creator, | 114 object_store_creator, |
111 constructor_for_test=lambda **_: file_system, | 115 constructor_for_test=lambda **_: file_system, |
112 **optargs) | 116 **optargs) |
OLD | NEW |