Index: chrome/common/extensions/docs/server2/echo_handler.py |
diff --git a/chrome/common/extensions/docs/server2/echo_handler.py b/chrome/common/extensions/docs/server2/echo_handler.py |
index c94c412157fc3a3b8c14442d315128e02824476d..c4550b000c16299224db7ebc845c4f673ed8c7c7 100755 |
--- a/chrome/common/extensions/docs/server2/echo_handler.py |
+++ b/chrome/common/extensions/docs/server2/echo_handler.py |
@@ -15,48 +15,21 @@ if os.path.abspath(SERVER_PATH) not in sys.path: |
from google.appengine.ext import webapp |
from google.appengine.api import memcache |
+from google.appengine.api import urlfetch |
from google.appengine.ext.webapp.util import run_wsgi_app |
-from api_data_source import APIDataSource |
-from api_list_data_source import APIListDataSource |
from appengine_memcache import AppEngineMemcache |
-from branch_utility import BranchUtility |
-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 server_instance import ServerInstance |
-from subversion_file_system import SubversionFileSystem |
-from template_data_source import TemplateDataSource |
from appengine_url_fetcher import AppEngineUrlFetcher |
+from branch_utility import BranchUtility |
+import server_instance |
SVN_URL = 'http://src.chromium.org/chrome' |
TRUNK_URL = SVN_URL + '/trunk' |
BRANCH_URL = SVN_URL + '/branches' |
-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 = {} |
- |
OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json' |
BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL, |
- DEFAULT_BRANCH, |
+ server_instance.DEFAULT_BRANCH, |
AppEngineUrlFetcher(''), |
AppEngineMemcache('branch_utility', memcache)) |
@@ -66,48 +39,6 @@ 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 get(self): |
path = self.request.path |
if '_ah/warmup' in path: |
@@ -130,9 +61,11 @@ 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) |
+ server_instance.GetInstanceForBranch(branch, |
+ memcache, |
+ urlfetch).Get(real_path, |
+ self.request, |
+ self.response) |
not at google - send to devlin
2012/07/30 21:19:09
why can't you put *all* of this, besides main(), i
cduvall
2012/07/30 22:48:09
Done.
|
def main(): |
run_wsgi_app(webapp.WSGIApplication([('/.*', Handler)], debug=False)) |