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

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

Issue 11828051: [Android] Add a command line tool for reverse port forwarding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 """Command line tool for forwarding ports from a device to the host.
8
9 Allows an Android device to connect to services running on the host machine,
10 i.e., "adb forward" in reverse.
bulach 2013/01/10 19:43:23 Requires |host_forwarder| and |device_forwarder| t
11 """
12
13 import optparse
14 import sys
15 import time
16
17 from pylib import android_commands, forwarder
18 from pylib.utils import run_tests_helper
19
20
21 def main(argv):
22 parser = optparse.OptionParser(usage='Usage: %prog [options] device_port '
23 'host_port [device_port_2 host_port_2] ...',
24 description=__doc__)
25 parser.add_option('-v',
26 '--verbose',
27 dest='verbose_count',
28 default=0,
29 action='count',
30 help='Verbose level (multiple times for more)')
31 parser.add_option('--device',
32 help='Serial number of device we should use.')
33 parser.add_option('--host',
34 help='Host address to forward to from the host machine. '
35 '127.0.0.1 by default', default='127.0.0.1')
36 parser.add_option('--debug', action='store_const', const='Debug',
37 dest='build_type', default='Release',
38 help='Use Debug build of host tools instead of Release.')
39
40 options, args = parser.parse_args(argv)
41 run_tests_helper.SetLogLevel(options.verbose_count)
42
43 if len(args) < 2 or not len(args) % 2:
44 parser.error('Need even number of port pairs')
45 sys.exit(1)
46
47 try:
48 port_pairs = map(int, args[1:])
49 port_pairs = zip(port_pairs[::2], port_pairs[1::2])
50 except ValueError:
51 parser.error('Bad port number')
52 sys.exit(1)
53
54 adb = android_commands.AndroidCommands(options.device)
55 forwarder_instance = forwarder.Forwarder(adb, options.build_type)
56 try:
57 forwarder_instance.Run(port_pairs, None, options.host)
58 while True:
59 time.sleep(60)
60 except KeyboardInterrupt:
61 sys.exit(0)
62 finally:
63 forwarder_instance.Close()
64
65
66 if __name__ == '__main__':
67 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698