John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import argparse |
| 7 | import logging |
| 8 | import sys |
| 9 | |
msw | 209e4b1 | 2015-04-23 20:31:30 | [diff] [blame] | 10 | from mopy.android import AndroidShell |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 11 | from mopy.config import Config |
msw | 209e4b1 | 2015-04-23 20:31:30 | [diff] [blame] | 12 | |
msw | b54a5f9c | 2015-07-15 23:10:59 | [diff] [blame] | 13 | USAGE = ('android_mojo_shell.py [<shell-and-app-args>] [<mojo-app>]') |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 14 | |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 15 | def main(): |
| 16 | logging.basicConfig() |
| 17 | |
msw | 209e4b1 | 2015-04-23 20:31:30 | [diff] [blame] | 18 | parser = argparse.ArgumentParser(usage=USAGE) |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 19 | |
| 20 | debug_group = parser.add_mutually_exclusive_group() |
| 21 | debug_group.add_argument('--debug', help='Debug build (default)', |
| 22 | default=True, action='store_true') |
| 23 | debug_group.add_argument('--release', help='Release build', default=False, |
| 24 | dest='debug', action='store_false') |
| 25 | parser.add_argument('--target-cpu', help='CPU architecture to run for.', |
msw | 6c8ec83 | 2015-05-18 20:16:35 | [diff] [blame] | 26 | choices=['x64', 'x86', 'arm'], default='arm') |
msw | 7e92ef9c | 2015-06-02 01:27:22 | [diff] [blame] | 27 | parser.add_argument('--device', help='Serial number of the target device.') |
msw | b54a5f9c | 2015-07-15 23:10:59 | [diff] [blame] | 28 | parser.add_argument('--verbose', default=False, action='store_true') |
sadrul | 14238f7 | 2015-07-24 22:58:35 | [diff] [blame] | 29 | parser.add_argument('--apk', help='Name of the APK to run.', |
| 30 | default='MojoRunner.apk') |
msw | 7e92ef9c | 2015-06-02 01:27:22 | [diff] [blame] | 31 | runner_args, args = parser.parse_known_args() |
| 32 | |
| 33 | logger = logging.getLogger() |
msw | b54a5f9c | 2015-07-15 23:10:59 | [diff] [blame] | 34 | logging.basicConfig(stream=sys.stdout, format='%(levelname)s:%(message)s') |
msw | 7e92ef9c | 2015-06-02 01:27:22 | [diff] [blame] | 35 | logger.setLevel(logging.DEBUG if runner_args.verbose else logging.WARNING) |
msw | b54a5f9c | 2015-07-15 23:10:59 | [diff] [blame] | 36 | logger.debug('Initialized logging: level=%s' % logger.level) |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 37 | |
| 38 | config = Config(target_os=Config.OS_ANDROID, |
msw | 7e92ef9c | 2015-06-02 01:27:22 | [diff] [blame] | 39 | target_cpu=runner_args.target_cpu, |
| 40 | is_debug=runner_args.debug, |
sadrul | 74d65353 | 2015-07-28 22:56:28 | [diff] [blame] | 41 | is_verbose=runner_args.verbose, |
sadrul | 14238f7 | 2015-07-24 22:58:35 | [diff] [blame] | 42 | apk_name=runner_args.apk) |
msw | 7e92ef9c | 2015-06-02 01:27:22 | [diff] [blame] | 43 | shell = AndroidShell(config) |
sadrul | 2075cfb | 2015-07-30 07:18:17 | [diff] [blame] | 44 | shell.InitShell(runner_args.device) |
msw | 209e4b1 | 2015-04-23 20:31:30 | [diff] [blame] | 45 | p = shell.ShowLogs() |
ben | 05d2eea | 2015-06-11 23:38:02 | [diff] [blame] | 46 | shell.StartActivity('MojoShellActivity', args, sys.stdout, p.terminate) |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 47 | return 0 |
| 48 | |
| 49 | |
msw | b54a5f9c | 2015-07-15 23:10:59 | [diff] [blame] | 50 | if __name__ == '__main__': |
John Abd-El-Malek | da4596e | 2015-04-02 19:16:53 | [diff] [blame] | 51 | sys.exit(main()) |