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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 (options, args) = parser.parse_args() | 67 (options, args) = parser.parse_args() |
68 | 68 |
69 if len(args) > 1: | 69 if len(args) > 1: |
70 parser.error('Too many positional arguments.') | 70 parser.error('Too many positional arguments.') |
71 host_file = args[0] if args else options.file | 71 host_file = args[0] if args else options.file |
72 | 72 |
73 if options.verbose: | 73 if options.verbose: |
74 logging.getLogger().setLevel(logging.DEBUG) | 74 logging.getLogger().setLevel(logging.DEBUG) |
75 | 75 |
76 devices = device_utils.DeviceUtils.HealthyDevices() | 76 devices = device_utils.DeviceUtils.HealthyDevices() |
77 | 77 if options.device: |
78 if not options.device: | 78 device = next((d for d in devices if d == options.device), None) |
| 79 if not device: |
| 80 raise device_errors.DeviceUnreachableError(options.device) |
| 81 else: |
79 if len(devices) > 1: | 82 if len(devices) > 1: |
80 parser.error('Multiple devices are attached. ' | 83 parser.error('Multiple devices are attached. ' |
81 'Please specify device serial number with --device.') | 84 'Please specify device serial number with --device.') |
82 elif len(devices) == 1: | 85 elif len(devices) == 1: |
83 device = devices[0] | 86 device = devices[0] |
84 else: | 87 else: |
85 raise device_errors.NoDevicesError() | 88 raise device_errors.NoDevicesError() |
86 else: | |
87 device = device_utils.DeviceUtils(options.device) | |
88 | 89 |
89 if options.video: | 90 if options.video: |
90 _CaptureVideo(device, host_file, options) | 91 _CaptureVideo(device, host_file, options) |
91 else: | 92 else: |
92 _CaptureScreenshot(device, host_file) | 93 _CaptureScreenshot(device, host_file) |
93 return 0 | 94 return 0 |
94 | 95 |
95 | 96 |
96 if __name__ == '__main__': | 97 if __name__ == '__main__': |
97 sys.exit(main()) | 98 sys.exit(main()) |
OLD | NEW |