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

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

Issue 15730007: Fixes for Python errors in json_schema_compiler preview server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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 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 11 import compiler
12 import cpp_type_generator 12 import cpp_type_generator
13 import cpp_util 13 import cpp_util
14 import h_generator 14 import h_generator
15 import idl_schema 15 import idl_schema
16 import json_schema 16 import json_schema
17 import model 17 import model
18 import optparse 18 import optparse
19 import os 19 import os
20 import schema_loader
20 import sys 21 import sys
21 import urlparse 22 import urlparse
22 from highlighters import ( 23 from highlighters import (
23 pygments_highlighter, none_highlighter, hilite_me_highlighter) 24 pygments_highlighter, none_highlighter, hilite_me_highlighter)
24 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer 25 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
25 26
26 class CompilerHandler(BaseHTTPRequestHandler): 27 class CompilerHandler(BaseHTTPRequestHandler):
27 """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler. 28 """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler.
28 """ 29 """
29 def do_GET(self): 30 def do_GET(self):
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 206
206 request_path = self._GetRequestPath(parsed_url) 207 request_path = self._GetRequestPath(parsed_url)
207 (file_root, file_ext) = os.path.splitext(request_path) 208 (file_root, file_ext) = os.path.splitext(request_path)
208 (filedir, filename) = os.path.split(file_root) 209 (filedir, filename) = os.path.split(file_root)
209 210
210 try: 211 try:
211 # Get main file. 212 # Get main file.
212 (api_def, file_path) = self._LoadModel(filedir, filename) 213 (api_def, file_path) = self._LoadModel(filedir, filename)
213 namespace = api_model.AddNamespace(api_def, file_path) 214 namespace = api_model.AddNamespace(api_def, file_path)
214 type_generator = cpp_type_generator.CppTypeGenerator( 215 type_generator = cpp_type_generator.CppTypeGenerator(
215 namespace, 216 api_model,
216 compiler.TypeNamespaceResolver(filedir), 217 schema_loader.SchemaLoader(filedir),
217 namespace.unix_name) 218 namespace)
218 219
219 # Get the model's dependencies. 220 # Get the model's dependencies.
220 for dependency in api_def.get('dependencies', []): 221 for dependency in api_def.get('dependencies', []):
221 # Dependencies can contain : in which case they don't refer to APIs, 222 # Dependencies can contain : in which case they don't refer to APIs,
222 # rather, permissions or manifest keys. 223 # rather, permissions or manifest keys.
223 if ':' in dependency: 224 if ':' in dependency:
224 continue 225 continue
225 (api_def, file_path) = self._LoadModel(filedir, dependency) 226 (api_def, file_path) = self._LoadModel(filedir, dependency)
226 referenced_namespace = api_model.AddNamespace(api_def, file_path) 227 referenced_namespace = api_model.AddNamespace(api_def, file_path)
227 if referenced_namespace: 228 if referenced_namespace:
228 type_generator.AddNamespace(referenced_namespace, 229 type_generator.AddNamespace(referenced_namespace,
229 cpp_util.Classname(referenced_namespace.name).lower()) 230 cpp_util.Classname(referenced_namespace.name).lower())
230 231
231 # Generate code 232 # Generate code
233 cpp_namespace = 'generated_api_schemas'
232 if file_ext == '.h': 234 if file_ext == '.h':
233 cpp_code = (h_generator.HGenerator(namespace, type_generator) 235 cpp_code = (h_generator.HGenerator(type_generator, cpp_namespace)
234 .Generate().Render()) 236 .Generate(namespace).Render())
235 elif file_ext == '.cc': 237 elif file_ext == '.cc':
236 cpp_code = (cc_generator.CCGenerator(namespace, type_generator) 238 cpp_code = (cc_generator.CCGenerator(type_generator, cpp_namespace)
237 .Generate().Render()) 239 .Generate(namespace).Render())
238 else: 240 else:
239 self.send_error(404, "File not found: %s" % request_path) 241 self.send_error(404, "File not found: %s" % request_path)
240 return 242 return
241 243
242 # Do highlighting on the generated code 244 # Do highlighting on the generated code
243 (highlighter_param, style_param) = self._GetHighlighterParams(parsed_url) 245 (highlighter_param, style_param) = self._GetHighlighterParams(parsed_url)
244 head.Append('<style>' + 246 head.Append('<style>' +
245 self.server.highlighters[highlighter_param].GetCSS(style_param) + 247 self.server.highlighters[highlighter_param].GetCSS(style_param) +
246 '</style>') 248 '</style>')
247 body.Append(self.server.highlighters[highlighter_param] 249 body.Append(self.server.highlighters[highlighter_param]
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 highlighters['pygments'] = pygments_highlighter.PygmentsHighlighter() 357 highlighters['pygments'] = pygments_highlighter.PygmentsHighlighter()
356 except ImportError as e: 358 except ImportError as e:
357 pass 359 pass
358 360
359 server = PreviewHTTPServer(('', int(opts.port)), 361 server = PreviewHTTPServer(('', int(opts.port)),
360 CompilerHandler, 362 CompilerHandler,
361 highlighters) 363 highlighters)
362 server.serve_forever() 364 server.serve_forever()
363 except KeyboardInterrupt: 365 except KeyboardInterrupt:
364 server.socket.close() 366 server.socket.close()
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