Exemplo n.º 1
0
 def __connect(self):
     """
     connect to device or exit
     @raise: EnvironmentError
     """
     if DEBUG:
         printLog(self.threadName + '[iDevice] Connecting to device %s...' % self.deviceId, logging.INFO)
     try:
         self.adbc, serialno = ViewClient.connectToDeviceOrExit(verbose=DEBUG, serialno=self.deviceId)
         # print 'Connected.'
         if self.adbc is None:
             printLog(self.threadName + '[iDevice] Failed to connect to Device %s...' % self.deviceId, logging.ERROR)
             return
         # get phone's screen resolution, once connected, it is fixed
         self.scn_width = int(self.adbc.display['width'])
         self.scn_height = int(self.adbc.display['height'])
         # printLog(self.threadName + "[iDevice] Device %s's screen resolution is: %d * %d" % (
         #     self.deviceId, self.scn_width, self.scn_height), logging.DEBUG)
         self.adbc.wake()
         # printLog(self.threadName + '[iDevice] Creating View Client... ', logging.DEBUG)
         self.vc = ViewClient(self.adbc, serialno, autodump=False, forceviewserveruse=True)
         if DEBUG:
             printLog(self.threadName + '[iDevice] Device %s connected.' % self.deviceId, logging.INFO)
         # self.resultFlag = True
     except Exception, e:
         printLog(self.threadName + "[iDevice] CANNOT connect to device %s. Please check the USB cable and "
                                    "reconnect the device." % self.deviceId, logging.ERROR)
         # if DEBUG:
         #     traceback.print_exc()
         raise EnvironmentError(e.message)
Exemplo n.º 2
0
    def __init__(self):

        # device = TestDevicePool().getDevice()
        # if device is None:
        #     print("NO IDLE DEVICE AVAILABLE. TERMINATE.")
        #     assert False
        # # self.threadName='<'+self.device.model+'_'+self.device.deviceId+'> '
        # print("Got device %s." % device.deviceId)
        devices = Shell().getShellCmdOutput(r"adb devices")
        # deviceIdList = filter(lambda x: len(x) > 0, devices.split('\n'))  # .split('\t',1)[0]
        deviceIdList = []  # filter(lambda x: len(x) > 0, devices.split('\n'))  # .split('\t',1)[0]
        connected_RE = re.compile("^\S+\t*device$")
        for line in devices.split("\n"):
            # if deviceIdList[i].strip() == 'List of devices attached':
            #     print 'list start'
            #     deviceIdList = deviceIdList[i+1:]
            #     break
            if connected_RE.match(line):
                deviceIdList.append(line.split("\t", 1)[0])

        if len(deviceIdList) > 0:
            print ("List of devices:")
            for j in range(len(deviceIdList)):
                print ("%d: %s\n" % (j, deviceIdList[j]))
            try:
                # connect device
                self.adbc, self.serial_no = ViewClient.connectToDeviceOrExit(verbose=DEBUG, serialno=deviceIdList[0])
                print "device %s connected." % self.serial_no
                self.devices = self.adbc.getDevices()
                for device in self.devices:
                    print device.serialno
            except:
                traceback.print_exc()
                raise RuntimeError("cannot connect to device.")
        else:
            raise RuntimeError("cannot find device.")