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

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

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up 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/echo_handler.py
diff --git a/chrome/common/extensions/docs/server2/echo_handler.py b/chrome/common/extensions/docs/server2/echo_handler.py
index c962a9073414f61772743531c7c2b9a23483c435..c068556e0636b2b7353aee56fff167fd046388ef 100755
--- a/chrome/common/extensions/docs/server2/echo_handler.py
+++ b/chrome/common/extensions/docs/server2/echo_handler.py
@@ -3,8 +3,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import sys
+import logging
import os
+import sys
# Add the original server location to sys.path so we are able to import
# modules from there.
@@ -12,21 +13,27 @@ 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))
-import branch_utility
-import urlfetch
-
from google.appengine.ext import webapp
+from google.appengine.api import memcache
from google.appengine.ext.webapp.util import run_wsgi_app
from api_data_source import APIDataSource
-from fetcher_cache import FetcherCache
+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_fetcher import LocalFetcher
+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_fetcher import SubversionFetcher
+from subversion_file_system import SubversionFileSystem
from template_data_source import TemplateDataSource
-from example_zipper import ExampleZipper
+from appengine_url_fetcher import AppEngineUrlFetcher
+
+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'
@@ -35,7 +42,7 @@ 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 = 'examples'
+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
@@ -46,22 +53,34 @@ DEFAULT_BRANCH = 'local'
# Global cache of instances because the Server 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 _GetURLFromBranch(branch):
+ if branch == 'trunk':
+ return TRUNK_URL + '/src'
+ return BRANCH_URL + '/' + branch + '/src'
+
class Server(webapp.RequestHandler):
def _GetInstanceForBranch(self, branch):
if branch in SERVER_INSTANCES:
return SERVER_INSTANCES[branch]
if branch == 'local':
- fetcher = LocalFetcher(EXTENSIONS_PATH)
- # No cache for local doc server.
- cache_timeout_seconds = 0
+ file_system = LocalFileSystem(EXTENSIONS_PATH)
else:
- fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch)
- cache_timeout_seconds = 300
- cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds)
+ 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)
intro_data_source = IntroDataSource(cache_builder,
[INTRO_PATH, ARTICLE_PATH])
- samples_data_source = SamplesDataSource(fetcher,
+ samples_data_source = SamplesDataSource(file_system,
cache_builder,
EXAMPLES_PATH)
template_data_source = TemplateDataSource(
@@ -71,7 +90,7 @@ class Server(webapp.RequestHandler):
samples_data_source,
cache_builder,
[PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH])
- example_zipper = ExampleZipper(fetcher,
+ example_zipper = ExampleZipper(file_system,
cache_builder,
DOCS_PATH,
EXAMPLES_PATH)
@@ -82,16 +101,22 @@ class Server(webapp.RequestHandler):
return SERVER_INSTANCES[branch]
def _HandleRequest(self, path):
- channel_name, real_path = (
- branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH))
- branch = branch_utility.GetBranchNumberForChannelName(channel_name,
- urlfetch)
+ 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)
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')
+ return
# Redirect paths like "directory" to "directory/". This is so relative file
# paths will know to treat this as a directory.
if os.path.splitext(path)[1] == '' and path[-1] != '/':
« no previous file with comments | « chrome/common/extensions/docs/server2/build_server.py ('k') | chrome/common/extensions/docs/server2/example_zipper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698