diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2014-06-06 10:30:20 +0300 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2014-06-06 10:30:20 +0300 |
commit | 85c15a40f96d3e14416bcbef1fd76537080798b5 (patch) | |
tree | df527ed05ac60a950c2db0815161415d415dd45b | |
parent | 644fd28c3b77de681dd2d9807ec5a4fa7ee1e875 (diff) |
Add options --host, --port, --verbose and --simulator to tools/ffdb.py
-rwxr-xr-x | tools/ffdb.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/tools/ffdb.py b/tools/ffdb.py index f83749ce..2171cb0e 100755 --- a/tools/ffdb.py +++ b/tools/ffdb.py @@ -151,7 +151,7 @@ def print_applist(applist, running_app_manifests, print_removable): return num_printed def main(): - global b2g_socket, webappsActorName + global b2g_socket, webappsActorName, HOST, PORT, VERBOSE if len(sys.argv) < 2 or '--help' in sys.argv or 'help' in sys.argv or '-v' in sys.argv: print '''Firefox OS Debug Bridge, a tool for automating FFOS device tasks from the command line. @@ -172,21 +172,53 @@ def main(): filename is specified, the screenshot is saved to that file. Otherwise the filename will be autogenerated. + Options: Additionally, the following options may be passed to control FFDB execution: + + --host <hostname>: Specifies the target network address to connect to. Default: 'localhost'. + --port <number>: Specifies the network port to connect to. Default: 6000. + --verbose: Enables verbose printing, mostly useful for debugging. + --simulator: Signal that we will be connecting to a FFOS simulator and not a real device. + In the above, whenever a command requires an <app> to be specified, either the human-readable name, localId or manifestURL of the application can be used.''' sys.exit(0) + connect_to_simulator = False + + options_with_value = ['--host', '--port'] + options = options_with_value + ['--verbose', '--simulator'] + # Process options + for i in range(0, len(sys.argv)): + if sys.argv[i] in options_with_value: + if i+1 >= sys.argv or sys.argv[i+1].startswith('-'): + print >> sys.stderr, "Missing value for option " + sys.argv[i] +'!' + sys.exit(1) + if sys.argv[i] == '--host': + HOST = sys.argv[i+1] + elif sys.argv[i] == '--port': + PORT = int(sys.argv[i+1]) + elif sys.argv[i] == '--verbose': + VERBOSE = True + elif sys.argv[i] == '--simulator': + connect_to_simulator = True + + # Clear the processed options so that parsing the commands below won't trip up on these. + if sys.argv[i] in options: sys.argv[i] = '' + if sys.argv[i] in options_with_value: sys.argv[i+1] = '' + + sys.argv = filter(lambda x: len(x) > 0, sys.argv) + b2g_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: b2g_socket.connect((HOST, PORT)) except Exception, e: if e[0] == 61: # Connection refused - if HOST == 'localhost' or HOST == '127.0.0.1': + if (HOST == 'localhost' or HOST == '127.0.0.1') and not connect_to_simulator: cmd = ['adb', 'forward', 'tcp:'+str(PORT), 'localfilesystem:/data/local/debugger-socket'] print 'Connection to ' + HOST + ':' + str(PORT) + ' refused, attempting to forward device debugger-socket to local address by calling ' + str(cmd) + ':' else: - print 'Error! Failed to connect to B2G device debugger socket at address ' + HOST + ':' + str(PORT) + '!' + print 'Error! Failed to connect to B2G ' + ('simulator' if connect_to_simulator else 'device') + ' debugger socket at address ' + HOST + ':' + str(PORT) + '!' sys.exit(1) try: retcode = subprocess.check_call(cmd) |