OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 """Takes a screenshot or a screen video capture from an Android device.""" | 7 """Takes a screenshot or a screen video capture from an Android device.""" |
8 | 8 |
9 import logging | 9 import logging |
10 import optparse | 10 import optparse |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT', | 62 video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT', |
63 help='Frame size to use instead of the device ' | 63 help='Frame size to use instead of the device ' |
64 'screen size.', default=None) | 64 'screen size.', default=None) |
65 parser.add_option_group(video_options) | 65 parser.add_option_group(video_options) |
66 | 66 |
67 (options, args) = parser.parse_args() | 67 (options, args) = parser.parse_args() |
68 | 68 |
69 if options.verbose: | 69 if options.verbose: |
70 logging.getLogger().setLevel(logging.DEBUG) | 70 logging.getLogger().setLevel(logging.DEBUG) |
71 | 71 |
72 if not options.device and len(android_commands.GetAttachedDevices()) > 1: | 72 devices = android_commands.GetAttachedDevices() |
| 73 |
| 74 if not options.device and len(devices) > 1: |
73 parser.error('Multiple devices are attached. ' | 75 parser.error('Multiple devices are attached. ' |
74 'Please specify device serial number with --device.') | 76 'Please specify device serial number with --device.') |
| 77 elif not options.device and len(devices) == 1: |
| 78 options.device = devices[0] |
75 | 79 |
76 if len(args) > 1: | 80 if len(args) > 1: |
77 parser.error('Too many positional arguments.') | 81 parser.error('Too many positional arguments.') |
78 host_file = args[0] if args else options.file | 82 host_file = args[0] if args else options.file |
79 device = device_utils.DeviceUtils(options.device) | 83 device = device_utils.DeviceUtils(options.device) |
80 | 84 |
81 if options.video: | 85 if options.video: |
82 _CaptureVideo(device, host_file, options) | 86 _CaptureVideo(device, host_file, options) |
83 else: | 87 else: |
84 _CaptureScreenshot(device, host_file) | 88 _CaptureScreenshot(device, host_file) |
85 return 0 | 89 return 0 |
86 | 90 |
87 | 91 |
88 if __name__ == '__main__': | 92 if __name__ == '__main__': |
89 sys.exit(main()) | 93 sys.exit(main()) |
OLD | NEW |