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 |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 | 13 |
14 from pylib import android_commands | 14 from pylib import android_commands |
15 from pylib import screenshot | 15 from pylib import screenshot |
16 from pylib.device import device_utils | 16 from pylib.device import device_utils |
17 from pylib.device import adb_wrapper | |
jbudorick
2014/12/16 18:14:20
nit: either switch to adb_wrapper.AdbWrapper.GetDe
Ian Wen
2014/12/16 18:48:37
Done.
| |
17 | 18 |
18 def _PrintMessage(heading, eol='\n'): | 19 def _PrintMessage(heading, eol='\n'): |
19 sys.stdout.write('%s%s' % (heading, eol)) | 20 sys.stdout.write('%s%s' % (heading, eol)) |
20 sys.stdout.flush() | 21 sys.stdout.flush() |
21 | 22 |
22 | 23 |
23 def _CaptureScreenshot(device, host_file): | 24 def _CaptureScreenshot(device, host_file): |
24 host_file = device.TakeScreenshot(host_file) | 25 host_file = device.TakeScreenshot(host_file) |
25 _PrintMessage('Screenshot written to %s' % os.path.abspath(host_file)) | 26 _PrintMessage('Screenshot written to %s' % os.path.abspath(host_file)) |
26 | 27 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT', | 63 video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT', |
63 help='Frame size to use instead of the device ' | 64 help='Frame size to use instead of the device ' |
64 'screen size.', default=None) | 65 'screen size.', default=None) |
65 parser.add_option_group(video_options) | 66 parser.add_option_group(video_options) |
66 | 67 |
67 (options, args) = parser.parse_args() | 68 (options, args) = parser.parse_args() |
68 | 69 |
69 if options.verbose: | 70 if options.verbose: |
70 logging.getLogger().setLevel(logging.DEBUG) | 71 logging.getLogger().setLevel(logging.DEBUG) |
71 | 72 |
72 if not options.device and len(android_commands.GetAttachedDevices()) > 1: | 73 devices = android_commands.GetAttachedDevices() |
74 | |
75 if not options.device and len(devices) > 1: | |
73 parser.error('Multiple devices are attached. ' | 76 parser.error('Multiple devices are attached. ' |
74 'Please specify device serial number with --device.') | 77 'Please specify device serial number with --device.') |
78 elif not options.device and len(devices) == 1: | |
79 options.device = devices[0] | |
75 | 80 |
76 if len(args) > 1: | 81 if len(args) > 1: |
77 parser.error('Too many positional arguments.') | 82 parser.error('Too many positional arguments.') |
78 host_file = args[0] if args else options.file | 83 host_file = args[0] if args else options.file |
79 device = device_utils.DeviceUtils(options.device) | 84 device = device_utils.DeviceUtils(options.device) |
80 | 85 |
81 if options.video: | 86 if options.video: |
82 _CaptureVideo(device, host_file, options) | 87 _CaptureVideo(device, host_file, options) |
83 else: | 88 else: |
84 _CaptureScreenshot(device, host_file) | 89 _CaptureScreenshot(device, host_file) |
85 return 0 | 90 return 0 |
86 | 91 |
87 | 92 |
88 if __name__ == '__main__': | 93 if __name__ == '__main__': |
89 sys.exit(main()) | 94 sys.exit(main()) |
OLD | NEW |