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

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

Issue 9447090: Allow comments in extension config files. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added minify to some files in tools/json_schema_compiler Created 8 years, 9 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 #!/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 cpp_type_generator 11 import cpp_type_generator
12 import cpp_util 12 import cpp_util
13 import h_generator 13 import h_generator
14 import json 14 import json
15 import model 15 import model
16 import optparse 16 import optparse
17 import os 17 import os
18 import sys 18 import sys
19 import urlparse 19 import urlparse
20 from highlighters import ( 20 from highlighters import (
21 pygments_highlighter, none_highlighter, hilite_me_highlighter) 21 pygments_highlighter, none_highlighter, hilite_me_highlighter)
22 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer 22 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
23 23
24 # We need to get json_minify from the third_party directory.
25 # This is similar to what is done in chrome/common/extensions/docs/build.py
26 third_party_path = os.path.dirname(os.path.realpath(__file__)) + \
27 '/../../third_party/'
28 if third_party_path not in sys.path:
29 sys.path.insert(0, third_party_path)
30 import json_minify as minify
31
24 class CompilerHandler(BaseHTTPRequestHandler): 32 class CompilerHandler(BaseHTTPRequestHandler):
25 """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler. 33 """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler.
26 """ 34 """
27 def do_GET(self): 35 def do_GET(self):
28 parsed_url = urlparse.urlparse(self.path) 36 parsed_url = urlparse.urlparse(self.path)
29 request_path = self._GetRequestPath(parsed_url) 37 request_path = self._GetRequestPath(parsed_url)
30 38
31 chromium_favicon = 'http://codereview.chromium.org/static/favicon.ico' 39 chromium_favicon = 'http://codereview.chromium.org/static/favicon.ico'
32 40
33 head = code.Code() 41 head = code.Code()
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 api_model = model.Model() 190 api_model = model.Model()
183 191
184 request_path = self._GetRequestPath(parsed_url) 192 request_path = self._GetRequestPath(parsed_url)
185 (file_root, file_ext) = os.path.splitext(request_path) 193 (file_root, file_ext) = os.path.splitext(request_path)
186 (filedir, filename) = os.path.split(file_root) 194 (filedir, filename) = os.path.split(file_root)
187 json_file_path = os.path.normpath(file_root + '.json') 195 json_file_path = os.path.normpath(file_root + '.json')
188 196
189 try: 197 try:
190 # Get main json file 198 # Get main json file
191 with open(json_file_path) as json_file: 199 with open(json_file_path) as json_file:
192 api_defs = json.loads(json_file.read()) 200 api_defs = json.loads(minify.json_minify(json_file.read()))
193 namespace = api_model.AddNamespace(api_defs[0], json_file_path) 201 namespace = api_model.AddNamespace(api_defs[0], json_file_path)
194 if not namespace: 202 if not namespace:
195 body.Append("<pre>Target file %s is marked nocompile</pre>" % 203 body.Append("<pre>Target file %s is marked nocompile</pre>" %
196 json_file_path) 204 json_file_path)
197 return 205 return
198 type_generator = cpp_type_generator.CppTypeGenerator( 206 type_generator = cpp_type_generator.CppTypeGenerator(
199 'preview::api', namespace, cpp_util.Classname(filename).lower()) 207 'preview::api', namespace, cpp_util.Classname(filename).lower())
200 208
201 # Get json file depedencies 209 # Get json file depedencies
202 for dependency in api_defs[0].get('dependencies', []): 210 for dependency in api_defs[0].get('dependencies', []):
203 json_file_path = os.path.join(filedir, dependency + '.json') 211 json_file_path = os.path.join(filedir, dependency + '.json')
204 with open(json_file_path) as json_file: 212 with open(json_file_path) as json_file:
205 api_defs = json.loads(json_file.read()) 213 api_defs = json.loads(minify.json_minify(json_file.read()))
206 referenced_namespace = api_model.AddNamespace(api_defs[0], 214 referenced_namespace = api_model.AddNamespace(api_defs[0],
207 json_file_path) 215 json_file_path)
208 if referenced_namespace: 216 if referenced_namespace:
209 type_generator.AddNamespace(referenced_namespace, 217 type_generator.AddNamespace(referenced_namespace,
210 cpp_util.Classname(referenced_namespace.name).lower()) 218 cpp_util.Classname(referenced_namespace.name).lower())
211 219
212 # Generate code 220 # Generate code
213 if file_ext == '.h': 221 if file_ext == '.h':
214 cpp_code = (h_generator.HGenerator(namespace, type_generator) 222 cpp_code = (h_generator.HGenerator(namespace, type_generator)
215 .Generate().Render()) 223 .Generate().Render())
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 print('') 337 print('')
330 server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler, 338 server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler,
331 { 339 {
332 'pygments': pygments_highlighter.PygmentsHighlighter(), 340 'pygments': pygments_highlighter.PygmentsHighlighter(),
333 'hilite': hilite_me_highlighter.HiliteMeHighlighter(), 341 'hilite': hilite_me_highlighter.HiliteMeHighlighter(),
334 'none': none_highlighter.NoneHighlighter(), 342 'none': none_highlighter.NoneHighlighter(),
335 }) 343 })
336 server.serve_forever() 344 server.serve_forever()
337 except KeyboardInterrupt: 345 except KeyboardInterrupt:
338 server.socket.close() 346 server.socket.close()
OLDNEW
« tools/json_schema_compiler/model_test.py ('K') | « tools/json_schema_compiler/model_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698