当前位置: 首页>>代码示例>>Python>>正文


Python DeviceManagerADB.devices方法代码示例

本文整理汇总了Python中mozdevice.DeviceManagerADB.devices方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceManagerADB.devices方法的具体用法?Python DeviceManagerADB.devices怎么用?Python DeviceManagerADB.devices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mozdevice.DeviceManagerADB的用法示例。


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

示例1: AndroidEmulator

# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import devices [as 别名]

#.........这里部分代码省略.........
        command = [self.emulator_path, "-avd",
                   self.avd_info.name, "-port", "5554"]
        if self.gpu:
            command += ['-gpu', 'swiftshader']
        if self.avd_info.extra_args:
            # -enable-kvm option is not valid on OSX
            if _get_host_platform() == 'macosx64' and '-enable-kvm' in self.avd_info.extra_args:
                self.avd_info.extra_args.remove('-enable-kvm')
            command += self.avd_info.extra_args
        log_path = os.path.join(EMULATOR_HOME_DIR, 'emulator.log')
        self.emulator_log = open(log_path, 'w')
        _log_debug("Starting the emulator with this command: %s" %
                   ' '.join(command))
        _log_debug("Emulator output will be written to '%s'" %
                   log_path)
        self.proc = ProcessHandler(
            command, storeOutput=False, processOutputLine=outputHandler,
            env=env)
        self.proc.run()
        _log_debug("Emulator started with pid %d" %
                   int(self.proc.proc.pid))

    def wait_for_start(self):
        """
           Verify that the emulator is running, the emulator device is visible
           to adb, and Android has booted.
        """
        if not self.proc:
            _log_warning("Emulator not started!")
            return False
        if self.check_completed():
            return False
        _log_debug("Waiting for device status...")
        while(('emulator-5554', 'device') not in self.dm.devices()):
            time.sleep(10)
            if self.check_completed():
                return False
        _log_debug("Device status verified.")

        _log_debug("Checking that Android has booted...")
        complete = False
        while(not complete):
            output = ''
            try:
                output = self.dm.shellCheckOutput(
                    ['getprop', 'sys.boot_completed'], timeout=5)
            except DMError:
                # adb not yet responding...keep trying
                pass
            if output.strip() == '1':
                complete = True
            else:
                time.sleep(10)
                if self.check_completed():
                    return False
        _log_debug("Android boot status verified.")

        if not self._verify_emulator():
            return False
        if self.avd_info.x86:
            _log_info("Running the x86 emulator; be sure to install an x86 APK!")
        else:
            _log_info("Running the arm emulator; be sure to install an arm APK!")
        return True

    def check_completed(self):
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:70,代码来源:android_device.py

示例2: AndroidEmulator

# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import devices [as 别名]

#.........这里部分代码省略.........
        def outputHandler(line):
            self.emulator_log.write("<%s>\n" % line)
        env = os.environ
        env['ANDROID_AVD_HOME'] = os.path.join(EMULATOR_HOME_DIR, "avd")
        command = [self.emulator_path, "-avd",
                   self.avd_info.name, "-port", "5554"]
        if self.avd_info.extra_args:
            command += self.avd_info.extra_args
        log_path = os.path.join(EMULATOR_HOME_DIR, 'emulator.log')
        self.emulator_log = open(log_path, 'w')
        _log_debug("Starting the emulator with this command: %s" %
                        ' '.join(command))
        _log_debug("Emulator output will be written to '%s'" %
                        log_path)
        self.proc = ProcessHandler(
            command, storeOutput=False, processOutputLine=outputHandler,
            env=env)
        self.proc.run()
        _log_debug("Emulator started with pid %d" %
                        int(self.proc.proc.pid))

    def wait_for_start(self):
        """
           Verify that the emulator is running, the emulator device is visible
           to adb, and Android has booted.
        """
        if not self.proc:
            _log_warning("Emulator not started!")
            return False
        if self.proc.proc.poll() is not None:
            _log_warning("Emulator has already completed!")
            return False
        _log_debug("Waiting for device status...")
        while(('emulator-5554', 'device') not in self.dm.devices()):
            time.sleep(10)
            if self.proc.proc.poll() is not None:
                _log_warning("Emulator has already completed!")
                return False
        _log_debug("Device status verified.")

        _log_debug("Checking that Android has booted...")
        complete = False
        while(not complete):
            output = ''
            try:
                output = self.dm.shellCheckOutput(
                    ['getprop', 'sys.boot_completed'], timeout=5)
            except DMError:
                # adb not yet responding...keep trying
                pass
            if output.strip() == '1':
                complete = True
            else:
                time.sleep(10)
                if self.proc.proc.poll() is not None:
                    _log_warning("Emulator has already completed!")
                    return False
        _log_debug("Android boot status verified.")

        if not self._verify_emulator():
            return False
        if self.avd_info.uses_sut:
            if not self._verify_sut():
                return False
        return True
开发者ID:DINKIN,项目名称:Waterfox,代码行数:69,代码来源:android_device.py

示例3: test_remount

# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import devices [as 别名]
    def test_remount(self):
        self.assertEquals(self.dm.remount(), 0)

    def test_list_devices(self):
        self.assertEquals(len(list(self.dm.devices())), 1)

    def test_shell(self):
        out = StringIO()
        self.dm.shell(["echo", "$COMPANY", ";", "pwd"], out,
                env={"COMPANY":"Mozilla"}, cwd="/", timeout=4, root=True)
        output = str(out.getvalue()).rstrip().splitlines()
        out.close()
        self.assertEquals(output, ['Mozilla', '/'])

    def test_reboot(self):
        # We are not running the reboot function because it takes too long
        #self.dm.reboot(wait=True)
        pass

    def test_port_forwarding(self):
        # I don't really know how to test this properly
        self.assertEquals(self.dm.forward("tcp:2828", "tcp:2828"), 0)

if __name__ == '__main__':
    dm = DeviceManagerADB()
    if not dm.devices():
       print "There are no connected adb devices"
       sys.exit(1)

    unittest.main()
开发者ID:qiuyang001,项目名称:Spidermonkey,代码行数:32,代码来源:test_devicemanagerADB.py

示例4: AndroidEmulator

# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import devices [as 别名]

#.........这里部分代码省略.........
    def start(self):
        """
           Launch the emulator.
        """

        def outputHandler(line):
            self.emulator_log.write("<%s>\n" % line)

        env = os.environ
        env["ANDROID_AVD_HOME"] = os.path.join(EMULATOR_HOME_DIR, "avd")
        command = [self.emulator_path, "-avd", self.avd_info.name, "-port", "5554"]
        if self.avd_info.extra_args:
            command += self.avd_info.extra_args
        log_path = os.path.join(EMULATOR_HOME_DIR, "emulator.log")
        self.emulator_log = open(log_path, "w")
        self._log_debug("Starting the emulator with this command: %s" % " ".join(command))
        self._log_debug("Emulator output will be written to '%s'" % log_path)
        self.proc = ProcessHandler(command, storeOutput=False, processOutputLine=outputHandler, env=env)
        self.proc.run()
        self._log_debug("Emulator started with pid %d" % int(self.proc.proc.pid))

    def wait_for_start(self):
        """
           Verify that the emulator is running, the emulator device is visible
           to adb, and Android has booted.
        """
        if not self.proc:
            self._log_warning("Emulator not started!")
            return False
        if self.proc.proc.poll() is not None:
            self._log_warning("Emulator has already completed!")
            return False
        self._log_debug("Waiting for device status...")
        while ("emulator-5554", "device") not in self.dm.devices():
            time.sleep(10)
            if self.proc.proc.poll() is not None:
                self._log_warning("Emulator has already completed!")
                return False
        self._log_debug("Device status verified.")

        self._log_debug("Checking that Android has booted...")
        complete = False
        while not complete:
            output = ""
            try:
                output = self.dm.shellCheckOutput(["getprop", "sys.boot_completed"], timeout=5)
            except DMError:
                # adb not yet responding...keep trying
                pass
            if output.strip() == "1":
                complete = True
            else:
                time.sleep(10)
                if self.proc.proc.poll() is not None:
                    self._log_warning("Emulator has already completed!")
                    return False
        self._log_debug("Android boot status verified.")

        if not self._verify_emulator():
            return False
        if self.avd_info.uses_sut:
            if not self._verify_sut():
                return False
        return True

    def wait(self):
开发者ID:Jinwoo-Song,项目名称:gecko-dev,代码行数:70,代码来源:android_device.py

示例5: configure_devices

# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import devices [as 别名]
 def configure_devices(self):
     """
        Ensure devices.ini is set up.
     """
     keep_going = True
     device_ini = os.path.join(self.config['base-dir'], 'devices.ini')
     if os.path.exists(device_ini):
         response = raw_input(
             "Use existing device configuration at %s? (Y/n) " % device_ini).strip()
         if not 'n' in response.lower():
             self.build_obj.log(logging.INFO, "autophone", {},
                 "Using device configuration at %s" % device_ini)
             return keep_going
     keep_going = False
     self.build_obj.log(logging.INFO, "autophone", {},
         "You must configure at least one Android device before running autophone.")
     response = raw_input(
         "Configure devices now? (Y/n) ").strip()
     if response.lower().startswith('y') or response == '':
         response = raw_input(
             "Connect your rooted Android test device(s) with usb and press Enter ")
         adb_path = 'adb'
         try:
             if os.path.exists(self.build_obj.substs["ADB"]):
                 adb_path = self.build_obj.substs["ADB"]
         except:
             if self.verbose:
                 self.build_obj.log(logging.ERROR, "autophone", {},
                     str(sys.exc_info()[0]))
             # No build environment?
             try:
                 adb_path = which.which('adb')
             except which.WhichError:
                 adb_path = raw_input(
                     "adb not found. Enter path to adb: ").strip()
         if self.verbose:
             print("Using adb at %s" % adb_path)
         dm = DeviceManagerADB(autoconnect=False, adbPath=adb_path, retryLimit=1)
         device_index = 1
         try:
             with open(os.path.join(self.config['base-dir'], 'devices.ini'), 'w') as f:
                 for device in dm.devices():
                     serial = device[0]
                     if self.verify_device(adb_path, serial):
                         f.write("[device-%d]\nserialno=%s\n" % (device_index, serial))
                         device_index += 1
                         self.build_obj.log(logging.INFO, "autophone", {},
                             "Added '%s' to device configuration." % serial)
                         keep_going = True
                     else:
                         self.build_obj.log(logging.WARNING, "autophone", {},
                             "Device '%s' is not rooted - skipping" % serial)
         except:
             self.build_obj.log(logging.ERROR, "autophone", {},
                 "Failed to get list of connected Android devices.")
             if self.verbose:
                 self.build_obj.log(logging.ERROR, "autophone", {},
                     str(sys.exc_info()[0]))
             keep_going = False
         if device_index <= 1:
             self.build_obj.log(logging.ERROR, "autophone", {},
                 "No devices configured! (Can you see your rooted test device(s) in 'adb devices'?")
             keep_going = False
         if keep_going:
             self.config['devices-configured'] = True
     return keep_going
开发者ID:MekliCZ,项目名称:positron,代码行数:68,代码来源:autophone.py


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