Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/common/extensions/docs/server2/host_file_system_provider.py

Issue 660383002: Docserver: Persist stat cache for versioned file systems (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 6 from gitiles_file_system import GitilesFileSystem
7 from local_file_system import LocalFileSystem 7 from local_file_system import LocalFileSystem
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.
18 ''' 18 '''
19 def __init__(self, 19 def __init__(self,
20 object_store_creator, 20 object_store_creator,
21 pinned_commit=None, 21 pinned_commit=None,
22 default_master_instance=None, 22 default_master_instance=None,
23 offline=False, 23 offline=False,
24 constructor_for_test=None): 24 constructor_for_test=None,
25 cache_only=False):
not at google - send to devlin 2014/10/20 21:06:57 Document this parameter (so I know what it means).
Ken Rockot(use gerrit already) 2014/10/22 03:19:54 Done.
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 |pinned_commit| 29 |pinned_commit|
29 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.
30 If None, 'master' file systems will use HEAD. 31 If None, 'master' file systems will use HEAD.
31 |default_master_instance| 32 |default_master_instance|
32 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
33 specific commit will return |default_master_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 GitilesFileSystems. 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._pinned_commit = pinned_commit 41 self._pinned_commit = pinned_commit
41 self._default_master_instance = default_master_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
45 self._cache_only = cache_only
44 46
45 @memoize 47 @memoize
46 def GetMaster(self, commit=None): 48 def GetMaster(self, commit=None):
47 '''Gets a file system tracking 'master'. Use this method rather than 49 '''Gets a file system tracking 'master'. Use this method rather than
48 GetBranch('master') because the behaviour is subtly different; 'master' can 50 GetBranch('master') because the behaviour is subtly different; 'master' can
49 be pinned to a specific commit (|pinned_commit| in constructor) and can have 51 be pinned to a specific commit (|pinned_commit| in constructor) and can have
50 have its default instance overridden (|default_master_instance| in the 52 have its default instance overridden (|default_master_instance| in the
51 constructor). 53 constructor).
52 54
53 |commit| if non-None determines a specific commit to pin the host file 55 |commit| if non-None determines a specific commit to pin the host file
54 system at, though it will be ignored if it's newer than |pinned_commit|. 56 system at, though it will be ignored if it's newer than |pinned_commit|.
55 If None then |commit| will track |pinned_commit| if is has been 57 If None then |commit| will track |pinned_commit| if is has been
56 set, or just HEAD (which might change during server runtime!). 58 set, or just HEAD (which might change during server runtime!).
57 ''' 59 '''
58 if commit is None: 60 if commit is None:
59 if self._default_master_instance is not None: 61 if self._default_master_instance is not None:
60 return self._default_master_instance 62 return self._default_master_instance
61 return self._Create('master', commit=self._pinned_commit) 63 return self._Create('master', commit=self._pinned_commit)
62 if self._pinned_commit is not None:
63 # XXX(ahernandez): THIS IS WRONG. Should be
64 # commit = Oldest(commit, self._pinned_commit).
65 commit = min(commit, self._pinned_commit)
66 return self._Create('master', commit=commit) 64 return self._Create('master', commit=commit)
67 65
68 @memoize 66 @memoize
69 def GetBranch(self, branch): 67 def GetBranch(self, branch):
70 '''Gets a file system tracking |branch|, for example '1150' - anything other 68 '''Gets a file system tracking |branch|, for example '1150' - anything other
71 than 'master', which must be constructed via the GetMaster() method. 69 than 'master', which must be constructed via the GetMaster() method.
72 70
73 Note: Unlike GetMaster this function doesn't take a |commit| argument 71 Note: Unlike GetMaster this function doesn't take a |commit| argument
74 since we assume that branches hardly ever change, while master frequently 72 since we assume that branches hardly ever change, while master frequently
75 changes. 73 changes.
76 ''' 74 '''
77 assert isinstance(branch, basestring), 'Branch %s must be a string' % branch 75 assert isinstance(branch, basestring), 'Branch %s must be a string' % branch
78 assert branch != 'master', ( 76 assert branch != 'master', (
79 'Cannot specify branch=\'master\', use GetMaster()') 77 'Cannot specify branch=\'master\', use GetMaster()')
80 return self._Create(branch) 78 return self._Create(branch)
81 79
82 def _Create(self, branch, commit=None): 80 def _Create(self, branch, commit=None):
83 '''Creates Gitiles file systems (or if in a test, potentially whatever 81 '''Creates Gitiles file systems (or if in a test, potentially whatever
84 |self._constructor_for_test specifies). Wraps the resulting file system in 82 |self._constructor_for_test specifies). Wraps the resulting file system in
85 an Offline file system if the offline flag is set, and finally wraps it in 83 an Offline file system if the offline flag is set, and finally wraps it in
86 a Caching file system. 84 a Caching file system.
87 ''' 85 '''
88 if self._constructor_for_test is not None: 86 if self._constructor_for_test is not None:
89 file_system = self._constructor_for_test(branch=branch, commit=commit) 87 file_system = self._constructor_for_test(branch=branch, commit=commit)
90 else: 88 else:
91 file_system = GitilesFileSystem.Create(branch=branch, commit=commit) 89 file_system = GitilesFileSystem.Create(branch=branch, commit=commit)
92 if self._offline: 90 if self._offline:
93 file_system = OfflineFileSystem(file_system) 91 file_system = OfflineFileSystem(file_system)
94 return CachingFileSystem(file_system, self._object_store_creator) 92 return CachingFileSystem(file_system, self._object_store_creator,
93 fail_on_miss=self._cache_only)
95 94
96 @staticmethod 95 @staticmethod
97 def ForLocal(object_store_creator, **optargs): 96 def ForLocal(object_store_creator, **optargs):
98 '''Used in creating a server instance on localhost. 97 '''Used in creating a server instance on localhost.
99 ''' 98 '''
100 return HostFileSystemProvider( 99 return HostFileSystemProvider(
101 object_store_creator, 100 object_store_creator,
102 constructor_for_test=lambda **_: LocalFileSystem.Create(), 101 constructor_for_test=lambda **_: LocalFileSystem.Create(),
103 **optargs) 102 **optargs)
104 103
105 @staticmethod 104 @staticmethod
106 def ForTest(file_system, object_store_creator, **optargs): 105 def ForTest(file_system, object_store_creator, **optargs):
107 '''Used in creating a test server instance. The HostFileSystemProvider 106 '''Used in creating a test server instance. The HostFileSystemProvider
108 returned here will always return |file_system| when its Create() method is 107 returned here will always return |file_system| when its Create() method is
109 called. 108 called.
110 ''' 109 '''
111 return HostFileSystemProvider( 110 return HostFileSystemProvider(
112 object_store_creator, 111 object_store_creator,
113 constructor_for_test=lambda **_: file_system, 112 constructor_for_test=lambda **_: file_system,
114 **optargs) 113 **optargs)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698