| Index: chrome/common/extensions/docs/server2/server_instance.py
|
| diff --git a/chrome/common/extensions/docs/server2/server_instance.py b/chrome/common/extensions/docs/server2/server_instance.py
|
| index faf0d21fa1c4e8973ffc2b96e12471f7d38285a9..f7f83ba5f87a858d94bf85101bce901a840b6413 100644
|
| --- a/chrome/common/extensions/docs/server2/server_instance.py
|
| +++ b/chrome/common/extensions/docs/server2/server_instance.py
|
| @@ -31,50 +31,70 @@ from sidenav_data_source import SidenavDataSource
|
| from subversion_file_system import SubversionFileSystem
|
| import svn_constants
|
| from template_data_source import TemplateDataSource
|
| -from third_party.json_schema_compiler.memoize import memoize
|
| from third_party.json_schema_compiler.model import UnixName
|
| import url_constants
|
|
|
| def _IsSamplesDisabled():
|
| return IsDevServer()
|
|
|
| -class ServerInstance(object):
|
| - # Lazily create so we don't create github file systems unnecessarily in
|
| - # tests.
|
| - branch_utility = None
|
| - github_file_system = None
|
| +def _CreateBranchUtility(start_configuration):
|
| + return BranchUtility(
|
| + url_constants.OMAHA_PROXY_URL,
|
| + AppEngineUrlFetcher(),
|
| + ObjectStoreCreator.SharedFactory(GetAppVersion(),
|
| + start_configuration))
|
| +
|
| +def _CreateGithubFileSystem(start_configuration):
|
| + # Slight hack: creating a github file system is pointless if samples are
|
| + # disabled, since it's only used for apps samples.
|
| + if _IsSamplesDisabled():
|
| + return EmptyDirFileSystem()
|
| + return GithubFileSystem(
|
| + AppEngineUrlFetcher(url_constants.GITHUB_URL),
|
| + AppEngineBlobstore(),
|
| + ObjectStoreCreator.SharedFactory(GetAppVersion(),
|
| + start_configuration))
|
|
|
| +class ServerInstance(object):
|
| @staticmethod
|
| - @memoize
|
| - def GetOrCreateOffline(channel):
|
| - '''Gets/creates a local ServerInstance, meaning that only resources local to
|
| + def CreateOffline(channel,
|
| + host_file_system_type=SubversionFileSystem,
|
| + app_samples_file_system=None):
|
| + '''Creates a local ServerInstance, meaning that only resources local to
|
| the server - memcache, object store, etc, are queried. This amounts to not
|
| setting up the subversion nor github file systems.
|
| '''
|
| - branch_utility = ServerInstance._GetOrCreateBranchUtility()
|
| + start_configuration = ObjectStoreCreator.START_POPULATED
|
| +
|
| + branch_utility = _CreateBranchUtility(start_configuration)
|
| branch = branch_utility.GetBranchNumberForChannelName(channel)
|
| - object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(),
|
| - branch)
|
| + object_store_creator_factory = ObjectStoreCreator.Factory(
|
| + GetAppVersion(),
|
| + branch,
|
| + start_configuration)
|
| +
|
| + if app_samples_file_system is None:
|
| + app_samples_file_system = _CreateGithubFileSystem(start_configuration)
|
| +
|
| # No svn nor github file systems. Rely on the crons to fill the caches, and
|
| # for the caches to exist.
|
| return ServerInstance(
|
| channel,
|
| object_store_creator_factory,
|
| - CachingFileSystem(OfflineFileSystem(SubversionFileSystem),
|
| - object_store_creator_factory,
|
| - use_existing_values=True),
|
| - # TODO(kalman): convert GithubFileSystem to be wrappable in a
|
| - # CachingFileSystem so that it can be replaced with an
|
| - # OfflineFileSystem. Currently GFS doesn't set the child versions of
|
| - # stat requests so it doesn't.
|
| - ServerInstance._GetOrCreateGithubFileSystem())
|
| + CachingFileSystem(OfflineFileSystem(host_file_system_type),
|
| + object_store_creator_factory),
|
| + app_samples_file_system)
|
|
|
| @staticmethod
|
| - def CreateOnline(channel):
|
| + def CreateOnline(channel,
|
| + host_file_system=None,
|
| + app_samples_file_system=None):
|
| '''Creates/creates an online server instance, meaning that both local and
|
| subversion/github resources are queried.
|
| '''
|
| - branch_utility = ServerInstance._GetOrCreateBranchUtility()
|
| + start_configuration = ObjectStoreCreator.START_EMPTY
|
| +
|
| + branch_utility = _CreateBranchUtility(start_configuration)
|
| branch = branch_utility.GetBranchNumberForChannelName(channel)
|
|
|
| if branch == 'trunk':
|
| @@ -90,58 +110,43 @@ class ServerInstance(object):
|
| viewvc_url = svn_url.replace(url_constants.SVN_URL,
|
| url_constants.VIEWVC_URL)
|
|
|
| - object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(),
|
| - branch)
|
| + object_store_creator_factory = ObjectStoreCreator.Factory(
|
| + GetAppVersion(),
|
| + branch,
|
| + start_configuration)
|
|
|
| - svn_file_system = CachingFileSystem(
|
| - SubversionFileSystem(AppEngineUrlFetcher(svn_url),
|
| - AppEngineUrlFetcher(viewvc_url)),
|
| - object_store_creator_factory)
|
| + if host_file_system is None:
|
| + host_file_system = SubversionFileSystem(AppEngineUrlFetcher(svn_url),
|
| + AppEngineUrlFetcher(viewvc_url))
|
| + cached_host_file_system = CachingFileSystem(host_file_system,
|
| + object_store_creator_factory)
|
| +
|
| + if app_samples_file_system is None:
|
| + app_samples_file_system = _CreateGithubFileSystem(start_configuration)
|
|
|
| return ServerInstance(channel,
|
| object_store_creator_factory,
|
| - svn_file_system,
|
| - ServerInstance._GetOrCreateGithubFileSystem())
|
| + cached_host_file_system,
|
| + app_samples_file_system)
|
|
|
| @staticmethod
|
| - def CreateForTest(file_system):
|
| + def CreateForTest(host_file_system):
|
| return ServerInstance('test',
|
| ObjectStoreCreator.TestFactory(),
|
| - file_system,
|
| - None)
|
| -
|
| - @staticmethod
|
| - def _GetOrCreateBranchUtility():
|
| - if ServerInstance.branch_utility is None:
|
| - ServerInstance.branch_utility = BranchUtility(
|
| - url_constants.OMAHA_PROXY_URL,
|
| - AppEngineUrlFetcher())
|
| - return ServerInstance.branch_utility
|
| -
|
| - @staticmethod
|
| - def _GetOrCreateGithubFileSystem():
|
| - # Initialising github is pointless if samples are disabled, since it's only
|
| - # used for apps samples.
|
| - if ServerInstance.github_file_system is None:
|
| - if _IsSamplesDisabled():
|
| - ServerInstance.github_file_system = EmptyDirFileSystem()
|
| - else:
|
| - ServerInstance.github_file_system = GithubFileSystem(
|
| - AppEngineUrlFetcher(url_constants.GITHUB_URL),
|
| - AppEngineBlobstore())
|
| - return ServerInstance.github_file_system
|
| + host_file_system,
|
| + EmptyDirFileSystem())
|
|
|
| def __init__(self,
|
| channel,
|
| object_store_creator_factory,
|
| - svn_file_system,
|
| - github_file_system):
|
| - self.svn_file_system = svn_file_system
|
| + host_file_system,
|
| + app_samples_file_system):
|
| + self.host_file_system = host_file_system
|
|
|
| - self.github_file_system = github_file_system
|
| + self.app_samples_file_system = app_samples_file_system
|
|
|
| self.compiled_fs_factory = CompiledFileSystem.Factory(
|
| - svn_file_system,
|
| + host_file_system,
|
| object_store_creator_factory)
|
|
|
| self.api_list_data_source_factory = APIListDataSource.Factory(
|
| @@ -165,13 +170,13 @@ class ServerInstance(object):
|
| # async fetch, so disable them. If you actually want to test samples, then
|
| # good luck, and modify _IsSamplesDisabled at the top.
|
| if _IsSamplesDisabled():
|
| - svn_fs_for_samples = EmptyDirFileSystem()
|
| + extension_samples_fs = EmptyDirFileSystem()
|
| else:
|
| - svn_fs_for_samples = self.svn_file_system
|
| + extension_samples_fs = self.host_file_system
|
| self.samples_data_source_factory = SamplesDataSource.Factory(
|
| channel,
|
| - svn_fs_for_samples,
|
| - self.github_file_system,
|
| + extension_samples_fs,
|
| + self.app_samples_file_system,
|
| self.ref_resolver_factory,
|
| object_store_creator_factory,
|
| svn_constants.EXAMPLES_PATH)
|
|
|