[Android] Add screenshot command line tool.

This modifies the no longer used monkeyrunner_screenshot.py into a
simple screenshot tool.

BUG=164644

Review URL: https://codereview.chromium.org/11470004

git-svn-id: http://src.chromium.org/svn/trunk/src/build@171615 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
newt@chromium.org 2012-12-06 22:47:36 +00:00
Родитель 55e53eb332
Коммит 01a368d9b8
2 изменённых файлов: 46 добавлений и 41 удалений

Просмотреть файл

@ -1,41 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import sys
from optparse import OptionParser
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
def main(argv):
# Parse options.
parser = OptionParser()
parser.add_option("--serial", dest="serial",
help="connect to device with specified SERIAL",
metavar="SERIAL")
parser.add_option("--file", dest="filename",
help="write screenshot to FILE",
metavar="FILE", default="Screenshot.png")
parser.add_option("--timeout", dest="timeout",
help="TIMEOUT in seconds for connecting to a device",
metavar="TIMEOUT", default=120)
(options, args) = parser.parse_args(argv)
# Connect to the current device, returning a MonkeyDevice object.
# Monkeyrunner fails with a NullPointerException if options.serial is None.
if options.serial:
device = MonkeyRunner.waitForConnection(options.timeout, options.serial)
else:
device = MonkeyRunner.waitForConnection(options.timeout)
if not device:
return 1
# Grab screenshot and write to disk.
result = device.takeSnapshot()
result.writeToFile(options.filename, 'png')
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))

46
android/screenshot.py Executable file
Просмотреть файл

@ -0,0 +1,46 @@
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Takes and saves a screenshot from an Android device.
Usage: screenshot.py [-s SERIAL] [-f FILE]
Options:
-s SERIAL connect to device with specified SERIAL
-f FILE write screenshot to FILE (default: Screenshot.png)
"""
from optparse import OptionParser
import os
import sys
from pylib import android_commands
def main(argv):
# Parse options.
parser = OptionParser()
parser.add_option('-s', '--serial', dest='serial',
help='connect to device with specified SERIAL',
metavar='SERIAL', default=None)
parser.add_option('-f', '--file', dest='filename',
help='write screenshot to FILE (default: %default)',
metavar='FILE', default='Screenshot.png')
(options, args) = parser.parse_args(argv)
if not options.serial and len(android_commands.GetAttachedDevices()) > 1:
parser.error('Multiple devices are attached. '
'Please specify SERIAL with -s.')
# Grab screenshot and write to disk.
filename = os.path.abspath(options.filename)
ac = android_commands.AndroidCommands(options.serial)
ac.TakeScreenshot(filename)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))