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

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

Issue 10828042: Extensions Docs Server: Integration testing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for CQ 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/handler.py
diff --git a/chrome/common/extensions/docs/server2/echo_handler.py b/chrome/common/extensions/docs/server2/handler.py
similarity index 50%
rename from chrome/common/extensions/docs/server2/echo_handler.py
rename to chrome/common/extensions/docs/server2/handler.py
index c94c412157fc3a3b8c14442d315128e02824476d..e18b0ec8414cfba16cd489ae717a7fac0617e22e 100755
--- a/chrome/common/extensions/docs/server2/echo_handler.py
+++ b/chrome/common/extensions/docs/server2/handler.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
# Copyright (c) 2012 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.
@@ -7,19 +6,14 @@ import logging
import os
import sys
-# Add the original server location to sys.path so we are able to import
-# modules from there.
-SERVER_PATH = 'chrome/common/extensions/docs/server2'
-if os.path.abspath(SERVER_PATH) not in sys.path:
- sys.path.append(os.path.abspath(SERVER_PATH))
-
-from google.appengine.ext import webapp
-from google.appengine.api import memcache
-from google.appengine.ext.webapp.util import run_wsgi_app
+from appengine_wrappers import webapp
+from appengine_wrappers import memcache
+from appengine_wrappers import urlfetch
from api_data_source import APIDataSource
from api_list_data_source import APIListDataSource
from appengine_memcache import AppEngineMemcache
+from appengine_url_fetcher import AppEngineUrlFetcher
from branch_utility import BranchUtility
from example_zipper import ExampleZipper
from file_system_cache import FileSystemCache
@@ -32,10 +26,22 @@ from subversion_file_system import SubversionFileSystem
from template_data_source import TemplateDataSource
from appengine_url_fetcher import AppEngineUrlFetcher
+# 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'
+
SVN_URL = 'http://src.chromium.org/chrome'
TRUNK_URL = SVN_URL + '/trunk'
BRANCH_URL = SVN_URL + '/branches'
+OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json'
+BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL,
+ DEFAULT_BRANCH,
+ AppEngineUrlFetcher(''),
+ AppEngineMemcache('branch_utility'))
+
+STATIC_DIR_PREFIX = 'docs/server2'
EXTENSIONS_PATH = 'chrome/common/extensions'
DOCS_PATH = 'docs'
API_PATH = 'api'
@@ -46,19 +52,50 @@ 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 = {}
-OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json'
-BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL,
- DEFAULT_BRANCH,
- AppEngineUrlFetcher(''),
- AppEngineMemcache('branch_utility', memcache))
+def _GetInstanceForBranch(branch, local_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)
+ file_system = MemcacheFileSystem(SubversionFileSystem(fetcher),
+ AppEngineMemcache(branch))
+
+ 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]
def _GetURLFromBranch(branch):
if branch == 'trunk':
@@ -66,56 +103,28 @@ def _GetURLFromBranch(branch):
return BRANCH_URL + '/' + branch + '/src'
class Handler(webapp.RequestHandler):
- def _GetInstanceForBranch(self, branch):
- if branch in SERVER_INSTANCES:
- return SERVER_INSTANCES[branch]
- if branch == 'local':
- file_system = LocalFileSystem(EXTENSIONS_PATH)
- else:
- fetcher = AppEngineUrlFetcher(
- _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH)
- file_system = MemcacheFileSystem(SubversionFileSystem(fetcher),
- AppEngineMemcache(branch, memcache))
+ def __init__(self, request, response, local_path=EXTENSIONS_PATH):
+ self._local_path = local_path
+ super(Handler, self).__init__(request, response)
- 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]
+ def _NavigateToPath(self, path):
+ channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path)
+ branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name)
+ if real_path == '':
+ real_path = 'index.html'
+ # TODO: This leaks Server instances when branch bumps.
+ _GetInstanceForBranch(branch, self._local_path).Get(real_path,
+ self.request,
+ self.response)
def get(self):
path = self.request.path
if '_ah/warmup' in path:
logging.info('Warmup request.')
- self.get('/chrome/extensions/trunk/samples.html')
- self.get('/chrome/extensions/dev/samples.html')
- self.get('/chrome/extensions/beta/samples.html')
- self.get('/chrome/extensions/stable/samples.html')
+ self._NavigateToPath('trunk/samples.html')
+ self._NavigateToPath('dev/samples.html')
+ self._NavigateToPath('beta/samples.html')
+ self._NavigateToPath('stable/samples.html')
return
# Redirect paths like "directory" to "directory/". This is so relative file
@@ -124,18 +133,4 @@ class Handler(webapp.RequestHandler):
self.redirect(path + '/')
path = path.replace('/chrome/extensions/', '')
path = path.strip('/')
-
- channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path)
- branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name)
- if real_path == '':
- real_path = 'index.html'
- # TODO: This leaks Server instances when branch bumps.
- self._GetInstanceForBranch(branch).Get(real_path,
- self.request,
- self.response)
-
-def main():
- run_wsgi_app(webapp.WSGIApplication([('/.*', Handler)], debug=False))
-
-if __name__ == '__main__':
- main()
+ self._NavigateToPath(path)

Powered by Google App Engine
This is Rietveld 408576698