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

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

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 8 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging 5 import logging
6 import os 6 import os
7 from StringIO import StringIO 7 from StringIO import StringIO
8 import traceback 8 import traceback
9 9
10 from appengine_wrappers import ( 10 from appengine_wrappers import (
11 DeadlineExceededError, IsDevServer, logservice, memcache, urlfetch, webapp) 11 DeadlineExceededError, IsDevServer, logservice, memcache, urlfetch, webapp)
12 from branch_utility import BranchUtility 12 from branch_utility import BranchUtility
13 from rietveld_utility import RietveldUtility
13 from server_instance import ServerInstance 14 from server_instance import ServerInstance
14 import svn_constants 15 import svn_constants
15 import time 16 import time
16 17
17 # The default channel to serve docs for if no channel is specified. 18 # The default channel to serve docs for if no channel is specified.
18 _DEFAULT_CHANNEL = 'stable' 19 _DEFAULT_CHANNEL = 'stable'
19 20
20 class Handler(webapp.RequestHandler): 21 class Handler(webapp.RequestHandler):
21 # AppEngine instances should never need to call out to SVN. That should only 22 # AppEngine instances should never need to call out to SVN. That should only
22 # ever be done by the cronjobs, which then write the result into DataStore, 23 # ever be done by the cronjobs, which then write the result into DataStore,
(...skipping 10 matching lines...) Expand all
33 # 34 #
34 # However, we can't expect users of preview.py nor the dev server to run a 35 # However, we can't expect users of preview.py nor the dev server to run a
35 # cronjob first, so, this is a hack allow that to be online all of the time. 36 # cronjob first, so, this is a hack allow that to be online all of the time.
36 # TODO(kalman): achieve this via proper dependency injection. 37 # TODO(kalman): achieve this via proper dependency injection.
37 ALWAYS_ONLINE = IsDevServer() 38 ALWAYS_ONLINE = IsDevServer()
38 39
39 def __init__(self, request, response): 40 def __init__(self, request, response):
40 super(Handler, self).__init__(request, response) 41 super(Handler, self).__init__(request, response)
41 42
42 def _HandleGet(self, path): 43 def _HandleGet(self, path):
43 channel_name, real_path = BranchUtility.SplitChannelNameFromPath(path) 44 channel_name, issue, real_path = (
not at google - send to devlin 2013/04/26 23:53:53 We only need to support 'trunk' here. Note for fut
方觉(Fang Jue) 2013/04/27 00:24:34 Yes. I know that. And SplitPatchFromPath will alwa
not at google - send to devlin 2013/04/27 00:45:30 Yep, as in when you pull this into its own servlet
45 RietveldUtility.SplitPatchFromPath(path))
46 if issue is None:
47 channel_name, real_path = BranchUtility.SplitChannelNameFromPath(path)
not at google - send to devlin 2013/04/26 23:53:53 I've just written https://codereview.chromium.org/
方觉(Fang Jue) 2013/04/27 00:24:34 I did take a look at it just now before I had brea
44 48
45 if channel_name == _DEFAULT_CHANNEL: 49 if channel_name == _DEFAULT_CHANNEL:
46 self.redirect('/%s' % real_path) 50 self.redirect('/%s' % real_path)
47 return 51 return
48 52
49 if channel_name is None: 53 if channel_name is None:
50 channel_name = _DEFAULT_CHANNEL 54 channel_name = _DEFAULT_CHANNEL
51 55
52 # TODO(kalman): Check if |path| is a directory and serve path/index.html 56 # TODO(kalman): Check if |path| is a directory and serve path/index.html
53 # rather than special-casing apps/extensions. 57 # rather than special-casing apps/extensions.
54 if real_path.strip('/') == 'apps': 58 if real_path.strip('/') == 'apps':
55 real_path = 'apps/index.html' 59 real_path = 'apps/index.html'
56 if real_path.strip('/') == 'extensions': 60 if real_path.strip('/') == 'extensions':
57 real_path = 'extensions/index.html' 61 real_path = 'extensions/index.html'
58 62
59 constructor = ( 63 # Serving patched content requires an online server instance to fetch
60 ServerInstance.CreateOnline if Handler.ALWAYS_ONLINE else 64 # data from SVN and Rietveld.
61 ServerInstance.GetOrCreateOffline) 65 if Handler.ALWAYS_ONLINE or issue is not None:
62 server_instance = constructor(channel_name) 66 server_instance = ServerInstance.CreateOnline(channel_name, issue)
67 else:
68 server_instance = ServerInstance.GetOrCreateOffline(channel_name)
63 69
64 canonical_path = server_instance.path_canonicalizer.Canonicalize(real_path) 70 canonical_path = server_instance.path_canonicalizer.Canonicalize(real_path)
65 if real_path != canonical_path: 71 if real_path != canonical_path:
66 self.redirect(canonical_path) 72 self.redirect(canonical_path)
67 return 73 return
68 74
69 server_instance.Get(real_path, self.request, self.response) 75 server_instance.Get(real_path, self.request, self.response)
70 76
71 def _HandleCron(self, path): 77 def _HandleCron(self, path):
72 # Cron strategy: 78 # Cron strategy:
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 # file paths will know to treat this as a directory. 218 # file paths will know to treat this as a directory.
213 if os.path.splitext(path)[1] == '' and path[-1] != '/': 219 if os.path.splitext(path)[1] == '' and path[-1] != '/':
214 self.redirect(path + '/') 220 self.redirect(path + '/')
215 return 221 return
216 222
217 path = path.strip('/') 223 path = path.strip('/')
218 if self._RedirectFromCodeDotGoogleDotCom(path): 224 if self._RedirectFromCodeDotGoogleDotCom(path):
219 return 225 return
220 226
221 self._HandleGet(path) 227 self._HandleGet(path)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698