• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python android.adb_shell函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wlauto.utils.android.adb_shell函数的典型用法代码示例。如果您正苦于以下问题:Python adb_shell函数的具体用法?Python adb_shell怎么用?Python adb_shell使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了adb_shell函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: connect

    def connect(self):  # NOQA pylint: disable=R0912
        iteration_number = 0
        max_iterations = self.ready_timeout / self.delay
        available = False
        self.logger.debug("Polling for device {}...".format(self.adb_name))
        while iteration_number < max_iterations:
            devices = adb_list_devices()
            if self.adb_name:
                for device in devices:
                    if device.name == self.adb_name and device.status != "offline":
                        available = True
            else:  # adb_name not set
                if len(devices) == 1:
                    available = True
                elif len(devices) > 1:
                    raise DeviceError("More than one device is connected and adb_name is not set.")

            if available:
                break
            else:
                time.sleep(self.delay)
                iteration_number += 1
        else:
            raise DeviceError("Could not boot {} ({}).".format(self.name, self.adb_name))

        while iteration_number < max_iterations:
            available = (
                int("0" + (adb_shell(self.adb_name, "getprop sys.boot_completed", timeout=self.default_timeout))) == 1
            )
            if available:
                break
            else:
                time.sleep(self.delay)
                iteration_number += 1
        else:
            raise DeviceError("Could not boot {} ({}).".format(self.name, self.adb_name))

        if self._just_rebooted:
            self.logger.debug("Waiting for boot to complete...")
            # On some devices, adb connection gets reset some time after booting.
            # This  causes errors during execution. To prevent this, open a shell
            # session and wait for it to be killed. Once its killed, give adb
            # enough time to restart, and then the device should be ready.
            # TODO: This is more of a work-around rather than an actual solution.
            #       Need to figure out what is going on the "proper" way of handling it.
            try:
                adb_shell(self.adb_name, "", timeout=20)
                time.sleep(5)  # give adb time to re-initialize
            except TimeoutError:
                pass  # timed out waiting for the session to be killed -- assume not going to be.

            self.logger.debug("Boot completed.")
            self._just_rebooted = False
        self._is_ready = True
开发者ID:chase-qi,项目名称:workload-automation,代码行数:54,代码来源:device.py


示例2: file_exists

 def file_exists(self, filepath):
     self._check_ready()
     output = adb_shell(self.adb_name, 'if [ -e \'{}\' ]; then echo 1; else echo 0; fi'.format(filepath),
                        timeout=self.default_timeout)
     if int(output):
         return True
     else:
         return False
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:8,代码来源:device.py


示例3: execute

    def execute(
        self,
        command,
        timeout=default_timeout,
        check_exit_code=True,
        background=False,
        as_root=False,
        busybox=False,
        **kwargs
    ):
        """
        Execute the specified command on the device using adb.

        Parameters:

            :param command: The command to be executed. It should appear exactly
                            as if you were typing it into a shell.
            :param timeout: Time, in seconds, to wait for adb to return before aborting
                            and raising an error. Defaults to ``AndroidDevice.default_timeout``.
            :param check_exit_code: If ``True``, the return code of the command on the Device will
                                    be check and exception will be raised if it is not 0.
                                    Defaults to ``True``.
            :param background: If ``True``, will execute adb in a subprocess, and will return
                               immediately, not waiting for adb to return. Defaults to ``False``
            :param busybox: If ``True``, will use busybox to execute the command. Defaults to ``False``.

                            Added in version 2.1.3

                            .. note:: The device must be rooted to be able to use busybox.

            :param as_root: If ``True``, will attempt to execute command in privileged mode. The device
                            must be rooted, otherwise an error will be raised. Defaults to ``False``.

                            Added in version 2.1.3

        :returns: If ``background`` parameter is set to ``True``, the subprocess object will
                  be returned; otherwise, the contents of STDOUT from the device will be returned.

        :raises: DeviceError if adb timed out  or if the command returned non-zero exit
                 code on the device, or if attempting to execute a command in privileged mode on an
                 unrooted device.

        """
        self._check_ready()
        if as_root and not self.is_rooted:
            raise DeviceError('Attempting to execute "{}" as root on unrooted device.'.format(command))
        if busybox:
            if not self.is_rooted:
                DeviceError(
                    'Attempting to execute "{}" with busybox. '.format(command)
                    + "Busybox can only be deployed to rooted devices."
                )
            command = " ".join([self.busybox, command])
        if background:
            return adb_background_shell(self.adb_name, command, as_root=as_root)
        else:
            return adb_shell(self.adb_name, command, timeout, check_exit_code, as_root)
开发者ID:bjackman,项目名称:workload-automation,代码行数:57,代码来源:device.py


示例4: connect

    def connect(self):  # NOQA pylint: disable=R0912
        super(Note3Device, self).connect()
        if self._just_rebooted:
            self.logger.debug('Waiting for boot to complete...')
            # On the Note 3, adb connection gets reset some time after booting.
            # This  causes errors during execution. To prevent this, open a shell
            # session and wait for it to be killed. Once its killed, give adb
            # enough time to restart, and then the device should be ready.
            try:
                adb_shell(self.adb_name, '', timeout=20)  # pylint: disable=no-member
                time.sleep(5)  # give adb time to re-initialize
            except TimeoutError:
                pass  # timed out waiting for the session to be killed -- assume not going to be.

            self.logger.debug('Boot completed.')
            self._just_rebooted = False
        # Swipe upwards to unlock the screen.
        time.sleep(self.long_delay)
        self.execute('input touchscreen swipe 540 1600 560 800 ')
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:19,代码来源:__init__.py


示例5: disable_selinux

 def disable_selinux(self):
     # This may be invoked from intialize() so we can't use execute() or the
     # standard API for doing this.
     api_level = int(adb_shell(self.adb_name, "getprop ro.build.version.sdk", timeout=self.default_timeout).strip())
     # SELinux was added in Android 4.3 (API level 18). Trying to
     # 'getenforce' in earlier versions will produce an error.
     if api_level >= 18:
         se_status = self.execute("getenforce", as_root=True).strip()
         if se_status == "Enforcing":
             self.execute("setenforce 0", as_root=True)
开发者ID:chase-qi,项目名称:workload-automation,代码行数:10,代码来源:device.py


示例6: is_network_connected

    def is_network_connected(self):
        network_host = 'www.google.com'
        self.logger.debug('Checking for internet connectivity.')
        output = adb_shell(self.adb_name, 'ping -q -w 1 -c 1 {}'.format(network_host),
                           timeout=self.default_timeout)

        if not 'unknown host' in output:
            self.logger.debug('Found network host {}'.format(network_host))
            return True
        else:
            self.logger.debug('Cannot find network host {}'.format(network_host))
            return False
开发者ID:muendelezaji,项目名称:workload-automation,代码行数:12,代码来源:device.py


示例7: is_rooted

 def is_rooted(self):
     if self._is_rooted is None:
         try:
             result = adb_shell(self.adb_name, 'su', timeout=1)
             if 'not found' in result:
                 self._is_rooted = False
             else:
                 self._is_rooted = True
         except TimeoutError:
             self._is_rooted = True
         except DeviceError:
             self._is_rooted = False
     return self._is_rooted
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:13,代码来源:device.py


示例8: clear_buffer

 def clear_buffer(self):
     self.logger.debug('Clearing logcat buffer.')
     with self.lock:
         adb_shell(self.adb_device, 'logcat -c', timeout=self.timeout)
         with open(self.buffer_file, 'w') as _:  # NOQA
             pass
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:6,代码来源:device.py


示例9: clear_logcat

 def clear_logcat(self):
     """Clear (flush) logcat log."""
     if self._logcat_poller:
         return self._logcat_poller.clear_buffer()
     else:
         return adb_shell(self.adb_name, 'logcat -c', timeout=self.default_timeout)
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:6,代码来源:device.py


示例10: delete_file

 def delete_file(self, filepath, as_root=False):  # pylint: disable=W0221
     self._check_ready()
     adb_shell(self.adb_name, "rm '{}'".format(filepath), as_root=as_root, timeout=self.default_timeout)
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:3,代码来源:device.py


示例11: ping

 def ping(self):
     try:
         # May be triggered inside initialize()
         adb_shell(self.adb_name, 'ls /', timeout=10)
     except (TimeoutError, CalledProcessError):
         raise DeviceNotRespondingError(self.adb_name or self.name)
开发者ID:JaviMerino,项目名称:workload-automation,代码行数:6,代码来源:device.py


示例12: file_exists

 def file_exists(self, filepath):
     self._check_ready()
     output = adb_shell(
         self.adb_name, "if [ -e '{}' ]; then echo 1; else echo 0; fi".format(filepath), timeout=self.default_timeout
     )
     return bool(int(output))
开发者ID:chase-qi,项目名称:workload-automation,代码行数:6,代码来源:device.py



注:本文中的wlauto.utils.android.adb_shell函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python misc.check_output函数代码示例发布时间:2022-05-26
下一篇:
Python android.adb_command函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap