OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import subprocess | 7 import subprocess |
8 import sys | 8 import sys |
| 9 import urlparse |
9 | 10 |
10 | 11 |
11 BUILD_DIRECTORY = 'out' | 12 BUILD_DIRECTORY = 'out' |
12 CONFIG_DIRECTORY = 'Debug' | 13 CONFIG_DIRECTORY = 'Debug' |
13 MOJO_SHELL_PATH = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, | 14 MOJO_SHELL_PATH = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, |
14 os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell')) | 15 os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell')) |
15 | 16 |
16 SUPPORTED_MIME_TYPES = [ | 17 SUPPORTED_MIME_TYPES = [ |
17 'text/html', | 18 'text/html', |
18 'text/plain', | 19 'text/plain', |
19 ] | 20 ] |
20 | 21 |
| 22 def start_http_server_for_file(path): |
| 23 HTTP_PORT = 9999 |
| 24 directory = os.path.dirname(os.path.abspath(path)) |
| 25 server_command = [ |
| 26 'python', |
| 27 '-m', |
| 28 'SimpleHTTPServer', |
| 29 str(HTTP_PORT) |
| 30 ] |
| 31 subprocess.Popen(server_command, cwd=directory) |
| 32 return 'http://localhost:%s/%s' % (HTTP_PORT, os.path.basename(path)) |
| 33 |
| 34 |
21 def main(args): | 35 def main(args): |
22 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') | 36 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') |
23 for mime_type in SUPPORTED_MIME_TYPES] | 37 for mime_type in SUPPORTED_MIME_TYPES] |
24 shell_command = [ | 38 shell_command = [ |
25 MOJO_SHELL_PATH, | 39 MOJO_SHELL_PATH, |
26 '--v=1', | 40 '--v=1', |
27 '--content-handlers=%s' % ','.join(content_handlers), | 41 '--content-handlers=%s' % ','.join(content_handlers), |
28 '--url-mappings=mojo:window_manager=mojo:sky_debugger', | 42 '--url-mappings=mojo:window_manager=mojo:sky_debugger', |
29 'mojo:window_manager', | 43 'mojo:window_manager', |
30 ] | 44 ] |
31 if args: | 45 if args: |
32 prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % args[0] | 46 url = args[0] |
| 47 parse_result = urlparse.urlparse(url) |
| 48 if not parse_result.scheme: |
| 49 url = start_http_server_for_file(url) |
| 50 |
| 51 prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % url |
33 shell_command.append(prompt_args) | 52 shell_command.append(prompt_args) |
34 subprocess.check_call(shell_command) | 53 subprocess.check_call(shell_command) |
35 | 54 |
36 | 55 |
37 if __name__ == '__main__': | 56 if __name__ == '__main__': |
38 main(sys.argv[1:]) | 57 main(sys.argv[1:]) |
OLD | NEW |