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

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

Issue 17816005: Doc server broken link detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Additional information for broken anchor links Created 7 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
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 from branch_utility import BranchUtility 5 from branch_utility import BranchUtility
6 from cron_servlet import CronServlet 6 from cron_servlet import CronServlet
7 from find_broken_links import CreateProcessor, FindBrokenLinks, usage
8 from instance_servlet import InstanceServlet
7 from patch_servlet import PatchServlet 9 from patch_servlet import PatchServlet
8 from instance_servlet import InstanceServlet
9 from servlet import Servlet, Request, Response 10 from servlet import Servlet, Request, Response
10 11
11 _SERVLETS = { 12 _SERVLETS = {
12 'cron': CronServlet, 13 'cron': CronServlet,
13 'patch': PatchServlet, 14 'patch': PatchServlet,
14 } 15 }
15 _DEFAULT_SERVLET = InstanceServlet.GetConstructor() 16 _DEFAULT_SERVLET = InstanceServlet.GetConstructor()
16 17
17 class Handler(Servlet): 18 class Handler(Servlet):
18 def Get(self): 19 def Get(self):
19 path = self._request.path 20 path = self._request.path
20 21
21 redirect = self._RedirectSpecialCases() 22 redirect = self._RedirectSpecialCases()
22 if redirect is None: 23 if redirect is None:
23 redirect = self._RedirectFromCodeDotGoogleDotCom() 24 redirect = self._RedirectFromCodeDotGoogleDotCom()
24 if redirect is not None: 25 if redirect is not None:
25 return redirect 26 return redirect
26 27
27 if path.startswith('_'): 28 if path.startswith('_'):
29 if path.startswith('_test_links'):
30 seed_paths = ['/extensions/index.html', '/apps/about_apps.html']
31 output = [usage]
32
33 # Functions to customize the behavior of the broken link finder.
34 def writer(*args):
35 output.append(' '.join([str(a) for a in args]))
36
37 def renderer(path):
38 return _DEFAULT_SERVLET(
39 Request(path, self._request.host, self._request.headers)).Get()
40
41 if '/' in path:
42 channel = path.split('/')[1]
43 if channel != 'stable':
44 seed_paths = ['/%s%s' % (channel, p) for p in seed_paths]
45
46 FindBrokenLinks(CreateProcessor(renderer), seed_paths, writer)
47
48 return Response.Ok('\n'.join(output))
not at google - send to devlin 2013/07/01 23:16:21 This is kinda cool, I actually once did add a _tes
49
28 servlet_path = path[1:] 50 servlet_path = path[1:]
29 if servlet_path.find('/') == -1: 51 if servlet_path.find('/') == -1:
30 servlet_path += '/' 52 servlet_path += '/'
31 servlet_name, servlet_path = servlet_path.split('/', 1) 53 servlet_name, servlet_path = servlet_path.split('/', 1)
32 servlet = _SERVLETS.get(servlet_name) 54 servlet = _SERVLETS.get(servlet_name)
33 if servlet is None: 55 if servlet is None:
34 return Response.NotFound('"%s" servlet not found' % servlet_path) 56 return Response.NotFound('"%s" servlet not found' % servlet_path)
35 else: 57 else:
36 servlet_path = path 58 servlet_path = path
37 servlet = _DEFAULT_SERVLET 59 servlet = _DEFAULT_SERVLET
(...skipping 24 matching lines...) Expand all
62 84
63 new_path = path.split('/') 85 new_path = path.split('/')
64 if len(new_path) > 0 and new_path[0] == 'chrome': 86 if len(new_path) > 0 and new_path[0] == 'chrome':
65 new_path.pop(0) 87 new_path.pop(0)
66 for channel in BranchUtility.GetAllChannelNames(): 88 for channel in BranchUtility.GetAllChannelNames():
67 if channel in new_path: 89 if channel in new_path:
68 position = new_path.index(channel) 90 position = new_path.index(channel)
69 new_path.pop(position) 91 new_path.pop(position)
70 new_path.insert(0, channel) 92 new_path.insert(0, channel)
71 return Response.Redirect('/'.join([new_host] + new_path)) 93 return Response.Redirect('/'.join([new_host] + new_path))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698