OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 argparse |
7 import json | 7 import json |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 22 matching lines...) Expand all Loading... |
33 'sky_server_root', | 33 'sky_server_root', |
34 'build_dir', | 34 'build_dir', |
35 ]) | 35 ]) |
36 | 36 |
37 | 37 |
38 def _port_in_use(port): | 38 def _port_in_use(port): |
39 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 39 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
40 return sock.connect_ex(('localhost', port)) == 0 | 40 return sock.connect_ex(('localhost', port)) == 0 |
41 | 41 |
42 | 42 |
43 # We need something to serve sky files, python's httpserver is sufficient. | 43 # We need something to serve dart files, python's httpserver is sufficient. |
44 def _start_http_server(port, root): | 44 def _start_http_server(port, root): |
45 server_command = [ | 45 server_command = [ |
46 'python', '-m', 'SimpleHTTPServer', str(port), | 46 'python', '-m', 'SimpleHTTPServer', str(port), |
47 ] | 47 ] |
48 return subprocess.Popen(server_command, cwd=root).pid | 48 return subprocess.Popen(server_command, cwd=root).pid |
49 | 49 |
50 | 50 |
51 # This 'strict dictionary' approach is useful for catching typos. | 51 # This 'strict dictionary' approach is useful for catching typos. |
52 class Pids(object): | 52 class Pids(object): |
53 def __init__(self, known_keys, contents=None): | 53 def __init__(self, known_keys, contents=None): |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 relative_path = os.path.relpath(path, root) | 110 relative_path = os.path.relpath(path, root) |
111 return 'sky://localhost:%s/%s' % (port, relative_path) | 111 return 'sky://localhost:%s/%s' % (port, relative_path) |
112 | 112 |
113 | 113 |
114 class StartSky(object): | 114 class StartSky(object): |
115 def add_subparser(self, subparsers): | 115 def add_subparser(self, subparsers): |
116 start_parser = subparsers.add_parser('start', | 116 start_parser = subparsers.add_parser('start', |
117 help='launch %s on the device' % APK_NAME) | 117 help='launch %s on the device' % APK_NAME) |
118 start_parser.add_argument('--install', action='store_true') | 118 start_parser.add_argument('--install', action='store_true') |
119 start_parser.add_argument('project_or_path', nargs='?', type=str, | 119 start_parser.add_argument('project_or_path', nargs='?', type=str, |
120 default='main.sky') | 120 default='main.dart') |
121 start_parser.set_defaults(func=self.run) | 121 start_parser.set_defaults(func=self.run) |
122 | 122 |
123 def _is_package_installed(self, package_name): | 123 def _is_package_installed(self, package_name): |
124 pm_path_cmd = [ADB_PATH, 'shell', 'pm', 'path', package_name] | 124 pm_path_cmd = [ADB_PATH, 'shell', 'pm', 'path', package_name] |
125 return subprocess.check_output(pm_path_cmd).strip() != '' | 125 return subprocess.check_output(pm_path_cmd).strip() != '' |
126 | 126 |
127 def run(self, args, pids): | 127 def run(self, args, pids): |
128 StopSky().run(args, pids) | 128 StopSky().run(args, pids) |
129 | 129 |
130 if not self._is_package_installed(ANDROID_PACKAGE): | 130 if not self._is_package_installed(ANDROID_PACKAGE): |
131 print '%s is not installed, installing.' % APK_NAME | 131 print '%s is not installed, installing.' % APK_NAME |
132 args.install = True | 132 args.install = True |
133 | 133 |
134 if args.install: | 134 if args.install: |
135 apk_path = os.path.join(SKY_PACKAGE_ROOT, 'apks', APK_NAME) | 135 apk_path = os.path.join(SKY_PACKAGE_ROOT, 'apks', APK_NAME) |
136 if not os.path.exists(apk_path): | 136 if not os.path.exists(apk_path): |
137 print "'%s' does not exist?" % apk_path | 137 print "'%s' does not exist?" % apk_path |
138 return 2 | 138 return 2 |
139 | 139 |
140 subprocess.check_call([ADB_PATH, 'install', '-r', apk_path]) | 140 subprocess.check_call([ADB_PATH, 'install', '-r', apk_path]) |
141 | 141 |
142 project_or_path = os.path.abspath(args.project_or_path) | 142 project_or_path = os.path.abspath(args.project_or_path) |
143 | 143 |
144 if os.path.isdir(project_or_path): | 144 if os.path.isdir(project_or_path): |
145 sky_server_root = project_or_path | 145 sky_server_root = project_or_path |
146 main_sky = os.path.join(project_or_path, 'main.sky') | 146 main_sky = os.path.join(project_or_path, 'main.dart') |
147 missing_msg = "Missing main.sky in project: %s" % sky_server_root | 147 missing_msg = "Missing main.dart in project: %s" % sky_server_root |
148 else: | 148 else: |
149 sky_server_root = os.path.dirname(project_or_path) | 149 sky_server_root = os.path.dirname(project_or_path) |
150 main_sky = project_or_path | 150 main_sky = project_or_path |
151 missing_msg = "%s does not exist." % main_sky | 151 missing_msg = "%s does not exist." % main_sky |
152 | 152 |
153 if not os.path.isfile(main_sky): | 153 if not os.path.isfile(main_sky): |
154 print missing_msg | 154 print missing_msg |
155 return 2 | 155 return 2 |
156 | 156 |
157 sky_server_port = SKY_SERVER_PORT | 157 sky_server_port = SKY_SERVER_PORT |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 args = parser.parse_args() | 278 args = parser.parse_args() |
279 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS) | 279 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS) |
280 exit_code = args.func(args, pids) | 280 exit_code = args.func(args, pids) |
281 # We could do this with an at-exit handler instead? | 281 # We could do this with an at-exit handler instead? |
282 pids.write_to(PID_FILE_PATH) | 282 pids.write_to(PID_FILE_PATH) |
283 sys.exit(exit_code) | 283 sys.exit(exit_code) |
284 | 284 |
285 | 285 |
286 if __name__ == '__main__': | 286 if __name__ == '__main__': |
287 SkyShellRunner().main() | 287 SkyShellRunner().main() |
OLD | NEW |