| 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 | 16 from pylib.device import device_utils |
| 17 | 17 |
| 18 def _PrintMessage(heading, eol='\n'): | 18 def _PrintMessage(heading, eol='\n'): |
| 19 sys.stdout.write('%s%s' % (heading, eol)) | 19 sys.stdout.write('%s%s' % (heading, eol)) |
| 20 sys.stdout.flush() | 20 sys.stdout.flush() |
| 21 | 21 |
| 22 | 22 |
| 23 def _CaptureScreenshot(adb, host_file): | 23 def _CaptureScreenshot(device, host_file): |
| 24 host_file = adb.TakeScreenshot(host_file) | 24 host_file = device.old_interface.TakeScreenshot(host_file) |
| 25 _PrintMessage('Screenshot written to %s' % os.path.abspath(host_file)) | 25 _PrintMessage('Screenshot written to %s' % os.path.abspath(host_file)) |
| 26 | 26 |
| 27 | 27 |
| 28 def _CaptureVideo(adb, host_file, options): | 28 def _CaptureVideo(device, host_file, options): |
| 29 size = tuple(map(int, options.size.split('x'))) if options.size else None | 29 size = tuple(map(int, options.size.split('x'))) if options.size else None |
| 30 recorder = screenshot.VideoRecorder(adb, | 30 recorder = screenshot.VideoRecorder(device, |
| 31 host_file, | 31 host_file, |
| 32 megabits_per_second=options.bitrate, | 32 megabits_per_second=options.bitrate, |
| 33 size=size, | 33 size=size, |
| 34 rotate=options.rotate) | 34 rotate=options.rotate) |
| 35 try: | 35 try: |
| 36 recorder.Start() | 36 recorder.Start() |
| 37 _PrintMessage('Recording. Press Enter to stop...', eol='') | 37 _PrintMessage('Recording. Press Enter to stop...', eol='') |
| 38 raw_input() | 38 raw_input() |
| 39 finally: | 39 finally: |
| 40 recorder.Stop() | 40 recorder.Stop() |
| (...skipping 29 matching lines...) Expand all Loading... |
| 70 if options.verbose: | 70 if options.verbose: |
| 71 logging.getLogger().setLevel(logging.DEBUG) | 71 logging.getLogger().setLevel(logging.DEBUG) |
| 72 | 72 |
| 73 if not options.device and len(android_commands.GetAttachedDevices()) > 1: | 73 if not options.device and len(android_commands.GetAttachedDevices()) > 1: |
| 74 parser.error('Multiple devices are attached. ' | 74 parser.error('Multiple devices are attached. ' |
| 75 'Please specify device serial number with --device.') | 75 'Please specify device serial number with --device.') |
| 76 | 76 |
| 77 if len(args) > 1: | 77 if len(args) > 1: |
| 78 parser.error('Too many positional arguments.') | 78 parser.error('Too many positional arguments.') |
| 79 host_file = args[0] if args else options.file | 79 host_file = args[0] if args else options.file |
| 80 adb = android_commands.AndroidCommands(options.device) | 80 device = device_utils.DeviceUtils(options.device) |
| 81 | 81 |
| 82 if options.video: | 82 if options.video: |
| 83 _CaptureVideo(adb, host_file, options) | 83 _CaptureVideo(device, host_file, options) |
| 84 else: | 84 else: |
| 85 _CaptureScreenshot(adb, host_file) | 85 _CaptureScreenshot(device, host_file) |
| 86 return 0 | 86 return 0 |
| 87 | 87 |
| 88 | 88 |
| 89 if __name__ == '__main__': | 89 if __name__ == '__main__': |
| 90 sys.exit(main()) | 90 sys.exit(main()) |
| OLD | NEW |