Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: build/android/screenshot.py

Issue 11510009: [Android] screenshot.py: handle positional arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 and saves a screenshot from an Android device. 7 """Takes and saves a screenshot from an Android device.
8 8
9 Usage: screenshot.py [-s SERIAL] [-f FILE] 9 Usage: screenshot.py [-s SERIAL] [[-f] FILE]
10 10
11 Options: 11 Options:
12 -s SERIAL connect to device with specified SERIAL 12 -s SERIAL connect to device with specified SERIAL
13 -f FILE write screenshot to FILE (default: Screenshot.png) 13 -f FILE write screenshot to FILE (default: Screenshot.png)
14 """ 14 """
15 15
16 from optparse import OptionParser 16 from optparse import OptionParser
17 import os 17 import os
18 import sys 18 import sys
19 19
20 from pylib import android_commands 20 from pylib import android_commands
21 21
22 22
23 def main(argv): 23 def main():
24 # Parse options. 24 # Parse options.
25 parser = OptionParser() 25 parser = OptionParser(usage='screenshot.py [-s SERIAL] [[-f] FILE]')
26 parser.add_option('-s', '--serial', dest='serial', 26 parser.add_option('-s', '--serial', dest='serial',
27 help='connect to device with specified SERIAL', 27 help='connect to device with specified SERIAL',
28 metavar='SERIAL', default=None) 28 metavar='SERIAL', default=None)
29 parser.add_option('-f', '--file', dest='filename', 29 parser.add_option('-f', '--file', dest='filename',
30 help='write screenshot to FILE (default: %default)', 30 help='write screenshot to FILE (default: %default)',
31 metavar='FILE', default='Screenshot.png') 31 metavar='FILE', default='Screenshot.png')
32 (options, args) = parser.parse_args(argv) 32 (options, args) = parser.parse_args()
33 33
34 if not options.serial and len(android_commands.GetAttachedDevices()) > 1: 34 if not options.serial and len(android_commands.GetAttachedDevices()) > 1:
35 parser.error('Multiple devices are attached. ' 35 parser.error('Multiple devices are attached. '
36 'Please specify SERIAL with -s.') 36 'Please specify SERIAL with -s.')
37 37
38 if len(args) > 1:
39 parser.error('Too many positional arguments.')
40 filename = os.path.abspath(args[0] if args else options.filename)
41
38 # Grab screenshot and write to disk. 42 # Grab screenshot and write to disk.
39 filename = os.path.abspath(options.filename)
40 ac = android_commands.AndroidCommands(options.serial) 43 ac = android_commands.AndroidCommands(options.serial)
41 ac.TakeScreenshot(filename) 44 ac.TakeScreenshot(filename)
42 return 0 45 return 0
43 46
44 47
45 if __name__ == '__main__': 48 if __name__ == '__main__':
46 sys.exit(main(sys.argv)) 49 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698