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..136be18a53d584347741c3d45ef0fab088c5376a 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('', urlfetch), |
+ AppEngineMemcache('branch_utility', memcache)) |
+ |
+STATIC_DIR_PREFIX = 'docs/server2' |
EXTENSIONS_PATH = 'chrome/common/extensions' |
DOCS_PATH = 'docs' |
API_PATH = 'api' |
@@ -46,19 +52,51 @@ 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, |
+ 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] |
def _GetURLFromBranch(branch): |
if branch == 'trunk': |
@@ -66,56 +104,22 @@ 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)) |
- |
- 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 __init__(self, request, response, local_path=EXTENSIONS_PATH): |
+ self._local_path = local_path |
+ super(Handler, self).__init__(request, 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.request.path = '/chrome/extensions/trunk/samples.html' |
+ self.get() |
+ self.request.path = '/chrome/extensions/dev/samples.html' |
+ self.get() |
+ self.request.path = '/chrome/extensions/beta/samples.html' |
+ self.get() |
+ self.request.path = '/chrome/extensions/stable/samples.html' |
+ self.get() |
not at google - send to devlin
2012/07/30 23:00:44
recursively calling get..?
Wow I didn't even noti
cduvall
2012/07/30 23:38:18
Done.
|
return |
# Redirect paths like "directory" to "directory/". This is so relative file |
@@ -130,12 +134,6 @@ class Handler(webapp.RequestHandler): |
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() |
+ _GetInstanceForBranch(branch, self._local_path).Get(real_path, |
+ self.request, |
+ self.response) |