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

Unified Diff: chrome/common/extensions/docs/server2/host_file_system_provider.py

Issue 26418002: Docserver: Pull knowledge of host file systems into a single (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename to provider Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/host_file_system_provider.py
diff --git a/chrome/common/extensions/docs/server2/host_file_system_creator.py b/chrome/common/extensions/docs/server2/host_file_system_provider.py
similarity index 64%
rename from chrome/common/extensions/docs/server2/host_file_system_creator.py
rename to chrome/common/extensions/docs/server2/host_file_system_provider.py
index cf741058ca9b6bec371bd768c076d0f655fb7902..a205e2ab63dd72abfbc44c77435f4f2e54ce9be2 100644
--- a/chrome/common/extensions/docs/server2/host_file_system_creator.py
+++ b/chrome/common/extensions/docs/server2/host_file_system_provider.py
@@ -6,14 +6,19 @@ from caching_file_system import CachingFileSystem
from local_file_system import LocalFileSystem
from offline_file_system import OfflineFileSystem
from subversion_file_system import SubversionFileSystem
+from third_party.json_schema_compiler.memoize import memoize
-class HostFileSystemCreator(object):
+# TODO(kalman): Rename this HostFileSystemProvider.
+
+class HostFileSystemProvider(object):
'''Creates host file systems with configuration information. By default, SVN
file systems are created, although a constructor method can be passed in to
override this behavior (likely for testing purposes).
'''
def __init__(self,
object_store_creator,
+ revision_for_trunk=None,
+ trunk=None,
offline=False,
constructor_for_test=None):
self._object_store_creator = object_store_creator
@@ -22,19 +27,39 @@ class HostFileSystemCreator(object):
self._offline = offline
# Provides custom create behavior, useful in tests.
self._constructor_for_test = constructor_for_test
+ # Common case is for trunk to be derived from the 'trunk' branch, but we
+ # need to allow overriding that for cases like pinning trunk to a specific
+ # revision and patched file systems.
+ if trunk is not None:
+ assert revision_for_trunk is None, \
+ 'Cannot specify both revision_for_trunk= and trunk='
+ self._trunk = trunk
+ else:
+ self._trunk = self._Create('trunk', revision=revision_for_trunk)
- def Create(self, branch='trunk', revision=None, offline=None):
+ @memoize
+ def GetTrunk(self, revision=None):
+ return (self._trunk if revision is None else
+ self._Create('trunk', revision=revision))
+
+ @memoize
+ def GetBranch(self, branch):
'''Creates either SVN file systems or specialized file systems from the
constructor passed into this instance. Wraps the resulting file system in
an Offline file system if the offline flag is set, and finally wraps it in a
Caching file system.
'''
+ assert isinstance(branch, basestring), 'Branch %s must be a string' % branch
+ assert branch != 'trunk', 'Cannot specify branch=\'trunk\', use GetTrunk()'
+ return self._Create(branch)
+
+ def _Create(self, branch, revision=None):
if self._constructor_for_test is not None:
file_system = self._constructor_for_test(branch=branch, revision=revision)
else:
file_system = SubversionFileSystem.Create(branch=branch,
revision=revision)
- if offline or (offline is None and self._offline):
+ if self._offline:
file_system = OfflineFileSystem(file_system)
return CachingFileSystem(file_system, self._object_store_creator)
@@ -42,16 +67,16 @@ class HostFileSystemCreator(object):
def ForLocal(object_store_creator):
'''Used in creating a server instance on localhost.
'''
- return HostFileSystemCreator(
+ return HostFileSystemProvider(
object_store_creator,
constructor_for_test=lambda **_: LocalFileSystem.Create())
@staticmethod
def ForTest(file_system, object_store_creator):
- '''Used in creating a test server instance. The HostFileSystemCreator
+ '''Used in creating a test server instance. The HostFileSystemProvider
returned here will always return |file_system| when its Create() method is
called.
'''
- return HostFileSystemCreator(
+ return HostFileSystemProvider(
object_store_creator,
constructor_for_test=lambda **_: file_system)

Powered by Google App Engine
This is Rietveld 408576698