Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / build / android / screenshot.py
blob86607cc0649349b5991cac456cdeb3e7e5e3e8b8
1 #!/usr/bin/env python
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]
11 Options:
12 -s SERIAL connect to device with specified SERIAL
13 -f FILE write screenshot to FILE (default: Screenshot.png)
14 """
16 from optparse import OptionParser
17 import os
18 import sys
20 from pylib import android_commands
23 def main():
24 # Parse options.
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.')
38 if len(args) > 1:
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)
45 return 0
48 if __name__ == '__main__':
49 sys.exit(main())