OLD | NEW |
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 | 9 |
10 import collections | 10 import collections |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 time.sleep(wait_period) | 397 time.sleep(wait_period) |
398 attempts += 1 | 398 attempts += 1 |
399 if not sdcard_ready: | 399 if not sdcard_ready: |
400 raise errors.WaitForResponseTimedOutError( | 400 raise errors.WaitForResponseTimedOutError( |
401 'SD card not ready after %s seconds' % timeout_time) | 401 'SD card not ready after %s seconds' % timeout_time) |
402 | 402 |
403 # It is tempting to turn this function into a generator, however this is not | 403 # It is tempting to turn this function into a generator, however this is not |
404 # possible without using a private (local) adb_shell instance (to ensure no | 404 # possible without using a private (local) adb_shell instance (to ensure no |
405 # other command interleaves usage of it), which would defeat the main aim of | 405 # other command interleaves usage of it), which would defeat the main aim of |
406 # being able to reuse the adb shell instance across commands. | 406 # being able to reuse the adb shell instance across commands. |
407 def RunShellCommand(self, command, timeout_time=20, log_result=True): | 407 def RunShellCommand(self, command, timeout_time=20, log_result=False): |
408 """Send a command to the adb shell and return the result. | 408 """Send a command to the adb shell and return the result. |
409 | 409 |
410 Args: | 410 Args: |
411 command: String containing the shell command to send. Must not include | 411 command: String containing the shell command to send. Must not include |
412 the single quotes as we use them to escape the whole command. | 412 the single quotes as we use them to escape the whole command. |
413 timeout_time: Number of seconds to wait for command to respond before | 413 timeout_time: Number of seconds to wait for command to respond before |
414 retrying, used by AdbInterface.SendShellCommand. | 414 retrying, used by AdbInterface.SendShellCommand. |
415 log_result: Boolean to indicate whether we should log the result of the | 415 log_result: Boolean to indicate whether we should log the result of the |
416 shell command. | 416 shell command. |
417 | 417 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 # 60 seconds which isn't sufficient for a lot of users of this method. | 544 # 60 seconds which isn't sufficient for a lot of users of this method. |
545 push_command = 'push %s %s' % (local_path, device_path) | 545 push_command = 'push %s %s' % (local_path, device_path) |
546 logging.info('>>> $' + push_command) | 546 logging.info('>>> $' + push_command) |
547 output = self._adb.SendCommand(push_command, timeout_time=30*60) | 547 output = self._adb.SendCommand(push_command, timeout_time=30*60) |
548 assert output | 548 assert output |
549 # Success looks like this: "3035 KB/s (12512056 bytes in 4.025s)" | 549 # Success looks like this: "3035 KB/s (12512056 bytes in 4.025s)" |
550 # Errors look like this: "failed to copy ... " | 550 # Errors look like this: "failed to copy ... " |
551 if not re.search('^[0-9]', output.splitlines()[-1]): | 551 if not re.search('^[0-9]', output.splitlines()[-1]): |
552 logging.critical('PUSH FAILED: ' + output) | 552 logging.critical('PUSH FAILED: ' + output) |
553 | 553 |
554 def GetFileContents(self, filename, log_result=True): | 554 def GetFileContents(self, filename, log_result=False): |
555 """Gets contents from the file specified by |filename|.""" | 555 """Gets contents from the file specified by |filename|.""" |
556 return self.RunShellCommand('if [ -f "' + filename + '" ]; then cat "' + | 556 return self.RunShellCommand('if [ -f "' + filename + '" ]; then cat "' + |
557 filename + '"; fi', log_result=log_result) | 557 filename + '"; fi', log_result=log_result) |
558 | 558 |
559 def SetFileContents(self, filename, contents): | 559 def SetFileContents(self, filename, contents): |
560 """Writes |contents| to the file specified by |filename|.""" | 560 """Writes |contents| to the file specified by |filename|.""" |
561 with tempfile.NamedTemporaryFile() as f: | 561 with tempfile.NamedTemporaryFile() as f: |
562 f.write(contents) | 562 f.write(contents) |
563 f.flush() | 563 f.flush() |
564 self._adb.Push(f.name, filename) | 564 self._adb.Push(f.name, filename) |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 if len(process_results) <= 8: | 948 if len(process_results) <= 8: |
949 continue | 949 continue |
950 # Column 0 is the executable name | 950 # Column 0 is the executable name |
951 # Column 1 is the pid | 951 # Column 1 is the pid |
952 # Column 8 is the Inode in use | 952 # Column 8 is the Inode in use |
953 if process_results[8] == socket_name: | 953 if process_results[8] == socket_name: |
954 pids.append( (int(process_results[1]), process_results[0]) ) | 954 pids.append( (int(process_results[1]), process_results[0]) ) |
955 break | 955 break |
956 logging.info('PidsUsingDevicePort: %s', pids) | 956 logging.info('PidsUsingDevicePort: %s', pids) |
957 return pids | 957 return pids |
OLD | NEW |