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

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

Issue 371813005: [Android] Switch to DeviceUtils versions of Ls, SetJavaAsserts, GetProp, and SetProp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 CommandFailedError if the file could not be written on the device. 539 CommandFailedError if the file could not be written on the device.
540 """ 540 """
541 if as_root: 541 if as_root:
542 if not self.old_interface.CanAccessProtectedFileContents(): 542 if not self.old_interface.CanAccessProtectedFileContents():
543 raise device_errors.CommandFailedError( 543 raise device_errors.CommandFailedError(
544 'Cannot write to %s with root priveleges.' % device_path) 544 'Cannot write to %s with root priveleges.' % device_path)
545 self.old_interface.SetProtectedFileContents(device_path, contents) 545 self.old_interface.SetProtectedFileContents(device_path, contents)
546 else: 546 else:
547 self.old_interface.SetFileContents(device_path, contents) 547 self.old_interface.SetFileContents(device_path, contents)
548 548
549 @decorators.WithTimeoutAndRetriesFromInstance()
550 def Ls(self, device_path, as_root=False, timeout=None, retries=None):
551 """Lists the contents of a directory on the device.
552
553 Args:
554 device_path: A string containing the path of the directory on the device
555 to list.
556 as_root: A boolean inidcating whether the ls should be executed with root
557 priveleges.
558 timeout: Same as for |IsOnline|.
559 retries: Same as for |IsOnline|.
560 Returns:
561 The contents of the directory specified by |device_path|.
562 """
563 return self.old_interface.ListPathContents(device_path)
564
565 @decorators.WithTimeoutAndRetriesFromInstance()
566 def SetJavaAsserts(self, enabled, timeout=None, retries=None):
567 """Enables or disables Java asserts.
568
569 Args:
570 enabled: A boolean indicating whether Java asserts should be enabled
571 or disabled.
572 timeout: Same as for |IsOnline|.
573 retries: Same as for |IsOnline|.
574 """
575 self.old_interface.SetJavaAssertsEnabled(enabled)
576
577 @decorators.WithTimeoutAndRetriesFromInstance()
578 def GetProp(self, property_name, timeout=None, retries=None):
579 """Gets a property from the device.
580
581 Args:
582 property_name: A string containing the name of the property to get from
583 the device.
584 timeout: Same as for |IsOnline|.
585 retries: Same as for |IsOnline|.
586 Returns:
587 The value of the device's |property_name| property.
588 """
589 return self.old_interface.system_properties[property_name]
tonyg 2014/07/07 15:22:56 Really up to you, but I thought it'd be more pytho
jbudorick 2014/07/07 16:12:45 I think I prefer GetProp / SetProp over the dict i
frankf 2014/07/07 17:29:03 I agree with John, explicit setter/getter in this
590
591 @decorators.WithTimeoutAndRetriesFromInstance()
592 def SetProp(self, property_name, value, timeout=None, retries=None):
593 """Sets a property on the device.
594
595 Args:
596 property_name: A string containing the name of the property to set on
597 the device.
598 value: A string containing the value to set to the property on the
599 device.
600 timeout: Same as for |IsOnline|.
601 retries: Same as for |IsOnline|.
602 """
603 self.old_interface.system_properties[property_name] = value
604
549 def __str__(self): 605 def __str__(self):
550 """Returns the device serial.""" 606 """Returns the device serial."""
551 return self.old_interface.GetDevice() 607 return self.old_interface.GetDevice()
552 608
553 @staticmethod 609 @staticmethod
554 def parallel(devices=None, async=False): 610 def parallel(devices=None, async=False):
555 """Creates a Parallelizer to operate over the provided list of devices. 611 """Creates a Parallelizer to operate over the provided list of devices.
556 612
557 If |devices| is either |None| or an empty list, the Parallelizer will 613 If |devices| is either |None| or an empty list, the Parallelizer will
558 operate over all attached devices. 614 operate over all attached devices.
559 615
560 Args: 616 Args:
561 devices: A list of either DeviceUtils instances or objects from 617 devices: A list of either DeviceUtils instances or objects from
562 from which DeviceUtils instances can be constructed. If None, 618 from which DeviceUtils instances can be constructed. If None,
563 all attached devices will be used. 619 all attached devices will be used.
564 async: If true, returns a Parallelizer that runs operations 620 async: If true, returns a Parallelizer that runs operations
565 asynchronously. 621 asynchronously.
566 Returns: 622 Returns:
567 A Parallelizer operating over |devices|. 623 A Parallelizer operating over |devices|.
568 """ 624 """
569 if not devices or len(devices) == 0: 625 if not devices or len(devices) == 0:
570 devices = pylib.android_commands.GetAttachedDevices() 626 devices = pylib.android_commands.GetAttachedDevices()
571 parallelizer_type = (parallelizer.Parallelizer if async 627 parallelizer_type = (parallelizer.Parallelizer if async
572 else parallelizer.SyncParallelizer) 628 else parallelizer.SyncParallelizer)
573 return parallelizer_type([ 629 return parallelizer_type([
574 d if isinstance(d, DeviceUtils) else DeviceUtils(d) 630 d if isinstance(d, DeviceUtils) else DeviceUtils(d)
575 for d in devices]) 631 for d in devices])
576 632
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698