Beispiel #1
0
    def install_device_executable(self, bin_path, destination, timeout=0):
        """
        Install a binary as device executable file

        :type bin_path: str
        :param bin_path: file to be installed

        :type  destination: str
        :param destination: destination on device

        :type  timeout: int
        :param timeout: operation timeout

        :rtype: tuple (bool, str)
        :return: Output status and output log
        """
        status = Util.Global.FAILURE
        status_msg = "Undefined error while pushing binary on device"
        binary_filename = os.path.basename(bin_path)

        if os.path.isfile(bin_path):
            if destination is not None:
                # Initialize timeout if not set
                if not timeout:
                    timeout = Util.compute_timeout_from_file_size(
                        bin_path, self._device.min_file_install_timeout)

                # Build chmod commands
                dest_path = posixpath.join(destination, binary_filename)
                bin_chmod_cmd = "chmod +x {0}".format(dest_path)
                # Push the binary file
                self._logger.info("Pushing %s -> %s ..." %
                                  (str(bin_path), str(dest_path)))
                # status, status_msg = self._run_cmd_and_check_failure(bin_push_cmd, timeout)
                status, status_msg = self._device.push(bin_path, destination,
                                                       timeout)

                if status == Util.Global.SUCCESS:
                    # Modify access right on the binary file
                    status, status_msg = self._run_cmd_and_check_failure(
                        bin_chmod_cmd, timeout)
                    if status == Util.Global.SUCCESS:
                        status_msg = "Binary has been successfully installed on the device!"
            else:
                status_msg = "Impossible to push %s, no destination given" % (
                    str(bin_path), )
        else:
            status_msg = "Impossible to install, no file given"

        return status, status_msg
Beispiel #2
0
    def install_device_app(self, app_path, timeout=0, allow_downgrade=False):
        """
        Install a device application

        :type app_path: str
        :param app_path: file to be installed

        :type  timeout: int
        :param timeout: operation timeout

        :type  allow_downgrade: bool
        :param allow_downgrade: allow the downgrade of application

        :rtype: tuple (bool, str)
        :return: Output status and output log
        """
        status = Util.Global.FAILURE
        status_msg = "Undefined error while installing application on device"
        cmd_options = "-r"
        if allow_downgrade:
            cmd_options += " -d"

        if os.path.isfile(app_path):
            # Define the timeout from the file size
            if not timeout:
                timeout = Util.compute_timeout_from_file_size(
                    app_path, self._device.min_file_install_timeout)

            self._logger.info("Installing {0} ...".format(app_path))
            cmd = 'adb install {0} "{1}"'.format(cmd_options, app_path)
            status, status_msg = self._run_cmd_and_check_failure(cmd, timeout)
        else:
            status_msg = "Impossible to install {0}, file does not exist".format(
                app_path)

        return status, status_msg