Пример #1
0
    def parse_args(self, args=None, namespace=None):
        result = super(ArgumentParser, self).parse_args(args, namespace)

        adb_path = result.adb_path or "adb"

        # Try to run the specified adb command
        try:
            subprocess.check_output([adb_path, "version"],
                                    stderr=subprocess.STDOUT)
        except (OSError, subprocess.CalledProcessError):
            msg = "ERROR: Unable to run adb executable (tried '{}')."
            if not result.adb_path:
                msg += "\n       Try specifying its location with --adb."
            sys.exit(msg.format(adb_path))

        try:
            if result.device == "-a":
                result.device = adb.get_device(adb_path=adb_path)
            elif result.device == "-d":
                result.device = adb.get_usb_device(adb_path=adb_path)
            elif result.device == "-e":
                result.device = adb.get_emulator_device(adb_path=adb_path)
            else:
                result.device = adb.get_device(result.serial, adb_path=adb_path)
        except (adb.DeviceNotFoundError, adb.NoUniqueDeviceError, RuntimeError):
            # Don't error out if we can't find a device.
            result.device = None

        return result
Пример #2
0
    def parse_args(self, args=None, namespace=None):
        result = super(ArgumentParser, self).parse_args(args, namespace)

        adb_path = result.adb_path or "adb"

        # Try to run the specified adb command
        try:
            subprocess.check_output([adb_path, "version"],
                                    stderr=subprocess.STDOUT)
        except (OSError, subprocess.CalledProcessError):
            msg = "ERROR: Unable to run adb executable (tried '{}')."
            if not result.adb_path:
                msg += "\n       Try specifying its location with --adb."
            sys.exit(msg.format(adb_path))

        try:
            if result.device == "-a":
                result.device = adb.get_device(adb_path=adb_path)
            elif result.device == "-d":
                result.device = adb.get_usb_device(adb_path=adb_path)
            elif result.device == "-e":
                result.device = adb.get_emulator_device(adb_path=adb_path)
            else:
                result.device = adb.get_device(result.serial, adb_path=adb_path)
        except (adb.DeviceNotFoundError, adb.NoUniqueDeviceError, RuntimeError):
            # Don't error out if we can't find a device.
            result.device = None

        return result
Пример #3
0
 def __call__(self, parser, namespace, values, option_string=None):
     if option_string is None:
         raise RuntimeError("DeviceAction called without option_string")
     elif option_string == "-a":
         # Handled in parse_args
         return
     elif option_string == "-d":
         namespace.device = adb.get_usb_device()
     elif option_string == "-e":
         namespace.device = adb.get_emulator_device()
     elif option_string == "-s":
         namespace.device = adb.get_device(values[0])
     else:
         raise RuntimeError("Unexpected flag {}".format(option_string))
Пример #4
0
 def __call__(self, parser, namespace, values, option_string=None):
     if option_string is None:
         raise RuntimeError("DeviceAction called without option_string")
     elif option_string == "-a":
         # Handled in parse_args
         return
     elif option_string == "-d":
         namespace.device = adb.get_usb_device()
     elif option_string == "-e":
         namespace.device = adb.get_emulator_device()
     elif option_string == "-s":
         namespace.device = adb.get_device(values[0])
     else:
         raise RuntimeError("Unexpected flag {}".format(option_string))