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

Side by Side Diff: devil/devil/android/device_utils.py

Issue 1776013005: [DO NOT COMMIT] Refactor systrace to support new clock sync design (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: changes from code review Created 4 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 | systrace/bin/systrace » ('j') | systrace/systrace/systrace_tracing_controller.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 a variety of device interactions based on adb. 5 """Provides a variety of device interactions based on adb.
6 6
7 Eventually, this will be based on adb_wrapper. 7 Eventually, this will be based on adb_wrapper.
8 """ 8 """
9 # pylint: disable=unused-argument 9 # pylint: disable=unused-argument
10 10
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 """ 707 """
708 if self.build_version_sdk < required_sdk_level: 708 if self.build_version_sdk < required_sdk_level:
709 raise device_errors.DeviceVersionError( 709 raise device_errors.DeviceVersionError(
710 ('Requires SDK level %s, device is SDK level %s' % 710 ('Requires SDK level %s, device is SDK level %s' %
711 (required_sdk_level, self.build_version_sdk)), 711 (required_sdk_level, self.build_version_sdk)),
712 device_serial=self.adb.GetDeviceSerial()) 712 device_serial=self.adb.GetDeviceSerial())
713 713
714 @decorators.WithTimeoutAndRetriesFromInstance() 714 @decorators.WithTimeoutAndRetriesFromInstance()
715 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, 715 def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None,
716 as_root=False, single_line=False, large_output=False, 716 as_root=False, single_line=False, large_output=False,
717 timeout=None, retries=None): 717 timeout=None, retries=None, split_lines=True):
718 """Run an ADB shell command. 718 """Run an ADB shell command.
719 719
720 The command to run |cmd| should be a sequence of program arguments or else 720 The command to run |cmd| should be a sequence of program arguments or else
721 a single string. 721 a single string.
722 722
723 When |cmd| is a sequence, it is assumed to contain the name of the command 723 When |cmd| is a sequence, it is assumed to contain the name of the command
724 to run followed by its arguments. In this case, arguments are passed to the 724 to run followed by its arguments. In this case, arguments are passed to the
725 command exactly as given, without any further processing by the shell. This 725 command exactly as given, without any further processing by the shell. This
726 allows to easily pass arguments containing spaces or special characters 726 allows to easily pass arguments containing spaces or special characters
727 without having to worry about getting quoting right. Whenever possible, it 727 without having to worry about getting quoting right. Whenever possible, it
(...skipping 16 matching lines...) Expand all
744 cwd: The device directory in which the command should be run. 744 cwd: The device directory in which the command should be run.
745 env: The environment variables with which the command should be run. 745 env: The environment variables with which the command should be run.
746 as_root: A boolean indicating whether the shell command should be run 746 as_root: A boolean indicating whether the shell command should be run
747 with root privileges. 747 with root privileges.
748 single_line: A boolean indicating if only a single line of output is 748 single_line: A boolean indicating if only a single line of output is
749 expected. 749 expected.
750 large_output: Uses a work-around for large shell command output. Without 750 large_output: Uses a work-around for large shell command output. Without
751 this large output will be truncated. 751 this large output will be truncated.
752 timeout: timeout in seconds 752 timeout: timeout in seconds
753 retries: number of retries 753 retries: number of retries
754 split_lines: Whether to split the output into a list of lines.
754 755
755 Returns: 756 Returns:
756 If single_line is False, the output of the command as a list of lines, 757 If single_line is False, the output of the command as a list of lines,
757 otherwise, a string with the unique line of output emmited by the command 758 otherwise, a string with the unique line of output emmited by the command
758 (with the optional newline at the end stripped). 759 (with the optional newline at the end stripped).
759 760
760 Raises: 761 Raises:
761 AdbCommandFailedError if check_return is True and the exit code of 762 AdbCommandFailedError if check_return is True and the exit code of
762 the command run on the device is non-zero. 763 the command run on the device is non-zero.
763 CommandFailedError if single_line is True but the output contains two or 764 CommandFailedError if single_line is True but the output contains two or
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd) 819 cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd)
819 if env: 820 if env:
820 env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) 821 env = ' '.join(env_quote(k, v) for k, v in env.iteritems())
821 cmd = '%s %s' % (env, cmd) 822 cmd = '%s %s' % (env, cmd)
822 if cwd: 823 if cwd:
823 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) 824 cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd)
824 if as_root and self.NeedsSU(): 825 if as_root and self.NeedsSU():
825 # "su -c sh -c" allows using shell features in |cmd| 826 # "su -c sh -c" allows using shell features in |cmd|
826 cmd = self._Su('sh -c %s' % cmd_helper.SingleQuote(cmd)) 827 cmd = self._Su('sh -c %s' % cmd_helper.SingleQuote(cmd))
827 828
828 output = handle_large_output(cmd, large_output).splitlines() 829 output = handle_large_output(cmd, large_output)
829 830
830 if single_line: 831 if split_lines:
832 output = output.splitlines()
833
834 if split_lines and single_line:
831 if not output: 835 if not output:
832 return '' 836 return ''
833 elif len(output) == 1: 837 elif len(output) == 1:
834 return output[0] 838 return output[0]
835 else: 839 else:
836 msg = 'one line of output was expected, but got: %s' 840 msg = 'one line of output was expected, but got: %s'
837 raise device_errors.CommandFailedError(msg % output, str(self)) 841 raise device_errors.CommandFailedError(msg % output, str(self))
838 else: 842 else:
839 return output 843 return output
840 844
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 on: bool to decide state to switch to. True = on False = off. 2173 on: bool to decide state to switch to. True = on False = off.
2170 """ 2174 """
2171 def screen_test(): 2175 def screen_test():
2172 return self.IsScreenOn() == on 2176 return self.IsScreenOn() == on
2173 2177
2174 if screen_test(): 2178 if screen_test():
2175 logging.info('Screen already in expected state.') 2179 logging.info('Screen already in expected state.')
2176 return 2180 return
2177 self.RunShellCommand('input keyevent 26') 2181 self.RunShellCommand('input keyevent 26')
2178 timeout_retry.WaitFor(screen_test, wait_period=1) 2182 timeout_retry.WaitFor(screen_test, wait_period=1)
OLDNEW
« no previous file with comments | « no previous file | systrace/bin/systrace » ('j') | systrace/systrace/systrace_tracing_controller.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698