| 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 argparse |
| 6 import os | 7 import os |
| 7 import subprocess | 8 import subprocess |
| 8 import sys | 9 import sys |
| 9 import urlparse | 10 import urlparse |
| 10 | 11 |
| 11 | 12 |
| 12 BUILD_DIRECTORY = 'out' | 13 BUILD_DIRECTORY = 'out' |
| 13 CONFIG_DIRECTORY = 'Debug' | 14 CONFIG_DIRECTORY = 'Debug' |
| 14 MOJO_SHELL_PATH = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, | 15 MOJO_SHELL_PATH = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, |
| 15 os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell')) | 16 os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell')) |
| 16 | 17 |
| 17 SUPPORTED_MIME_TYPES = [ | 18 SUPPORTED_MIME_TYPES = [ |
| 18 'text/html', | 19 'text/html', |
| 19 'text/plain', | 20 'text/plain', |
| 20 ] | 21 ] |
| 21 | 22 |
| 22 def start_http_server_for_file(path): | 23 def start_http_server_for_file(path): |
| 23 HTTP_PORT = 9999 | 24 HTTP_PORT = 9999 |
| 24 directory = os.path.dirname(os.path.abspath(path)) | 25 directory = os.path.dirname(os.path.abspath(path)) |
| 25 server_command = [ | 26 server_command = [ |
| 26 'python', | 27 'python', |
| 27 '-m', | 28 '-m', |
| 28 'SimpleHTTPServer', | 29 'SimpleHTTPServer', |
| 29 str(HTTP_PORT) | 30 str(HTTP_PORT) |
| 30 ] | 31 ] |
| 31 subprocess.Popen(server_command, cwd=directory) | 32 subprocess.Popen(server_command, cwd=directory) |
| 32 return 'http://localhost:%s/%s' % (HTTP_PORT, os.path.basename(path)) | 33 return 'http://localhost:%s/%s' % (HTTP_PORT, os.path.basename(path)) |
| 33 | 34 |
| 34 | 35 |
| 35 def main(args): | 36 def main(): |
| 37 parser = argparse.ArgumentParser(description='Sky launcher/debugger') |
| 38 parser.add_argument('--gdb', action='store_true') |
| 39 parser.add_argument('url', nargs='?', type=str) |
| 40 args = parser.parse_args() |
| 41 |
| 36 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') | 42 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') |
| 37 for mime_type in SUPPORTED_MIME_TYPES] | 43 for mime_type in SUPPORTED_MIME_TYPES] |
| 38 shell_command = [ | 44 shell_command = [ |
| 39 MOJO_SHELL_PATH, | 45 MOJO_SHELL_PATH, |
| 40 '--v=1', | 46 '--v=1', |
| 41 '--content-handlers=%s' % ','.join(content_handlers), | 47 '--content-handlers=%s' % ','.join(content_handlers), |
| 42 '--url-mappings=mojo:window_manager=mojo:sky_debugger', | 48 '--url-mappings=mojo:window_manager=mojo:sky_debugger', |
| 43 'mojo:window_manager', | 49 'mojo:window_manager', |
| 44 ] | 50 ] |
| 45 if args: | 51 if args.url: |
| 46 url = args[0] | 52 url = args.url |
| 47 parse_result = urlparse.urlparse(url) | 53 if not urlparse.urlparse(url).scheme: |
| 48 if not parse_result.scheme: | |
| 49 url = start_http_server_for_file(url) | 54 url = start_http_server_for_file(url) |
| 50 | 55 |
| 51 prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % url | 56 prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % url |
| 52 shell_command.append(prompt_args) | 57 shell_command.append(prompt_args) |
| 58 if args.gdb: |
| 59 shell_command = ['gdb', '--args'] + shell_command |
| 60 |
| 61 print ' '.join(shell_command) |
| 53 subprocess.check_call(shell_command) | 62 subprocess.check_call(shell_command) |
| 54 | 63 |
| 55 | 64 |
| 56 if __name__ == '__main__': | 65 if __name__ == '__main__': |
| 57 main(sys.argv[1:]) | 66 main() |
| OLD | NEW |