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
5 # found in the LICENSE file.
7 """Takes and saves a screenshot from an Android device.
9 Usage: screenshot.py [-s SERIAL] [[-f] FILE]
12 -s SERIAL connect to device with specified SERIAL
13 -f FILE write screenshot to FILE (default: Screenshot.png)
16 from optparse
import OptionParser
20 from pylib
import android_commands
25 parser
= OptionParser(usage
='screenshot.py [-s SERIAL] [[-f] FILE]')
26 parser
.add_option('-s', '--serial', dest
='serial',
27 help='connect to device with specified SERIAL',
28 metavar
='SERIAL', default
=None)
29 parser
.add_option('-f', '--file', dest
='filename',
30 help='write screenshot to FILE (default: %default)',
31 metavar
='FILE', default
='Screenshot.png')
32 (options
, args
) = parser
.parse_args()
34 if not options
.serial
and len(android_commands
.GetAttachedDevices()) > 1:
35 parser
.error('Multiple devices are attached. '
36 'Please specify SERIAL with -s.')
39 parser
.error('Too many positional arguments.')
40 filename
= os
.path
.abspath(args
[0] if args
else options
.filename
)
42 # Grab screenshot and write to disk.
43 ac
= android_commands
.AndroidCommands(options
.serial
)
44 ac
.TakeScreenshot(filename
)
48 if __name__
== '__main__':