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

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

Issue 1281923003: [Android] Add --blacklist-file as a command-line option. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix telemetry_unittests Created 5 years, 4 months 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
« no previous file with comments | « build/android/pylib/utils/test_environment.py ('k') | build/android/test_runner.py » ('j') | 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 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 screenshot 14 from pylib import screenshot
15 from pylib.device import device_blacklist
15 from pylib.device import device_errors 16 from pylib.device import device_errors
16 from pylib.device import device_utils 17 from pylib.device import device_utils
17 18
18 def _PrintMessage(heading, eol='\n'): 19 def _PrintMessage(heading, eol='\n'):
19 sys.stdout.write('%s%s' % (heading, eol)) 20 sys.stdout.write('%s%s' % (heading, eol))
20 sys.stdout.flush() 21 sys.stdout.flush()
21 22
22 23
23 def _CaptureScreenshot(device, host_file): 24 def _CaptureScreenshot(device, host_file):
24 host_file = device.TakeScreenshot(host_file) 25 host_file = device.TakeScreenshot(host_file)
(...skipping 15 matching lines...) Expand all
40 host_file = recorder.Pull(host_file) 41 host_file = recorder.Pull(host_file)
41 _PrintMessage('Video written to %s' % os.path.abspath(host_file)) 42 _PrintMessage('Video written to %s' % os.path.abspath(host_file))
42 43
43 44
44 def main(): 45 def main():
45 # Parse options. 46 # Parse options.
46 parser = optparse.OptionParser(description=__doc__, 47 parser = optparse.OptionParser(description=__doc__,
47 usage='screenshot.py [options] [filename]') 48 usage='screenshot.py [options] [filename]')
48 parser.add_option('-d', '--device', metavar='ANDROID_DEVICE', help='Serial ' 49 parser.add_option('-d', '--device', metavar='ANDROID_DEVICE', help='Serial '
49 'number of Android device to use.', default=None) 50 'number of Android device to use.', default=None)
51 parser.add_option('--blacklist-file', help='Device blacklist JSON file.')
50 parser.add_option('-f', '--file', help='Save result to file instead of ' 52 parser.add_option('-f', '--file', help='Save result to file instead of '
51 'generating a timestamped file name.', metavar='FILE') 53 'generating a timestamped file name.', metavar='FILE')
52 parser.add_option('-v', '--verbose', help='Verbose logging.', 54 parser.add_option('-v', '--verbose', help='Verbose logging.',
53 action='store_true') 55 action='store_true')
54 video_options = optparse.OptionGroup(parser, 'Video capture') 56 video_options = optparse.OptionGroup(parser, 'Video capture')
55 video_options.add_option('--video', help='Enable video capturing. Requires ' 57 video_options.add_option('--video', help='Enable video capturing. Requires '
56 'Android KitKat or later', action='store_true') 58 'Android KitKat or later', action='store_true')
57 video_options.add_option('-b', '--bitrate', help='Bitrate in megabits/s, ' 59 video_options.add_option('-b', '--bitrate', help='Bitrate in megabits/s, '
58 'from 0.1 to 100 mbps, %default mbps by default.', 60 'from 0.1 to 100 mbps, %default mbps by default.',
59 default=4, type='float') 61 default=4, type='float')
60 video_options.add_option('-r', '--rotate', help='Rotate video by 90 degrees.', 62 video_options.add_option('-r', '--rotate', help='Rotate video by 90 degrees.',
61 default=False, action='store_true') 63 default=False, action='store_true')
62 video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT', 64 video_options.add_option('-s', '--size', metavar='WIDTHxHEIGHT',
63 help='Frame size to use instead of the device ' 65 help='Frame size to use instead of the device '
64 'screen size.', default=None) 66 'screen size.', default=None)
65 parser.add_option_group(video_options) 67 parser.add_option_group(video_options)
66 68
67 (options, args) = parser.parse_args() 69 (options, args) = parser.parse_args()
68 70
69 if len(args) > 1: 71 if len(args) > 1:
70 parser.error('Too many positional arguments.') 72 parser.error('Too many positional arguments.')
71 host_file = args[0] if args else options.file 73 host_file = args[0] if args else options.file
72 74
73 if options.verbose: 75 if options.verbose:
74 logging.getLogger().setLevel(logging.DEBUG) 76 logging.getLogger().setLevel(logging.DEBUG)
75 77
76 devices = device_utils.DeviceUtils.HealthyDevices() 78 if options.blacklist_file:
79 blacklist = device_blacklist.Blacklist(options.blacklist_file)
80 else:
81 blacklist = None
82
83 devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
77 if options.device: 84 if options.device:
78 device = next((d for d in devices if d == options.device), None) 85 device = next((d for d in devices if d == options.device), None)
79 if not device: 86 if not device:
80 raise device_errors.DeviceUnreachableError(options.device) 87 raise device_errors.DeviceUnreachableError(options.device)
81 else: 88 else:
82 if len(devices) > 1: 89 if len(devices) > 1:
83 parser.error('Multiple devices are attached. ' 90 parser.error('Multiple devices are attached. '
84 'Please specify device serial number with --device.') 91 'Please specify device serial number with --device.')
85 elif len(devices) == 1: 92 elif len(devices) == 1:
86 device = devices[0] 93 device = devices[0]
87 else: 94 else:
88 raise device_errors.NoDevicesError() 95 raise device_errors.NoDevicesError()
89 96
90 if options.video: 97 if options.video:
91 _CaptureVideo(device, host_file, options) 98 _CaptureVideo(device, host_file, options)
92 else: 99 else:
93 _CaptureScreenshot(device, host_file) 100 _CaptureScreenshot(device, host_file)
94 return 0 101 return 0
95 102
96 103
97 if __name__ == '__main__': 104 if __name__ == '__main__':
98 sys.exit(main()) 105 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/pylib/utils/test_environment.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698