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

Side by Side Diff: sky/tools/skydb

Issue 692163002: Fix urls under /sky to work again (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« sky/tools/sky_server ('K') | « sky/tools/sky_server ('k') | 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 # 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 argparse
7 import os 7 import os
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import urlparse 10 import urlparse
11 import logging 11 import logging
12 import socket; 12 import socket;
13 13
14 14
15 OUT_DIR = 'out' 15 OUT_DIR = 'out'
16 CONFIG_NAME = 'Debug' 16 CONFIG_NAME = 'Debug'
17 SKY_TOOLS_DIRECTORY = os.path.abspath(os.path.join(__file__, os.pardir)) 17 SKY_TOOLS_DIRECTORY = os.path.abspath(os.path.join(__file__, os.pardir))
18 MOJO_ROOT = os.path.abspath(os.path.join(SKY_TOOLS_DIRECTORY, os.pardir, 18 MOJO_ROOT = os.path.abspath(os.path.join(SKY_TOOLS_DIRECTORY, os.pardir,
19 os.pardir)) 19 os.pardir))
20 MOJO_SHELL_PATH = os.path.join(MOJO_ROOT, OUT_DIR, CONFIG_NAME, 'mojo_shell') 20 MOJO_SHELL_PATH = os.path.join(MOJO_ROOT, OUT_DIR, CONFIG_NAME, 'mojo_shell')
21 21
22 SUPPORTED_MIME_TYPES = [ 22 SUPPORTED_MIME_TYPES = [
23 'text/html', 23 'text/html',
24 'text/sky', 24 'text/sky',
25 'text/plain', 25 'text/plain',
26 ] 26 ]
27 27
28 class SkyDebugger(object): 28 class SkyDebugger(object):
29 def __init__(self):
30 self._sky_server = None
31
29 @staticmethod 32 @staticmethod
30 def _port_in_use(port): 33 def _port_in_use(port):
31 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 34 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
32 return sock.connect_ex(('localhost', port)) == 0 35 return sock.connect_ex(('localhost', port)) == 0
33 36
34 def _start_http_server_for_file(self, path): 37 def _start_http_server_for_file(self, path):
35 HTTP_PORT = 9999 38 HTTP_PORT = 9999
36 39
37 path = os.path.abspath(path) 40 path = os.path.abspath(path)
38 if os.path.commonprefix([path, MOJO_ROOT]) == MOJO_ROOT: 41 if os.path.commonprefix([path, MOJO_ROOT]) == MOJO_ROOT:
39 server_root = MOJO_ROOT 42 server_root = MOJO_ROOT
40 else: 43 else:
41 server_root = os.path.dirname(path) 44 server_root = os.path.dirname(path)
42 logging.warn( 45 logging.warn(
43 '%s is outside of mojo root, using %s as server root' % 46 '%s is outside of mojo root, using %s as server root' %
44 (path, server_root)) 47 (path, server_root))
45 relative_path = os.path.relpath(path, server_root) 48 relative_path = os.path.relpath(path, server_root)
46 49
47 if self._port_in_use(HTTP_PORT): 50 if self._port_in_use(HTTP_PORT):
48 logging.warn( 51 logging.warn(
49 'Port %s already in use, assuming custom sky_server started.') 52 'Port %s already in use, assuming custom sky_server started.' %
53 HTTP_PORT)
50 else: 54 else:
51 server_command = [ 55 server_command = [
52 os.path.join(SKY_TOOLS_DIRECTORY, 'sky_server'), 56 os.path.join(SKY_TOOLS_DIRECTORY, 'sky_server'),
53 server_root, 57 server_root,
54 str(HTTP_PORT), 58 str(HTTP_PORT),
55 ] 59 ]
56 self._sky_server = subprocess.Popen(server_command) 60 self._sky_server = subprocess.Popen(server_command)
57 return 'http://localhost:%s/%s' % (HTTP_PORT, relative_path) 61 return 'http://localhost:%s/%s' % (HTTP_PORT, relative_path)
58 62
59 def main(self): 63 def main(self):
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 96
93 97
94 if __name__ == '__main__': 98 if __name__ == '__main__':
95 skydb = SkyDebugger() 99 skydb = SkyDebugger()
96 try: 100 try:
97 skydb.main() 101 skydb.main()
98 except (KeyboardInterrupt, SystemExit): 102 except (KeyboardInterrupt, SystemExit):
99 pass 103 pass
100 finally: 104 finally:
101 skydb.shutdown() 105 skydb.shutdown()
OLDNEW
« sky/tools/sky_server ('K') | « sky/tools/sky_server ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698