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

Side by Side Diff: devil/devil/android/tools/screenshot.py

Issue 2972253002: [devil] Extract logging common behavior to its own module. (Closed)
Patch Set: mikecase comments and rebase Created 3 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 | « devil/devil/android/tools/provision_devices.py ('k') | devil/devil/utils/logging_common.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 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Takes a screenshot from an Android device.""" 6 """Takes a screenshot from an Android device."""
7 7
8 import argparse 8 import argparse
9 import logging 9 import logging
10 import os 10 import os
11 import sys 11 import sys
12 12
13 if __name__ == '__main__': 13 if __name__ == '__main__':
14 sys.path.append(os.path.abspath(os.path.join( 14 sys.path.append(os.path.abspath(os.path.join(
15 os.path.dirname(__file__), '..', '..', '..'))) 15 os.path.dirname(__file__), '..', '..', '..')))
16 from devil.android import device_utils 16 from devil.android import device_utils
17 from devil.android.tools import script_common 17 from devil.android.tools import script_common
18 from devil.utils import logging_common
18 19
19 logger = logging.getLogger(__name__) 20 logger = logging.getLogger(__name__)
20 21
21 22
22 def main(): 23 def main():
23 # Parse options. 24 # Parse options.
24 parser = argparse.ArgumentParser(description=__doc__) 25 parser = argparse.ArgumentParser(description=__doc__)
26 logging_common.AddLoggingArguments(parser)
25 script_common.AddDeviceArguments(parser) 27 script_common.AddDeviceArguments(parser)
26 parser.add_argument('-f', '--file', metavar='FILE', 28 parser.add_argument('-f', '--file', metavar='FILE',
27 help='Save result to file instead of generating a ' 29 help='Save result to file instead of generating a '
28 'timestamped file name.') 30 'timestamped file name.')
29 parser.add_argument('-v', '--verbose', action='store_true',
30 help='Verbose logging.')
31 parser.add_argument('host_file', nargs='?', 31 parser.add_argument('host_file', nargs='?',
32 help='File to which the screenshot will be saved.') 32 help='File to which the screenshot will be saved.')
33 33
34 args = parser.parse_args() 34 args = parser.parse_args()
35
36 host_file = args.host_file or args.file 35 host_file = args.host_file or args.file
37 36 logging_common.InitializeLogging(args)
38 if args.verbose:
39 logging.getLogger().setLevel(logging.DEBUG)
40 37
41 devices = script_common.GetDevices(args.devices, args.blacklist_file) 38 devices = script_common.GetDevices(args.devices, args.blacklist_file)
42 39
43 def screenshot(device): 40 def screenshot(device):
44 f = None 41 f = None
45 if host_file: 42 if host_file:
46 root, ext = os.path.splitext(host_file) 43 root, ext = os.path.splitext(host_file)
47 f = '%s_%s%s' % (root, str(device), ext) 44 f = '%s_%s%s' % (root, str(device), ext)
48 f = device.TakeScreenshot(f) 45 f = device.TakeScreenshot(f)
49 print 'Screenshot for device %s written to %s' % ( 46 print 'Screenshot for device %s written to %s' % (
50 str(device), os.path.abspath(f)) 47 str(device), os.path.abspath(f))
51 48
52 device_utils.DeviceUtils.parallel(devices).pMap(screenshot) 49 device_utils.DeviceUtils.parallel(devices).pMap(screenshot)
53 return 0 50 return 0
54 51
55 52
56 if __name__ == '__main__': 53 if __name__ == '__main__':
57 sys.exit(main()) 54 sys.exit(main())
OLDNEW
« no previous file with comments | « devil/devil/android/tools/provision_devices.py ('k') | devil/devil/utils/logging_common.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698