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

Side by Side Diff: chrome/common/extensions/docs/server2/echo_handler.py

Issue 10689144: Extensions Docs Server: Samples zip files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
not at google - send to devlin 2012/07/11 00:35:09 At what point do we rename this file from echo_han
cduvall 2012/07/11 20:56:30 Yeah definitely no longer an echo handler. echo_ha
5 5
6 import sys 6 import sys
7 import os 7 import os
8 8
9 # Add the original server location to sys.path so we are able to import 9 # Add the original server location to sys.path so we are able to import
10 # modules from there. 10 # modules from there.
11 SERVER_PATH = 'chrome/common/extensions/docs/server2' 11 SERVER_PATH = 'chrome/common/extensions/docs/server2'
12 if os.path.abspath(SERVER_PATH) not in sys.path: 12 if os.path.abspath(SERVER_PATH) not in sys.path:
13 sys.path.append(os.path.abspath(SERVER_PATH)) 13 sys.path.append(os.path.abspath(SERVER_PATH))
14 14
15 import branch_utility 15 import branch_utility
16 import urlfetch 16 import urlfetch
17 17
18 from google.appengine.ext import webapp 18 from google.appengine.ext import webapp
19 from google.appengine.ext.webapp.util import run_wsgi_app 19 from google.appengine.ext.webapp.util import run_wsgi_app
20 20
21 from api_data_source import APIDataSource 21 from api_data_source import APIDataSource
22 from fetcher_cache import FetcherCache 22 from fetcher_cache import FetcherCache
23 from intro_data_source import IntroDataSource 23 from intro_data_source import IntroDataSource
24 from local_fetcher import LocalFetcher 24 from local_fetcher import LocalFetcher
25 from server_instance import ServerInstance 25 from server_instance import ServerInstance
26 from subversion_fetcher import SubversionFetcher 26 from subversion_fetcher import SubversionFetcher
27 from template_data_source import TemplateDataSource 27 from template_data_source import TemplateDataSource
28 from zip_data_source import ZipDataSource
28 29
29 EXTENSIONS_PATH = 'chrome/common/extensions' 30 EXTENSIONS_PATH = 'chrome/common/extensions'
30 DOCS_PATH = 'docs' 31 DOCS_PATH = 'docs'
31 API_PATH = 'api' 32 API_PATH = 'api'
32 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' 33 INTRO_PATH = DOCS_PATH + '/server2/templates/intros'
33 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' 34 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public'
34 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' 35 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private'
36 ZIP_IGNORE_PATH = EXTENSIONS_PATH + '/' + DOCS_PATH
not at google - send to devlin 2012/07/11 00:35:09 The ignore path is prefix that should be stripped
cduvall 2012/07/11 20:56:30 Done.
35 37
36 # The branch that the server will default to when no branch is specified in the 38 # The branch that the server will default to when no branch is specified in the
37 # URL. This is necessary because it is not possible to pass flags to the script 39 # URL. This is necessary because it is not possible to pass flags to the script
38 # handler. 40 # handler.
39 DEFAULT_BRANCH = 'local' 41 DEFAULT_BRANCH = 'local'
40 42
41 # Global cache of instances because the Server is recreated for every request. 43 # Global cache of instances because the Server is recreated for every request.
42 SERVER_INSTANCES = {} 44 SERVER_INSTANCES = {}
43 45
44 class Server(webapp.RequestHandler): 46 class Server(webapp.RequestHandler):
45 def _GetInstanceForBranch(self, branch): 47 def _GetInstanceForBranch(self, branch):
46 if branch in SERVER_INSTANCES: 48 if branch in SERVER_INSTANCES:
47 return SERVER_INSTANCES[branch] 49 return SERVER_INSTANCES[branch]
48 if branch == 'local': 50 if branch == 'local':
49 fetcher = LocalFetcher(EXTENSIONS_PATH) 51 fetcher = LocalFetcher(EXTENSIONS_PATH)
50 # No cache for local doc server. 52 # No cache for local doc server.
51 cache_timeout_seconds = 0 53 cache_timeout_seconds = 0
52 else: 54 else:
53 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) 55 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch)
54 cache_timeout_seconds = 300 56 cache_timeout_seconds = 300
55 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) 57 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds)
56 api_data_source = APIDataSource(cache_builder, API_PATH) 58 api_data_source = APIDataSource(cache_builder, API_PATH)
57 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH) 59 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH)
58 template_data_source = TemplateDataSource( 60 template_data_source = TemplateDataSource(
59 branch, 61 branch,
60 api_data_source, 62 api_data_source,
61 intro_data_source, 63 intro_data_source,
62 cache_builder, 64 cache_builder,
63 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) 65 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH])
66 zip_data_source = ZipDataSource(cache_builder, DOCS_PATH, ZIP_IGNORE_PATH)
64 SERVER_INSTANCES[branch] = ServerInstance( 67 SERVER_INSTANCES[branch] = ServerInstance(
65 template_data_source, 68 template_data_source,
69 zip_data_source,
66 cache_builder) 70 cache_builder)
67 return SERVER_INSTANCES[branch] 71 return SERVER_INSTANCES[branch]
68 72
69 def _HandleRequest(self, path): 73 def _HandleRequest(self, path):
70 channel_name, real_path = ( 74 channel_name, real_path = (
71 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH)) 75 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH))
72 branch = branch_utility.GetBranchNumberForChannelName(channel_name, 76 branch = branch_utility.GetBranchNumberForChannelName(channel_name,
73 urlfetch) 77 urlfetch)
74 if real_path == '': 78 if real_path == '':
75 real_path = 'index.html' 79 real_path = 'index.html'
(...skipping 11 matching lines...) Expand all
87 91
88 def main(): 92 def main():
89 handlers = [ 93 handlers = [
90 ('/.*', Server), 94 ('/.*', Server),
91 ] 95 ]
92 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) 96 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False))
93 97
94 98
95 if __name__ == '__main__': 99 if __name__ == '__main__':
96 main() 100 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698