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

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

Issue 9582013: Revert 124660 - Allow comments in extension config files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « tools/json_schema_compiler/model_test.py ('k') | 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 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 from json_schema import LoadJSON 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 class CompilerHandler(BaseHTTPRequestHandler): 24 class CompilerHandler(BaseHTTPRequestHandler):
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 api_model = model.Model() 182 api_model = model.Model()
183 183
184 request_path = self._GetRequestPath(parsed_url) 184 request_path = self._GetRequestPath(parsed_url)
185 (file_root, file_ext) = os.path.splitext(request_path) 185 (file_root, file_ext) = os.path.splitext(request_path)
186 (filedir, filename) = os.path.split(file_root) 186 (filedir, filename) = os.path.split(file_root)
187 json_file_path = os.path.normpath(file_root + '.json') 187 json_file_path = os.path.normpath(file_root + '.json')
188 188
189 try: 189 try:
190 # Get main json file 190 # Get main json file
191 api_defs = LoadJSON(json_file_path) 191 with open(json_file_path) as json_file:
192 api_defs = json.loads(json_file.read())
192 namespace = api_model.AddNamespace(api_defs[0], json_file_path) 193 namespace = api_model.AddNamespace(api_defs[0], json_file_path)
193 if not namespace: 194 if not namespace:
194 body.Append("<pre>Target file %s is marked nocompile</pre>" % 195 body.Append("<pre>Target file %s is marked nocompile</pre>" %
195 json_file_path) 196 json_file_path)
196 return 197 return
197 type_generator = cpp_type_generator.CppTypeGenerator( 198 type_generator = cpp_type_generator.CppTypeGenerator(
198 'preview::api', namespace, namespace.unix_name) 199 'preview::api', namespace, namespace.unix_name)
199 200
200 # Get json file depedencies 201 # Get json file depedencies
201 for dependency in api_defs[0].get('dependencies', []): 202 for dependency in api_defs[0].get('dependencies', []):
202 json_file_path = os.path.join(filedir, dependency + '.json') 203 json_file_path = os.path.join(filedir, dependency + '.json')
203 api_defs = LoadJSON(json_file_path) 204 with open(json_file_path) as json_file:
205 api_defs = json.loads(json_file.read())
204 referenced_namespace = api_model.AddNamespace(api_defs[0], 206 referenced_namespace = api_model.AddNamespace(api_defs[0],
205 json_file_path) 207 json_file_path)
206 if referenced_namespace: 208 if referenced_namespace:
207 type_generator.AddNamespace(referenced_namespace, 209 type_generator.AddNamespace(referenced_namespace,
208 cpp_util.Classname(referenced_namespace.name).lower()) 210 cpp_util.Classname(referenced_namespace.name).lower())
209 211
210 # Generate code 212 # Generate code
211 if file_ext == '.h': 213 if file_ext == '.h':
212 cpp_code = (h_generator.HGenerator(namespace, type_generator) 214 cpp_code = (h_generator.HGenerator(namespace, type_generator)
213 .Generate().Render()) 215 .Generate().Render())
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 print('') 329 print('')
328 server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler, 330 server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler,
329 { 331 {
330 'pygments': pygments_highlighter.PygmentsHighlighter(), 332 'pygments': pygments_highlighter.PygmentsHighlighter(),
331 'hilite': hilite_me_highlighter.HiliteMeHighlighter(), 333 'hilite': hilite_me_highlighter.HiliteMeHighlighter(),
332 'none': none_highlighter.NoneHighlighter(), 334 'none': none_highlighter.NoneHighlighter(),
333 }) 335 })
334 server.serve_forever() 336 server.serve_forever()
335 except KeyboardInterrupt: 337 except KeyboardInterrupt:
336 server.socket.close() 338 server.socket.close()
OLDNEW
« no previous file with comments | « 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