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

Side by Side Diff: build/android/adb_reverse_forwarder.py

Issue 1088793002: [Android] Remove android_commands uses from build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2013 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 6
7 """Command line tool for forwarding ports from a device to the host. 7 """Command line tool for forwarding ports from a device to the host.
8 8
9 Allows an Android device to connect to services running on the host machine, 9 Allows an Android device to connect to services running on the host machine,
10 i.e., "adb forward" in reverse. Requires |host_forwarder| and |device_forwarder| 10 i.e., "adb forward" in reverse. Requires |host_forwarder| and |device_forwarder|
11 to be built. 11 to be built.
12 """ 12 """
13 13
14 import logging
14 import optparse 15 import optparse
15 import sys 16 import sys
16 import time 17 import time
17 18
18 from pylib import android_commands 19 from pylib import constants
19 from pylib import constants, forwarder 20 from pylib import forwarder
21 from pylib.device import adb_wrapper
20 from pylib.device import device_utils 22 from pylib.device import device_utils
21 from pylib.utils import run_tests_helper 23 from pylib.utils import run_tests_helper
22 24
23 25
24 def main(argv): 26 def main(argv):
25 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port ' 27 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port '
26 'host_port [device_port_2 host_port_2] ...', 28 'host_port [device_port_2 host_port_2] ...',
27 description=__doc__) 29 description=__doc__)
28 parser.add_option('-v', 30 parser.add_option('-v',
29 '--verbose', 31 '--verbose',
(...skipping 14 matching lines...) Expand all
44 parser.error('Need even number of port pairs') 46 parser.error('Need even number of port pairs')
45 sys.exit(1) 47 sys.exit(1)
46 48
47 try: 49 try:
48 port_pairs = map(int, args[1:]) 50 port_pairs = map(int, args[1:])
49 port_pairs = zip(port_pairs[::2], port_pairs[1::2]) 51 port_pairs = zip(port_pairs[::2], port_pairs[1::2])
50 except ValueError: 52 except ValueError:
51 parser.error('Bad port number') 53 parser.error('Bad port number')
52 sys.exit(1) 54 sys.exit(1)
53 55
54 devices = android_commands.GetAttachedDevices() 56 devices = adb_wrapper.AdbWrapper.GetDevices()
55 57
56 if options.device: 58 if options.device:
57 if options.device not in devices: 59 if options.device not in [d.GetDeviceSerial() for d in devices]:
58 raise Exception('Error: %s not in attached devices %s' % (options.device, 60 raise Exception('Error: %s not in attached devices %s' % (options.device,
59 ','.join(devices))) 61 ','.join(devices)))
60 devices = [options.device] 62 devices = [options.device]
61 else: 63 else:
62 if not devices: 64 if not devices:
63 raise Exception('Error: no connected devices') 65 raise Exception('Error: no connected devices')
64 print "No device specified. Defaulting to " + devices[0] 66 logging.info('No device specified. Defaulting to %s', devices[0])
65 67
66 device = device_utils.DeviceUtils(devices[0]) 68 device = device_utils.DeviceUtils(devices[0])
67 constants.SetBuildType(options.build_type) 69 constants.SetBuildType(options.build_type)
68 try: 70 try:
69 forwarder.Forwarder.Map(port_pairs, device) 71 forwarder.Forwarder.Map(port_pairs, device)
70 while True: 72 while True:
71 time.sleep(60) 73 time.sleep(60)
72 except KeyboardInterrupt: 74 except KeyboardInterrupt:
73 sys.exit(0) 75 sys.exit(0)
74 finally: 76 finally:
75 forwarder.Forwarder.UnmapAllDevicePorts(device) 77 forwarder.Forwarder.UnmapAllDevicePorts(device)
76 78
77 if __name__ == '__main__': 79 if __name__ == '__main__':
78 main(sys.argv) 80 main(sys.argv)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698