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

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 547623002: Simpler logic to setup/restore Chrome command line (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nit (lined up params) Created 6 years, 3 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
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=W0613 9 # pylint: disable=W0613
10 10
11 import pipes
11 import sys 12 import sys
12 import time 13 import time
13 14
14 import pylib.android_commands 15 import pylib.android_commands
15 from pylib.device import adb_wrapper 16 from pylib.device import adb_wrapper
16 from pylib.device import decorators 17 from pylib.device import decorators
17 from pylib.device import device_errors 18 from pylib.device import device_errors
18 from pylib.utils import apk_helper 19 from pylib.utils import apk_helper
19 from pylib.utils import parallelizer 20 from pylib.utils import parallelizer
20 21
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 """ 629 """
629 if as_root: 630 if as_root:
630 if not self.old_interface.CanAccessProtectedFileContents(): 631 if not self.old_interface.CanAccessProtectedFileContents():
631 raise device_errors.CommandFailedError( 632 raise device_errors.CommandFailedError(
632 'Cannot write to %s with root privileges.' % device_path) 633 'Cannot write to %s with root privileges.' % device_path)
633 self.old_interface.SetProtectedFileContents(device_path, contents) 634 self.old_interface.SetProtectedFileContents(device_path, contents)
634 else: 635 else:
635 self.old_interface.SetFileContents(device_path, contents) 636 self.old_interface.SetFileContents(device_path, contents)
636 637
637 @decorators.WithTimeoutAndRetriesFromInstance() 638 @decorators.WithTimeoutAndRetriesFromInstance()
639 def WriteTextFile(self, device_path, text, as_root=False, timeout=None,
640 retries=None):
641 """Writes |text| to a file on the device.
642
643 Assuming that |text| is a small string, this is typically more efficient
644 than |WriteFile|, as no files are pushed into the device.
645
646 Args:
647 device_path: A string containing the absolute path to the file to write
648 on the device.
649 text: A short string of text to write to the file on the device.
650 as_root: A boolean indicating whether the write should be executed with
651 root privileges.
652 timeout: timeout in seconds
653 retries: number of retries
654
655 Raises:
656 CommandFailedError if the file could not be written on the device.
657 CommandTimeoutError on timeout.
658 DeviceUnreachableError on missing device.
659 """
660 self._RunShellCommandImpl('echo {1} > {0}'.format(device_path,
661 pipes.quote(text)), check_return=True, as_root=as_root)
662
663 @decorators.WithTimeoutAndRetriesFromInstance()
638 def Ls(self, device_path, timeout=None, retries=None): 664 def Ls(self, device_path, timeout=None, retries=None):
639 """Lists the contents of a directory on the device. 665 """Lists the contents of a directory on the device.
640 666
641 Args: 667 Args:
642 device_path: A string containing the path of the directory on the device 668 device_path: A string containing the path of the directory on the device
643 to list. 669 to list.
644 timeout: timeout in seconds 670 timeout: timeout in seconds
645 retries: number of retries 671 retries: number of retries
646 672
647 Returns: 673 Returns:
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 A Parallelizer operating over |devices|. 841 A Parallelizer operating over |devices|.
816 """ 842 """
817 if not devices or len(devices) == 0: 843 if not devices or len(devices) == 0:
818 devices = pylib.android_commands.GetAttachedDevices() 844 devices = pylib.android_commands.GetAttachedDevices()
819 parallelizer_type = (parallelizer.Parallelizer if async 845 parallelizer_type = (parallelizer.Parallelizer if async
820 else parallelizer.SyncParallelizer) 846 else parallelizer.SyncParallelizer)
821 return parallelizer_type([ 847 return parallelizer_type([
822 d if isinstance(d, DeviceUtils) else DeviceUtils(d) 848 d if isinstance(d, DeviceUtils) else DeviceUtils(d)
823 for d in devices]) 849 for d in devices])
824 850
OLDNEW
« no previous file with comments | « build/android/pylib/android_commands.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698