コード例 #1
0
    def Oem(self, oem_command, err_to_out):
        """Run an OEM command.

    Args:
      oem_command: The OEM command to run.
      err_to_out: Whether to redirect stderr to stdout.
    Returns:
      The result message for the OEM command.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            out = self.fastboot_command('-s',
                                        self.serial_number,
                                        'oem',
                                        oem_command,
                                        _err_to_out=err_to_out)
            return out
        except sh.ErrorReturnCode as e:
            if err_to_out:
                err = e.stdout
            else:
                err = e.stderr
            raise fastboot_exceptions.FastbootFailure(err)
        finally:
            self._lock.release()
コード例 #2
0
    def Oem(self, oem_command, err_to_out):
        """"Run an OEM command.

    Args:
      oem_command: The OEM command to run.
      err_to_out: Whether to redirect stderr to stdout.
    Returns:
      The result message for the OEM command.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            # We need to redirect the output no matter err_to_out is set
            # So that FastbootFailure can catch the right error.
            return subprocess.check_output([
                FastbootDevice.fastboot_command, '-s', self.serial_number,
                'oem', oem_command
            ],
                                           stderr=subprocess.STDOUT,
                                           creationflags=CREATE_NO_WINDOW)
        except subprocess.CalledProcessError as e:
            raise fastboot_exceptions.FastbootFailure(e.output)
        finally:
            self._lock.release()
コード例 #3
0
    def GetVar(self, var):
        """Get a variable from the device.

    Note that the return value is in stderr instead of stdout.
    Args:
      var: The name of the variable.
    Returns:
      The value for the variable.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            # Fastboot getvar command's output would be in stderr instead of stdout.
            # Need to redirect stderr to stdout.
            out = self.fastboot_command('-s',
                                        self.serial_number,
                                        'getvar',
                                        var,
                                        _err_to_out=True)
        except sh.ErrorReturnCode as e:
            # Since we redirected stderr, we should print stdout here.
            raise fastboot_exceptions.FastbootFailure(e.stdout)
        finally:
            self._lock.release()
        if var == 'at-vboot-state':
            # For the result of vboot-state, it does not follow the standard.
            return out
        lines = out.split('\n')
        for line in lines:
            if line.startswith(var + ': '):
                value = line.replace(var + ': ', '')
        return value
コード例 #4
0
    def ListDevices():
        """List all fastboot devices.

    Returns:
      A list of serial numbers for all the fastboot devices.
    """
        try:
            out = FastbootDevice.fastboot_command('devices')
            device_serial_numbers = out.replace('\tfastboot',
                                                '').rstrip().split('\n')
            # filter out empty string
            return filter(None, device_serial_numbers)
        except sh.ErrorReturnCode as e:
            raise fastboot_exceptions.FastbootFailure(e.stderr)
コード例 #5
0
    def Reboot(self):
        """Reboot the device into fastboot mode.

    Returns:
      The command output.
    """
        try:
            self._lock.acquire()
            out = self.fastboot_command('-s', self.serial_number,
                                        'reboot-bootloader')
            return out
        except sh.ErrorReturnCode as e:
            raise fastboot_exceptions.FastbootFailure(e.stderr)
        finally:
            self._lock.release()
コード例 #6
0
    def ListDevices():
        """List all fastboot devices.

    Returns:
      A list of serial numbers for all the fastboot devices.
    """
        try:
            out = subprocess.check_output(
                [FastbootDevice.fastboot_command, 'devices'],
                creationflags=CREATE_NO_WINDOW)
            device_serial_numbers = (out.replace('\tfastboot',
                                                 '').rstrip().splitlines())
            # filter out empty string
            return filter(None, device_serial_numbers)
        except subprocess.CalledProcessError as e:
            raise fastboot_exceptions.FastbootFailure(e.output)
コード例 #7
0
    def Reboot(self):
        """Reboot the device into fastboot mode.

    Returns:
      The command output.
    """
        try:
            self._lock.acquire()
            out = subprocess.check_output([
                FastbootDevice.fastboot_command, '-s', self.serial_number,
                'reboot-bootloader'
            ],
                                          creationflags=CREATE_NO_WINDOW)
            return out
        except subprocess.CalledProcessError as e:
            raise fastboot_exceptions.FastbootFailure(e.output)
        finally:
            self._lock.release()
コード例 #8
0
    def Download(self, file_path):
        """Push a file from the file system to the fastboot device.

    Args:
      file_path: The file path of the file on the local file system
        that would be pushed to fastboot device.
    Returns:
      The output for the fastboot command required.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            out = self.fastboot_command('-s', self.serial_number, 'stage',
                                        file_path)
            return out
        except sh.ErrorReturnCode as e:
            raise fastboot_exceptions.FastbootFailure(e.stderr)
        finally:
            self._lock.release()
コード例 #9
0
    def Flash(self, partition, file_path):
        """Flash a file to a partition.

    Args:
      file_path: The partition file to be flashed.
      partition: The partition to be flashed.
    Returns:
      The output for the fastboot command required.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            out = self.fastboot_command('-s', self.serial_number, 'flash',
                                        partition, file_path)
            return out
        except sh.ErrorReturnCode as e:
            raise fastboot_exceptions.FastbootFailure(e.stderr)
        finally:
            self._lock.release()
コード例 #10
0
    def Download(self, file_path):
        """Push a file from the file system to the fastboot device.

    Args:
      file_path: The file path of the file on the local file system
        that would be pushed to fastboot device.
    Returns:
      The output for the fastboot command required.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            return subprocess.check_output([
                FastbootDevice.fastboot_command, '-s', self.serial_number,
                'stage', file_path
            ],
                                           creationflags=CREATE_NO_WINDOW)
        except subprocess.CalledProcessError as e:
            raise fastboot_exceptions.FastbootFailure(e.output)
        finally:
            self._lock.release()
コード例 #11
0
    def Flash(self, partition, file_path):
        """Flash a file to a partition.

    Args:
      file_path: The partition file to be flashed.
      partition: The partition to be flashed.
    Returns:
      The output for the fastboot command required.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            self._lock.acquire()
            return subprocess.check_output([
                FastbootDevice.fastboot_command, '-s', self.serial_number,
                'flash', partition, file_path
            ],
                                           creationflags=CREATE_NO_WINDOW)
        except subprocess.CalledProcessError as e:
            raise fastboot_exceptions.FastbootFailure(e.output)
        finally:
            self._lock.release()
コード例 #12
0
    def GetVar(self, var):
        """Get a variable from the device.

    Note that the return value is in stderr instead of stdout.
    Args:
      var: The name of the variable.
    Returns:
      The value for the variable.
    Raises:
      FastbootFailure: If failure happens during the command.
    """
        try:
            # Fastboot getvar command's output would be in stderr instead of stdout.
            # Need to redirect stderr to stdout.
            self._lock.acquire()

            # Need the shell=True flag for windows, otherwise it hangs.
            out = subprocess.check_output([
                FastbootDevice.fastboot_command, '-s', self.serial_number,
                'getvar', var
            ],
                                          stderr=subprocess.STDOUT,
                                          shell=True,
                                          creationflags=CREATE_NO_WINDOW)
        except subprocess.CalledProcessError as e:
            # Since we redirected stderr, we should print stdout here.
            raise fastboot_exceptions.FastbootFailure(e.output)
        finally:
            self._lock.release()
        if var == 'at-vboot-state':
            # For the result of vboot-state, it does not follow the standard.
            return out
        lines = out.splitlines()
        for line in lines:
            if line.startswith(var + ': '):
                value = line.replace(var + ': ', '').replace('\r', '')
        return value