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

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

Issue 10546078: Extension docs server: APIDataSource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 logging 16 import logging
17 import urlfetch 17 import urlfetch
18 18
19 from google.appengine.ext import webapp 19 from google.appengine.ext import webapp
20 from google.appengine.ext.webapp.util import run_wsgi_app 20 from google.appengine.ext.webapp.util import run_wsgi_app
21 21
22 from api_data_source import APIDataSource
22 from local_fetcher import LocalFetcher 23 from local_fetcher import LocalFetcher
23 from server_instance import ServerInstance 24 from server_instance import ServerInstance
24 from subversion_fetcher import SubversionFetcher 25 from subversion_fetcher import SubversionFetcher
25 from template_data_source import TemplateDataSource 26 from template_data_source import TemplateDataSource
26 27
27 EXTENSIONS_PATH = 'chrome/common/extensions/' 28 EXTENSIONS_PATH = 'chrome/common/extensions/'
28 DOCS_PATH = 'docs/' 29 DOCS_PATH = 'docs/'
30 API_PATH = 'api/'
29 PUBLIC_TEMPLATE_PATH = DOCS_PATH + 'template2/public/' 31 PUBLIC_TEMPLATE_PATH = DOCS_PATH + 'template2/public/'
30 PRIVATE_TEMPLATE_PATH = DOCS_PATH + 'template2/private/' 32 PRIVATE_TEMPLATE_PATH = DOCS_PATH + 'template2/private/'
31 33
32 # Global cache of instances because the Server is recreated for every request. 34 # Global cache of instances because the Server is recreated for every request.
33 SERVER_INSTANCES = {} 35 SERVER_INSTANCES = {}
34 36
35 class Server(webapp.RequestHandler): 37 class Server(webapp.RequestHandler):
36 def _GetInstanceForBranch(self, branch): 38 def _GetInstanceForBranch(self, branch):
37 if branch in SERVER_INSTANCES: 39 if branch in SERVER_INSTANCES:
38 return SERVER_INSTANCES[branch] 40 return SERVER_INSTANCES[branch]
39 if branch == 'local': 41 if branch == 'local':
40 fetcher = LocalFetcher(EXTENSIONS_PATH) 42 fetcher = LocalFetcher(EXTENSIONS_PATH)
41 # No cache for local doc server. 43 # No cache for local doc server.
42 cache_timeout_seconds = 0 44 cache_timeout_seconds = 0
43 else: 45 else:
44 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) 46 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch)
45 cache_timeout_seconds = 300 47 cache_timeout_seconds = 300
46 data_source = TemplateDataSource( 48 template_data_source = TemplateDataSource(
47 fetcher, 49 fetcher,
48 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH], 50 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH],
49 cache_timeout_seconds) 51 cache_timeout_seconds)
50 SERVER_INSTANCES[branch] = ServerInstance(data_source, fetcher) 52 api_data_source = APIDataSource(fetcher, [API_PATH], cache_timeout_seconds)
53 SERVER_INSTANCES[branch] = ServerInstance(
54 api_data_source,
55 template_data_source,
56 fetcher)
51 return SERVER_INSTANCES[branch] 57 return SERVER_INSTANCES[branch]
52 58
53 def _HandleRequest(self, path): 59 def _HandleRequest(self, path):
54 channel_name = branch_utility.GetChannelNameFromPath(path) 60 channel_name = branch_utility.GetChannelNameFromPath(path)
55 branch = branch_utility.GetBranchNumberForChannelName(channel_name, 61 branch = branch_utility.GetBranchNumberForChannelName(channel_name,
56 urlfetch) 62 urlfetch)
57 self._GetInstanceForBranch(branch).Run(path, self) 63 self._GetInstanceForBranch(branch).Run(path, self)
58 64
59 def get(self): 65 def get(self):
60 path = self.request.path 66 path = self.request.path
61 path = path.replace('/chrome/extensions/', '') 67 path = path.replace('/chrome/extensions/', '')
62 if len(path) > 0 and path[0] == '/': 68 if len(path) > 0 and path[0] == '/':
63 path = path.strip('/') 69 path = path.strip('/')
64 self._HandleRequest(path) 70 self._HandleRequest(path)
65 71
66 def main(): 72 def main():
67 handlers = [ 73 handlers = [
68 ('/.*', Server), 74 ('/.*', Server),
69 ] 75 ]
70 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) 76 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False))
71 77
72 78
73 if __name__ == '__main__': 79 if __name__ == '__main__':
74 main() 80 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698