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

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

Issue 10837078: Preview Docs Server: Send response for the preview server. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 is a preview server for the apps and extensions docs. Navigate to a docs 6 # This is a preview server for the apps and extensions docs. Navigate to a docs
7 # page, and the page will be rendered how it will be on the production server. 7 # page, and the page will be rendered how it will be on the production server.
8 # 8 #
9 # For example: http://localhost:8000/tabs.html will render the docs page for 9 # For example: http://localhost:8000/tabs.html will render the docs page for
10 # the tabs API. 10 # the tabs API.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 class RequestHandler(BaseHTTPRequestHandler): 45 class RequestHandler(BaseHTTPRequestHandler):
46 """A HTTPRequestHandler that outputs the docs page generated by Handler. 46 """A HTTPRequestHandler that outputs the docs page generated by Handler.
47 """ 47 """
48 def do_GET(self): 48 def do_GET(self):
49 parsed_url = urlparse.urlparse(self.path) 49 parsed_url = urlparse.urlparse(self.path)
50 request = Request(parsed_url.path) 50 request = Request(parsed_url.path)
51 response = Response() 51 response = Response()
52 Handler(request, response, local_path=_GetLocalPath()).get() 52 Handler(request, response, local_path=_GetLocalPath()).get()
53 content = response.out.getvalue() 53 content = response.out.getvalue()
54
55 self.send_response(response.status)
56 self.end_headers()
54 if isinstance(content, str): 57 if isinstance(content, str):
55 self.wfile.write(content) 58 self.wfile.write(content)
56 else: 59 else:
57 self.wfile.write(content.encode('utf-8', 'replace')) 60 self.wfile.write(content.encode('utf-8', 'replace'))
58 61
59 if __name__ == '__main__': 62 if __name__ == '__main__':
60 parser = optparse.OptionParser( 63 parser = optparse.OptionParser(
61 description='Runs a server to preview the extension documentation.', 64 description='Runs a server to preview the extension documentation.',
62 usage='usage: %prog [option]...') 65 usage='usage: %prog [option]...')
63 parser.add_option('-p', '--port', default="8000", 66 parser.add_option('-p', '--port', default="8000",
64 help='port to run the server on') 67 help='port to run the server on')
65 68
66 (opts, argv) = parser.parse_args() 69 (opts, argv) = parser.parse_args()
67 70
68 print('Starting previewserver on port %s' % opts.port) 71 print('Starting previewserver on port %s' % opts.port)
69 print('The extension documentation can be found at:') 72 print('The extension documentation can be found at:')
70 print('') 73 print('')
71 print(' http://localhost:%s' % opts.port) 74 print(' http://localhost:%s' % opts.port)
72 print('') 75 print('')
73 76
74 server = HTTPServer(('', int(opts.port)), RequestHandler) 77 server = HTTPServer(('', int(opts.port)), RequestHandler)
75 try: 78 try:
76 server.serve_forever() 79 server.serve_forever()
77 finally: 80 finally:
78 server.socket.close() 81 server.socket.close()
79 shutil.rmtree(os.path.join(sys.argv[0].rsplit(os.sep, 1)[0], 'third_party')) 82 shutil.rmtree(os.path.join(sys.argv[0].rsplit(os.sep, 1)[0], 'third_party'))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698