Index: chrome/common/extensions/docs/server2/handler.py |
diff --git a/chrome/common/extensions/docs/server2/handler.py b/chrome/common/extensions/docs/server2/handler.py |
index 1adb106ea9aa53766fb8586933ff5dd2a3af36f9..1099a9a5b0b6427ab02ecd162532c3cb9c2641a1 100644 |
--- a/chrome/common/extensions/docs/server2/handler.py |
+++ b/chrome/common/extensions/docs/server2/handler.py |
@@ -14,13 +14,15 @@ from appengine_wrappers import urlfetch |
from api_data_source import APIDataSource |
from api_list_data_source import APIListDataSource |
from appengine_blobstore import AppEngineBlobstore |
-from in_memory_object_store import InMemoryObjectStore |
from appengine_url_fetcher import AppEngineUrlFetcher |
+from availability_data_source import AvailabilityDataSource |
from branch_utility import BranchUtility |
-from example_zipper import ExampleZipper |
+from chrome_version_data_source import ChromeVersionDataSource |
from compiled_file_system import CompiledFileSystem |
import compiled_file_system as compiled_fs |
+from example_zipper import ExampleZipper |
from github_file_system import GithubFileSystem |
+from in_memory_object_store import InMemoryObjectStore |
from intro_data_source import IntroDataSource |
from known_issues_data_source import KnownIssuesDataSource |
from local_file_system import LocalFileSystem |
@@ -36,7 +38,7 @@ import url_constants |
# Increment this version to force the server to reload all pages in the first |
# cron job that is run. |
-_VERSION = 1 |
+_VERSION = 2 |
# The default channel to serve docs for if no channel is specified. |
_DEFAULT_CHANNEL = 'stable' |
@@ -46,6 +48,9 @@ BRANCH_UTILITY = BranchUtility(url_constants.OMAHA_PROXY_URL, |
AppEngineUrlFetcher(None), |
BRANCH_UTILITY_MEMCACHE) |
+AVAILABILITY_DATA_SOURCE_MEMCACHE = InMemoryObjectStore( |
+ 'availability_data_source') |
+ |
GITHUB_MEMCACHE = InMemoryObjectStore('github') |
GITHUB_FILE_SYSTEM = GithubFileSystem( |
AppEngineUrlFetcher(url_constants.GITHUB_URL), |
@@ -84,7 +89,89 @@ def _CreateMemcacheFileSystem(branch, branch_memcache): |
return MemcacheFileSystem(SubversionFileSystem(fetcher, stat_fetcher), |
branch_memcache) |
-_default_branch = BRANCH_UTILITY.GetBranchNumberForChannelName(_DEFAULT_CHANNEL) |
+def _CreateAPIDataSourceForBranch(branch_number): |
+ return _CreateObjectsForBranch(branch_number, None) |
+ |
+def _CreateInstanceForBranch(branch_number, channel_info): |
+ return _CreateObjectsForBranch(branch_number, channel_info) |
+ |
+def _CreateObjectsForBranch(branch_number, channel_info=None): |
+ """Passed to the global instance of chrome_version_data_source, and also used |
+ in _GetInstanceForBranch. Allows for the creation of api_data_sources linked |
+ to |branch_number|, which is the maximum branch number from a given version of |
+ chrome, and the creation of a branch instance. |
+ """ |
+ channel_name = _DEFAULT_CHANNEL |
+ availability_data_source = None |
+ instance = None |
+ |
+ if channel_info is not None: |
+ channel_name = channel_info['name'] |
+ availability_data_source = AvailabilityDataSource( |
+ CHROME_VERSION_DATA_SOURCE, |
+ channel_info['version'], |
+ AVAILABILITY_DATA_SOURCE_MEMCACHE) |
+ |
+ branch_memcache = InMemoryObjectStore(branch_number) |
+ file_system = _CreateMemcacheFileSystem(branch_number, branch_memcache) |
+ cache_factory = CompiledFileSystem.Factory(file_system, branch_memcache) |
+ api_list_data_source_factory = APIListDataSource.Factory( |
+ cache_factory, |
+ file_system, |
+ API_PATH, |
+ PUBLIC_TEMPLATE_PATH) |
+ api_data_source_factory = APIDataSource.Factory(cache_factory, |
+ API_PATH, |
+ availability_data_source) |
+ # Give the ReferenceResolver a memcache, to speed up the lookup of |
+ # duplicate $refs. |
+ ref_resolver_factory = ReferenceResolver.Factory( |
+ api_data_source_factory, |
+ api_list_data_source_factory, |
+ branch_memcache) |
+ api_data_source_factory.SetReferenceResolverFactory(ref_resolver_factory) |
+ samples_data_source_factory = SamplesDataSource.Factory( |
+ channel_name, |
+ file_system, |
+ GITHUB_FILE_SYSTEM, |
+ cache_factory, |
+ GITHUB_COMPILED_FILE_SYSTEM, |
+ ref_resolver_factory, |
+ EXAMPLES_PATH) |
+ api_data_source_factory.SetSamplesDataSourceFactory( |
+ samples_data_source_factory) |
+ |
+ if channel_info is not None: |
+ intro_data_source_factory = IntroDataSource.Factory( |
+ cache_factory, |
+ ref_resolver_factory, |
+ [INTRO_PATH, ARTICLE_PATH]) |
+ sidenav_data_source_factory = SidenavDataSource.Factory(cache_factory, |
+ JSON_PATH) |
+ template_data_source_factory = TemplateDataSource.Factory( |
+ channel_name, |
+ api_data_source_factory, |
+ api_list_data_source_factory, |
+ intro_data_source_factory, |
+ samples_data_source_factory, |
+ KNOWN_ISSUES_DATA_SOURCE, |
+ sidenav_data_source_factory, |
+ cache_factory, |
+ ref_resolver_factory, |
+ PUBLIC_TEMPLATE_PATH, |
+ PRIVATE_TEMPLATE_PATH, |
+ BRANCH_UTILITY.GetChannelInfoForAllChannels()) |
+ example_zipper = ExampleZipper(file_system, |
+ cache_factory, |
+ DOCS_PATH) |
+ instance = ServerInstance(template_data_source_factory, |
+ example_zipper, |
+ cache_factory) |
+ return instance |
+ return api_data_source_factory.Create(None) |
not at google - send to devlin
2013/04/02 10:29:39
divergent return types is super confusing, took me
epeterson
2013/04/03 03:59:57
The ChromeVersionDataSource needed a way to create
|
+ |
+_default_branch = BRANCH_UTILITY.GetChannelInfoForChannelName( |
+ _DEFAULT_CHANNEL)['branch'] |
APPS_MEMCACHE = InMemoryObjectStore(_default_branch) |
APPS_FILE_SYSTEM = _CreateMemcacheFileSystem(_default_branch, APPS_MEMCACHE) |
APPS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( |
@@ -102,11 +189,19 @@ KNOWN_ISSUES_DATA_SOURCE = KnownIssuesDataSource( |
InMemoryObjectStore('KnownIssues'), |
AppEngineUrlFetcher(None)) |
+CHROME_VERSION_DATA_SOURCE = ChromeVersionDataSource( |
+ url_constants.OMAHA_BETA_HISTORY, |
+ AppEngineUrlFetcher(None), |
+ InMemoryObjectStore('chrome_version_data_source'), |
+ _CreateAPIDataSourceForBranch) |
+ |
def _MakeInstanceKey(branch, number): |
return '%s/%s' % (branch, number) |
def _GetInstanceForBranch(channel_name, local_path): |
epeterson
2013/04/03 03:59:57
This local_path doesn't seem to be used anywhere (
|
- branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) |
+ channel_info = BRANCH_UTILITY.GetChannelInfoForChannelName( |
+ channel_name) |
+ branch = channel_info['branch'] |
# The key for the server is a tuple of |channel_name| with |branch|, since |
# sometimes stable and beta point to the same branch. |
@@ -115,60 +210,9 @@ def _GetInstanceForBranch(channel_name, local_path): |
if instance is not None: |
return instance |
- branch_memcache = InMemoryObjectStore(branch) |
- file_system = _CreateMemcacheFileSystem(branch, branch_memcache) |
- cache_factory = CompiledFileSystem.Factory(file_system, branch_memcache) |
- api_list_data_source_factory = APIListDataSource.Factory(cache_factory, |
- file_system, |
- API_PATH, |
- PUBLIC_TEMPLATE_PATH) |
- api_data_source_factory = APIDataSource.Factory( |
- cache_factory, |
- API_PATH) |
- |
- # Give the ReferenceResolver a memcache, to speed up the lookup of |
- # duplicate $refs. |
- ref_resolver_factory = ReferenceResolver.Factory( |
- api_data_source_factory, |
- api_list_data_source_factory, |
- branch_memcache) |
- api_data_source_factory.SetReferenceResolverFactory(ref_resolver_factory) |
- samples_data_source_factory = SamplesDataSource.Factory( |
- channel_name, |
- file_system, |
- GITHUB_FILE_SYSTEM, |
- cache_factory, |
- GITHUB_COMPILED_FILE_SYSTEM, |
- ref_resolver_factory, |
- EXAMPLES_PATH) |
- api_data_source_factory.SetSamplesDataSourceFactory( |
- samples_data_source_factory) |
- intro_data_source_factory = IntroDataSource.Factory( |
- cache_factory, |
- ref_resolver_factory, |
- [INTRO_PATH, ARTICLE_PATH]) |
- sidenav_data_source_factory = SidenavDataSource.Factory(cache_factory, |
- JSON_PATH) |
- template_data_source_factory = TemplateDataSource.Factory( |
- channel_name, |
- api_data_source_factory, |
- api_list_data_source_factory, |
- intro_data_source_factory, |
- samples_data_source_factory, |
- KNOWN_ISSUES_DATA_SOURCE, |
- sidenav_data_source_factory, |
- cache_factory, |
- ref_resolver_factory, |
- PUBLIC_TEMPLATE_PATH, |
- PRIVATE_TEMPLATE_PATH) |
- example_zipper = ExampleZipper(file_system, |
- cache_factory, |
- DOCS_PATH) |
- |
- instance = ServerInstance(template_data_source_factory, |
- example_zipper, |
- cache_factory) |
+ instance = _CreateInstanceForBranch(branch, channel_info) |
SERVER_INSTANCES[instance_key] = instance |
+ |
return instance |
def _CleanBranches(): |
@@ -226,7 +270,6 @@ class Handler(webapp.RequestHandler): |
_GetInstanceForBranch(channel_name, self._local_path).Get(real_path, |
self.request, |
self.response) |
- |
def _Render(self, files, channel): |
original_response = self.response |
for f in files: |
@@ -266,7 +309,7 @@ class Handler(webapp.RequestHandler): |
# be called. The same is then done separately with the apps samples page, |
# since it pulls its data from Github. |
channel = path.split('/')[-1] |
- branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel) |
+ branch = BRANCH_UTILITY.GetChannelInfoForChannelName(channel)['branch'] |
logging.info('Running cron job for %s.' % branch) |
branch_memcache = InMemoryObjectStore(branch) |
file_system = _CreateMemcacheFileSystem(branch, branch_memcache) |