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

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: cleanup 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_provider.py b/chrome/common/extensions/docs/server2/host_file_system_provider.py
new file mode 100644
index 0000000000000000000000000000000000000000..c55e1e694dd5b5f708448dad794007ac0cfa07b2
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/host_file_system_provider.py
@@ -0,0 +1,88 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+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
+
not at google - send to devlin 2013/10/08 15:48:39 no amount of --similarity=? will convince git cl t
Jeffrey Yasskin 2013/10/08 17:46:05 Half the time I try to increase the --similarity a
not at google - send to devlin 2013/10/08 18:27:37 hm ok I'll give it a go.
+
+class HostFileSystemProvider(object):
Jeffrey Yasskin 2013/10/08 17:46:05 What's the difference between a "Creator" and a "P
not at google - send to devlin 2013/10/08 18:27:37 the memoization is an implementation detail, thoug
+ '''Provides cached instances of host file systems for trunk or any branch.
+ '''
+ def __init__(self,
+ object_store_creator,
+ max_trunk_revision=None,
+ default_trunk_instance=None,
+ offline=False,
+ constructor_for_test=None):
+ '''
+ |object_store_creator|
+ Provides caches for file systems that need one.
+ |max_trunk_revision|
+ If not None, the maximum revision that a 'trunk' file system will be
+ created at. If None, 'trunk' file systems will use HEAD.
+ |default_trunk_instance|
+ If not None, 'trunk' file systems provided by this class without a
+ specific revision will return |default_trunk_instance| instead.
+ |offline|
+ If True all provided file systems will be wrapped in an OfflineFileSystem.
+ |constructor_for_test|
+ Provides a custom constructor rather than creating SubversionFileSystems.
+ '''
+ self._object_store_creator = object_store_creator
+ self._max_trunk_revision = max_trunk_revision
+ self._default_trunk_instance = default_trunk_instance
+ self._offline = offline
+ self._constructor_for_test = constructor_for_test
Jeffrey Yasskin 2013/10/08 17:46:05 Don't do it in this change (to keep the diff small
not at google - send to devlin 2013/10/08 18:27:37 SGTM.
+
+ @memoize
Jeffrey Yasskin 2013/10/08 17:46:05 Memoization is dangerous in long-lived servers whe
not at google - send to devlin 2013/10/08 18:27:37 that's not the level that the memoization happens
Jeffrey Yasskin 2013/10/08 20:49:39 'k, sounds good.
+ def GetTrunk(self, revision=None):
Jeffrey Yasskin 2013/10/08 17:46:05 Please describe the meaning of 'revision' on trunk
not at google - send to devlin 2013/10/08 18:27:37 Done.
+ if revision is None:
+ if self._default_trunk_instance is not None:
+ return self._default_trunk_instance
+ return self._Create('trunk', revision=self._max_trunk_revision)
+ if self._max_trunk_revision is not None:
+ revision = min(revision, self._max_trunk_revision)
+ return self._Create('trunk', revision=revision)
+
+ @memoize
Jeffrey Yasskin 2013/10/08 17:46:05 Branches also change over time, but maybe we don't
not at google - send to devlin 2013/10/08 18:27:37 correct, branches change, and it would be seriousl
Jeffrey Yasskin 2013/10/08 20:49:39 Given my misunderstanding about this memoization t
not at google - send to devlin 2013/10/08 21:29:36 Strictly speaking yes. We should be making sure th
+ def GetBranch(self, branch):
+ '''Creates either SVN file systems or specialized file systems from the
Jeffrey Yasskin 2013/10/08 17:46:05 This seems like it still belongs on _Create. You s
not at google - send to devlin 2013/10/08 18:27:37 Done.
+ 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 self._offline:
+ file_system = OfflineFileSystem(file_system)
+ return CachingFileSystem(file_system, self._object_store_creator)
+
+ @staticmethod
Jeffrey Yasskin 2013/10/08 17:46:05 If these had been @classmethod, you wouldn't have
not at google - send to devlin 2013/10/08 18:27:37 that sounds like a nice pattern in general, thanks
+ def ForLocal(object_store_creator):
+ '''Used in creating a server instance on localhost.
+ '''
+ return HostFileSystemProvider(
+ object_store_creator,
+ constructor_for_test=lambda **_: LocalFileSystem.Create())
Jeffrey Yasskin 2013/10/08 17:46:05 'constructor_for_test' seems like the wrong name i
not at google - send to devlin 2013/10/08 18:27:37 Local only makes sense when testing (or when runni
+
+ @staticmethod
+ def ForTest(file_system, object_store_creator):
+ '''Used in creating a test server instance. The HostFileSystemProvider
+ returned here will always return |file_system| when its Create() method is
+ called.
+ '''
+ return HostFileSystemProvider(
+ object_store_creator,
+ constructor_for_test=lambda **_: file_system)

Powered by Google App Engine
This is Rietveld 408576698