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

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

Issue 10828042: Extensions Docs Server: Integration testing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved logic into server instance Created 8 years, 5 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/server_instance.py
diff --git a/chrome/common/extensions/docs/server2/server_instance.py b/chrome/common/extensions/docs/server2/server_instance.py
index c8ebe85b61db73f21ec19a4a0d1bb04d7f7010be..02bb542e26c704d4a1b4f07e770748503e9eb11e 100644
--- a/chrome/common/extensions/docs/server2/server_instance.py
+++ b/chrome/common/extensions/docs/server2/server_instance.py
@@ -6,8 +6,83 @@ from fnmatch import fnmatch
import mimetypes
import os
+from api_data_source import APIDataSource
+from api_list_data_source import APIListDataSource
+from appengine_memcache import AppEngineMemcache
+from example_zipper import ExampleZipper
+from file_system_cache import FileSystemCache
+from intro_data_source import IntroDataSource
+from local_file_system import LocalFileSystem
+from memcache_file_system import MemcacheFileSystem
+from samples_data_source import SamplesDataSource
+from subversion_file_system import SubversionFileSystem
+from template_data_source import TemplateDataSource
+from appengine_url_fetcher import AppEngineUrlFetcher
+
STATIC_DIR_PREFIX = 'docs/server2'
-DOCS_PREFIX = 'docs'
+EXTENSIONS_PATH = 'chrome/common/extensions'
+DOCS_PATH = 'docs'
+API_PATH = 'api'
+INTRO_PATH = DOCS_PATH + '/server2/templates/intros'
+ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles'
+PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public'
+PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private'
+EXAMPLES_PATH = DOCS_PATH + '/examples'
+FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH
+
+# The branch that the server will default to when no branch is specified in the
+# URL. This is necessary because it is not possible to pass flags to the script
+# handler.
+DEFAULT_BRANCH = 'local'
+
+# Global cache of instances because Handler is recreated for every request.
+SERVER_INSTANCES = {}
+
+def GetInstanceForBranch(branch,
+ memcache,
+ urlfetch,
+ local_path=EXTENSIONS_PATH):
+ if branch in SERVER_INSTANCES:
+ return SERVER_INSTANCES[branch]
+ if branch == 'local':
+ file_system = LocalFileSystem(local_path)
+ else:
+ fetcher = AppEngineUrlFetcher(
+ _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH,
+ urlfetch)
+ file_system = MemcacheFileSystem(SubversionFileSystem(fetcher),
+ AppEngineMemcache(branch, memcache))
+
+ cache_builder = FileSystemCache.Builder(file_system)
+ api_data_source = APIDataSource(cache_builder, API_PATH)
+ api_list_data_source = APIListDataSource(cache_builder,
+ file_system,
+ API_PATH,
+ PUBLIC_TEMPLATE_PATH)
+ intro_data_source = IntroDataSource(cache_builder,
+ [INTRO_PATH, ARTICLE_PATH])
+ samples_data_source_factory = SamplesDataSource.Factory(branch,
+ file_system,
+ cache_builder,
+ EXAMPLES_PATH)
+ template_data_source_factory = TemplateDataSource.Factory(
+ branch,
+ api_data_source,
+ api_list_data_source,
+ intro_data_source,
+ samples_data_source_factory,
+ cache_builder,
+ PUBLIC_TEMPLATE_PATH,
+ PRIVATE_TEMPLATE_PATH)
+ example_zipper = ExampleZipper(file_system,
+ cache_builder,
+ DOCS_PATH,
+ EXAMPLES_PATH)
+ SERVER_INSTANCES[branch] = ServerInstance(
+ template_data_source_factory,
+ example_zipper,
+ cache_builder)
+ return SERVER_INSTANCES[branch]
class ServerInstance(object):
"""This class is used to hold a data source and fetcher for an instance of a
@@ -40,7 +115,7 @@ class ServerInstance(object):
content = self._example_zipper.Create(path[:-len('.zip')])
response.headers['content-type'] = mimetypes.types_map['.zip']
elif path.startswith('examples/'):
- content = self._cache.GetFromFile(DOCS_PREFIX + '/' + path)
+ content = self._cache.GetFromFile(DOCS_PATH + '/' + path)
response.headers['content-type'] = 'text/plain'
elif path.startswith('static/'):
content = self._FetchStaticResource(path, response)

Powered by Google App Engine
This is Rietveld 408576698