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

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: Samples page with full links and descriptions 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.
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 example_zipper import ExampleZipper
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 EXAMPLES_PATH = 'examples'
37 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH
35 38
36 # The branch that the server will default to when no branch is specified in the 39 # 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 40 # URL. This is necessary because it is not possible to pass flags to the script
38 # handler. 41 # handler.
39 DEFAULT_BRANCH = 'local' 42 DEFAULT_BRANCH = 'local'
40 43
41 # Global cache of instances because the Server is recreated for every request. 44 # Global cache of instances because the Server is recreated for every request.
42 SERVER_INSTANCES = {} 45 SERVER_INSTANCES = {}
43 46
44 class Server(webapp.RequestHandler): 47 class Server(webapp.RequestHandler):
45 def _GetInstanceForBranch(self, branch): 48 def _GetInstanceForBranch(self, branch):
46 if branch in SERVER_INSTANCES: 49 if branch in SERVER_INSTANCES:
47 return SERVER_INSTANCES[branch] 50 return SERVER_INSTANCES[branch]
48 if branch == 'local': 51 if branch == 'local':
49 fetcher = LocalFetcher(EXTENSIONS_PATH) 52 fetcher = LocalFetcher(EXTENSIONS_PATH)
50 # No cache for local doc server. 53 # No cache for local doc server.
51 cache_timeout_seconds = 0 54 cache_timeout_seconds = 0
52 else: 55 else:
53 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) 56 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch)
54 cache_timeout_seconds = 300 57 cache_timeout_seconds = 300
55 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) 58 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds)
56 api_data_source = APIDataSource(cache_builder, API_PATH) 59 api_data_source = APIDataSource(cache_builder, API_PATH)
57 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH) 60 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH)
58 template_data_source = TemplateDataSource( 61 template_data_source = TemplateDataSource(
59 branch, 62 branch,
60 api_data_source, 63 api_data_source,
61 intro_data_source, 64 intro_data_source,
62 cache_builder, 65 cache_builder,
66 FULL_EXAMPLES_PATH,
63 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) 67 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH])
68 example_zipper = ExampleZipper(cache_builder, DOCS_PATH, EXAMPLES_PATH)
64 SERVER_INSTANCES[branch] = ServerInstance( 69 SERVER_INSTANCES[branch] = ServerInstance(
65 template_data_source, 70 template_data_source,
71 example_zipper,
66 cache_builder) 72 cache_builder)
67 return SERVER_INSTANCES[branch] 73 return SERVER_INSTANCES[branch]
68 74
69 def _HandleRequest(self, path): 75 def _HandleRequest(self, path):
70 channel_name, real_path = ( 76 channel_name, real_path = (
71 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH)) 77 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH))
72 branch = branch_utility.GetBranchNumberForChannelName(channel_name, 78 branch = branch_utility.GetBranchNumberForChannelName(channel_name,
73 urlfetch) 79 urlfetch)
74 if real_path == '': 80 if real_path == '':
75 real_path = 'index.html' 81 real_path = 'index.html'
(...skipping 11 matching lines...) Expand all
87 93
88 def main(): 94 def main():
89 handlers = [ 95 handlers = [
90 ('/.*', Server), 96 ('/.*', Server),
91 ] 97 ]
92 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) 98 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False))
93 99
94 100
95 if __name__ == '__main__': 101 if __name__ == '__main__':
96 main() 102 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698