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

Side by Side Diff: tools/json_schema_compiler/preview.py

Issue 23549025: Clean up JSON Schema Compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed enum test and added blank lines. Created 7 years, 3 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 | « tools/json_schema_compiler/model_test.py ('k') | tools/json_schema_compiler/schema_util.py » ('j') | 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 2
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 """Server for viewing the compiled C++ code from tools/json_schema_compiler. 6 """Server for viewing the compiled C++ code from tools/json_schema_compiler.
7 """ 7 """
8 8
9 import cc_generator 9 import cc_generator
10 import code 10 import code
11 import compiler
12 import cpp_type_generator 11 import cpp_type_generator
13 import cpp_util 12 import cpp_util
14 import h_generator 13 import h_generator
15 import idl_schema 14 import idl_schema
16 import json_schema 15 import json_schema
17 import model 16 import model
18 import optparse 17 import optparse
19 import os 18 import os
20 import schema_loader 19 import schema_loader
21 import sys
22 import urlparse 20 import urlparse
23 from highlighters import ( 21 from highlighters import (
24 pygments_highlighter, none_highlighter, hilite_me_highlighter) 22 pygments_highlighter, none_highlighter, hilite_me_highlighter)
25 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer 23 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
26 24
25
27 class CompilerHandler(BaseHTTPRequestHandler): 26 class CompilerHandler(BaseHTTPRequestHandler):
28 """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler. 27 """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler.
29 """ 28 """
30 def do_GET(self): 29 def do_GET(self):
31 parsed_url = urlparse.urlparse(self.path) 30 parsed_url = urlparse.urlparse(self.path)
32 request_path = self._GetRequestPath(parsed_url) 31 request_path = self._GetRequestPath(parsed_url)
33 32
34 chromium_favicon = 'http://codereview.chromium.org/static/favicon.ico' 33 chromium_favicon = 'http://codereview.chromium.org/static/favicon.ico'
35 34
36 head = code.Code() 35 head = code.Code()
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 html.Append('<li><a href="/%s/">%s/</a>' % (full_path, filename)) 319 html.Append('<li><a href="/%s/">%s/</a>' % (full_path, filename))
321 elif file_ext in ['.json', '.idl']: 320 elif file_ext in ['.json', '.idl']:
322 # cc/h panes will automatically update via the hash change event. 321 # cc/h panes will automatically update via the hash change event.
323 html.Append('<li><a href="#%s">%s</a>' % 322 html.Append('<li><a href="#%s">%s</a>' %
324 (filename, filename)) 323 (filename, filename))
325 324
326 html.Append('</ul>') 325 html.Append('</ul>')
327 326
328 return html.Render() 327 return html.Render()
329 328
329
330 class PreviewHTTPServer(HTTPServer, object): 330 class PreviewHTTPServer(HTTPServer, object):
331 def __init__(self, server_address, handler, highlighters): 331 def __init__(self, server_address, handler, highlighters):
332 super(PreviewHTTPServer, self).__init__(server_address, handler) 332 super(PreviewHTTPServer, self).__init__(server_address, handler)
333 self.highlighters = highlighters 333 self.highlighters = highlighters
334 334
335 335
336 if __name__ == '__main__': 336 if __name__ == '__main__':
337 parser = optparse.OptionParser( 337 parser = optparse.OptionParser(
338 description='Runs a server to preview the json_schema_compiler output.', 338 description='Runs a server to preview the json_schema_compiler output.',
339 usage='usage: %prog [option]...') 339 usage='usage: %prog [option]...')
(...skipping 17 matching lines...) Expand all
357 highlighters['pygments'] = pygments_highlighter.PygmentsHighlighter() 357 highlighters['pygments'] = pygments_highlighter.PygmentsHighlighter()
358 except ImportError as e: 358 except ImportError as e:
359 pass 359 pass
360 360
361 server = PreviewHTTPServer(('', int(opts.port)), 361 server = PreviewHTTPServer(('', int(opts.port)),
362 CompilerHandler, 362 CompilerHandler,
363 highlighters) 363 highlighters)
364 server.serve_forever() 364 server.serve_forever()
365 except KeyboardInterrupt: 365 except KeyboardInterrupt:
366 server.socket.close() 366 server.socket.close()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/model_test.py ('k') | tools/json_schema_compiler/schema_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698