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

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

Issue 14273035: Docserver: refactor the Handler/ServerInstance relationship into a servlet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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 # This helps you preview the apps and extensions docs. 6 # This helps you preview the apps and extensions docs.
7 # 7 #
8 # ./preview.py --help 8 # ./preview.py --help
9 # 9 #
10 # There are two modes: server- and render- mode. The default is server, in which 10 # There are two modes: server- and render- mode. The default is server, in which
(...skipping 15 matching lines...) Expand all
26 # 26 #
27 # Note: absolute paths into static content (e.g. /static/css/site.css) will be 27 # Note: absolute paths into static content (e.g. /static/css/site.css) will be
28 # relative paths (e.g. static/css/site.css) for convenient sandboxing. 28 # relative paths (e.g. static/css/site.css) for convenient sandboxing.
29 29
30 # NOTE: RUN THIS FIRST. Or all third_party imports will fail. 30 # NOTE: RUN THIS FIRST. Or all third_party imports will fail.
31 import build_server 31 import build_server
32 # Copy all the files necessary to run the server. These are cleaned up when the 32 # Copy all the files necessary to run the server. These are cleaned up when the
33 # server quits. 33 # server quits.
34 build_server.main() 34 build_server.main()
35 35
36 from render_servlet import AlwaysOnline
36 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer 37 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
37 from local_renderer import LocalRenderer 38 from local_renderer import LocalRenderer
38 import logging 39 import logging
39 import optparse 40 import optparse
40 import os 41 import os
41 import sys 42 import sys
42 import time 43 import time
43 44
44 def _GetLocalPath(): 45 def _GetLocalPath():
45 if os.sep in sys.argv[0]: 46 if os.sep in sys.argv[0]:
46 return os.path.join(sys.argv[0].rsplit(os.sep, 1)[0], os.pardir, os.pardir) 47 return os.path.join(sys.argv[0].rsplit(os.sep, 1)[0], os.pardir, os.pardir)
47 return os.path.join(os.pardir, os.pardir) 48 return os.path.join(os.pardir, os.pardir)
48 49
50 @AlwaysOnline
49 def _Render(base_dir, path): 51 def _Render(base_dir, path):
50 renderer = LocalRenderer(base_dir) 52 renderer = LocalRenderer(base_dir)
51 content, status, headers = renderer.Render(path, always_online=True) 53 content, status, headers = renderer.Render(path)
52 while status in [301, 302]: 54 while status in [301, 302]:
53 redirect = headers['Location'].lstrip('/') 55 redirect = headers['Location'].lstrip('/')
54 sys.stderr.write('<!-- Redirected %s to %s -->\n' % (path, redirect)) 56 sys.stderr.write('<!-- Redirected %s to %s -->\n' % (path, redirect))
55 content, status, headers = renderer.Render(redirect, always_online=True) 57 content, status, headers = renderer.Render(redirect)
56 return (content, status, headers) 58 return (content, status, headers)
57 59
58 class RequestHandler(BaseHTTPRequestHandler): 60 class RequestHandler(BaseHTTPRequestHandler):
59 class Factory(object): 61 class Factory(object):
60 def __init__(self, base_dir): 62 def __init__(self, base_dir):
61 self._base_dir = base_dir 63 self._base_dir = base_dir
62 64
63 def Create(self, *args): 65 def Create(self, *args):
64 return RequestHandler(self._base_dir, *args) 66 return RequestHandler(self._base_dir, *args)
65 67
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 print(' http://localhost:%s/apps/' % opts.port) 143 print(' http://localhost:%s/apps/' % opts.port)
142 print('') 144 print('')
143 145
144 logging.getLogger().setLevel(logging.INFO) 146 logging.getLogger().setLevel(logging.INFO)
145 server = HTTPServer(('', int(opts.port)), 147 server = HTTPServer(('', int(opts.port)),
146 RequestHandler.Factory(opts.directory).Create) 148 RequestHandler.Factory(opts.directory).Create)
147 try: 149 try:
148 server.serve_forever() 150 server.serve_forever()
149 finally: 151 finally:
150 server.socket.close() 152 server.socket.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698