| OLD | NEW |
| 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 from json_schema import LoadJSON |
| 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 Loading... |
| 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 with open(json_file_path) as json_file: | 191 api_defs = LoadJSON(json_file_path) |
| 192 api_defs = json.loads(json_file.read()) | |
| 193 namespace = api_model.AddNamespace(api_defs[0], json_file_path) | 192 namespace = api_model.AddNamespace(api_defs[0], json_file_path) |
| 194 if not namespace: | 193 if not namespace: |
| 195 body.Append("<pre>Target file %s is marked nocompile</pre>" % | 194 body.Append("<pre>Target file %s is marked nocompile</pre>" % |
| 196 json_file_path) | 195 json_file_path) |
| 197 return | 196 return |
| 198 type_generator = cpp_type_generator.CppTypeGenerator( | 197 type_generator = cpp_type_generator.CppTypeGenerator( |
| 199 'preview::api', namespace, namespace.unix_name) | 198 'preview::api', namespace, namespace.unix_name) |
| 200 | 199 |
| 201 # Get json file depedencies | 200 # Get json file depedencies |
| 202 for dependency in api_defs[0].get('dependencies', []): | 201 for dependency in api_defs[0].get('dependencies', []): |
| 203 json_file_path = os.path.join(filedir, dependency + '.json') | 202 json_file_path = os.path.join(filedir, dependency + '.json') |
| 204 with open(json_file_path) as json_file: | 203 api_defs = LoadJSON(json_file_path) |
| 205 api_defs = json.loads(json_file.read()) | |
| 206 referenced_namespace = api_model.AddNamespace(api_defs[0], | 204 referenced_namespace = api_model.AddNamespace(api_defs[0], |
| 207 json_file_path) | 205 json_file_path) |
| 208 if referenced_namespace: | 206 if referenced_namespace: |
| 209 type_generator.AddNamespace(referenced_namespace, | 207 type_generator.AddNamespace(referenced_namespace, |
| 210 cpp_util.Classname(referenced_namespace.name).lower()) | 208 cpp_util.Classname(referenced_namespace.name).lower()) |
| 211 | 209 |
| 212 # Generate code | 210 # Generate code |
| 213 if file_ext == '.h': | 211 if file_ext == '.h': |
| 214 cpp_code = (h_generator.HGenerator(namespace, type_generator) | 212 cpp_code = (h_generator.HGenerator(namespace, type_generator) |
| 215 .Generate().Render()) | 213 .Generate().Render()) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 print('') | 327 print('') |
| 330 server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler, | 328 server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler, |
| 331 { | 329 { |
| 332 'pygments': pygments_highlighter.PygmentsHighlighter(), | 330 'pygments': pygments_highlighter.PygmentsHighlighter(), |
| 333 'hilite': hilite_me_highlighter.HiliteMeHighlighter(), | 331 'hilite': hilite_me_highlighter.HiliteMeHighlighter(), |
| 334 'none': none_highlighter.NoneHighlighter(), | 332 'none': none_highlighter.NoneHighlighter(), |
| 335 }) | 333 }) |
| 336 server.serve_forever() | 334 server.serve_forever() |
| 337 except KeyboardInterrupt: | 335 except KeyboardInterrupt: |
| 338 server.socket.close() | 336 server.socket.close() |
| OLD | NEW |