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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 234803006: [Android] Move screenshot implementation back into AndroidCommands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + default host_path=None Created 6 years, 8 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 | « no previous file | build/android/pylib/screenshot.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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Provides an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 # pylint: disable-all 9 # pylint: disable-all
10 10
11 import collections 11 import collections
12 import datetime 12 import datetime
13 import inspect 13 import inspect
14 import json 14 import json
15 import logging 15 import logging
16 import os 16 import os
17 import re 17 import re
18 import shlex 18 import shlex
19 import signal 19 import signal
20 import subprocess 20 import subprocess
21 import sys 21 import sys
22 import tempfile 22 import tempfile
23 import time 23 import time
24 24
25 import cmd_helper 25 import cmd_helper
26 import constants 26 import constants
27 import screenshot
28 import system_properties 27 import system_properties
29 from utils import host_utils 28 from utils import host_utils
30 from device import device_utils
31 29
32 try: 30 try:
33 from pylib import pexpect 31 from pylib import pexpect
34 except ImportError: 32 except ImportError:
35 pexpect = None 33 pexpect = None
36 34
37 sys.path.append(os.path.join( 35 sys.path.append(os.path.join(
38 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) 36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner'))
39 import adb_interface 37 import adb_interface
40 import am_instrument_parser 38 import am_instrument_parser
(...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 if 'test: not found' not in status: 1703 if 'test: not found' not in status:
1706 return int(status) == 0 1704 return int(status) == 0
1707 raise errors.AbortError('"test" binary not found. OS too old.') 1705 raise errors.AbortError('"test" binary not found. OS too old.')
1708 1706
1709 except ValueError: 1707 except ValueError:
1710 if IsDeviceAttached(self._device): 1708 if IsDeviceAttached(self._device):
1711 raise errors.DeviceUnresponsiveError('Device may be offline.') 1709 raise errors.DeviceUnresponsiveError('Device may be offline.')
1712 1710
1713 return False 1711 return False
1714 1712
1715 def TakeScreenshot(self, host_file): 1713 @staticmethod
1714 def GetTimestamp():
1715 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime())
1716
1717 @staticmethod
1718 def EnsureHostDirectory(host_file):
1719 host_dir = os.path.dirname(os.path.abspath(host_file))
1720 if not os.path.exists(host_dir):
1721 os.makedirs(host_dir)
1722
1723 def TakeScreenshot(self, host_file=None):
1716 """Saves a screenshot image to |host_file| on the host. 1724 """Saves a screenshot image to |host_file| on the host.
1717 1725
1718 Args: 1726 Args:
1719 host_file: Absolute path to the image file to store on the host or None to 1727 host_file: Absolute path to the image file to store on the host or None to
1720 use an autogenerated file name. 1728 use an autogenerated file name.
1721 1729
1722 Returns: 1730 Returns:
1723 Resulting host file name of the screenshot. 1731 Resulting host file name of the screenshot.
1724 """ 1732 """
1725 return screenshot.TakeScreenshot(device_utils.DeviceUtils(self), host_file) 1733 host_file = os.path.abspath(host_file or
1734 'screenshot-%s.png' % self.GetTimestamp())
1735 self.EnsureHostDirectory(host_file)
1736 device_file = '%s/screenshot.png' % self.GetExternalStorage()
1737 self.RunShellCommand(
1738 '/system/bin/screencap -p %s' % device_file)
1739 self.PullFileFromDevice(device_file, host_file)
1740 self.RunShellCommand('rm -f "%s"' % device_file)
1741 return host_file
1726 1742
1727 def PullFileFromDevice(self, device_file, host_file): 1743 def PullFileFromDevice(self, device_file, host_file):
1728 """Download |device_file| on the device from to |host_file| on the host. 1744 """Download |device_file| on the device from to |host_file| on the host.
1729 1745
1730 Args: 1746 Args:
1731 device_file: Absolute path to the file to retrieve from the device. 1747 device_file: Absolute path to the file to retrieve from the device.
1732 host_file: Absolute path to the file to store on the host. 1748 host_file: Absolute path to the file to store on the host.
1733 """ 1749 """
1734 assert self._adb.Pull(device_file, host_file) 1750 assert self._adb.Pull(device_file, host_file)
1735 assert os.path.exists(host_file) 1751 assert os.path.exists(host_file)
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 """ 1924 """
1909 def __init__(self, output): 1925 def __init__(self, output):
1910 self._output = output 1926 self._output = output
1911 1927
1912 def write(self, data): 1928 def write(self, data):
1913 data = data.replace('\r\r\n', '\n') 1929 data = data.replace('\r\r\n', '\n')
1914 self._output.write(data) 1930 self._output.write(data)
1915 1931
1916 def flush(self): 1932 def flush(self):
1917 self._output.flush() 1933 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/screenshot.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698