Example #1
0
def DroidConnectByHWID(hwid, timeout=30, **kwargs):
  """Try to connect to the given device by waiting for it to show up using mDNS with the given timeout."""

  import re
  if re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+', hwid):
    print "Connected via SUT to %s" % (hwid)
    return DroidSUT(hwid, **kwargs)

  nt = NetworkTools()
  local_ip = nt.getLanIp()

  zc = Zeroconf(local_ip)

  evt = threading.Event()
  listener = ZeroconfListener(hwid, evt)
  sb = ServiceBrowser(zc, "_sutagent._tcp.local.", listener)
  foundIP = None
  if evt.wait(timeout):
    # we found the hwid 
    foundIP = listener.ip
    sb.cancel()
    zc.close()

  if foundIP is not None:
    return DroidSUT(foundIP, **kwargs)
    print "Connected via SUT to %s [at %s]" % (hwid, foundIP)

  # try connecting via adb
  try:
    sut = DroidADB(deviceSerial=hwid, **kwargs)
  except:
    return None

  print "Connected via ADB to %s" % (hwid)
  return sut
Example #2
0
def DroidConnectByHWID(hwid, timeout=30, **kwargs):
    """Try to connect to the given device by waiting for it to show up using mDNS with the given timeout."""
    zc = Zeroconf(moznetwork.get_ip())

    evt = threading.Event()
    listener = ZeroconfListener(hwid, evt)
    sb = ServiceBrowser(zc, "_sutagent._tcp.local.", listener)
    foundIP = None
    if evt.wait(timeout):
        # we found the hwid
        foundIP = listener.ip
    sb.cancel()
    zc.close()

    if foundIP is not None:
        return DroidSUT(foundIP, **kwargs)
    print "Connected via SUT to %s [at %s]" % (hwid, foundIP)

    # try connecting via adb
    try:
        sut = DroidADB(deviceSerial=hwid, **kwargs)
    except:
        return None

    print "Connected via ADB to %s" % (hwid)
    return sut
Example #3
0
class DiscoveryServer(object):
    def __init__(self, name='DiscoveryServer'):
        self.zeroconf = Zeroconf()
        self.description = {'version': '0.1', 'auth': 'none'}
        self.service_info = ServiceInfo(
                '_http._tcp.local.',
                'waa._http._tcp.local.',
                socket.inet_aton('127.0.0.1'),
                1234,
                0,
                0,
                self.description)

    def run(self):
        self.zeroconf.registerService(self.service_info)

    def stop(self):
        self.zeroconf.close()
Example #4
0
class DiscoveryClient(multiprocessing.Process):
    def __init__(self, name='DiscoveryClient'):
        super(DiscoveryClient, self).__init__(name=name)
        self.event = multiprocessing.Event()
        self.zeroconf = Zeroconf()

    def run(self):
        self.event.set()
        while self.event.is_set():
            service = self.zeroconf.getServiceInfo(
                    '_http._tcp.local.',
                    'waa._http._tcp.local.')
            print service
            time.sleep(1)

    def stop(self):
        self.event.clear()
        self.zeroconf.close()
        self.terminate()
Example #5
0
 def __init__(self, name='DiscoveryServer'):
     self.zeroconf = Zeroconf()
     self.description = {'version': '0.1', 'auth': 'none'}
     self.service_info = ServiceInfo(
             '_http._tcp.local.',
             'waa._http._tcp.local.',
             socket.inet_aton('127.0.0.1'),
             1234,
             0,
             0,
             self.description)
Example #6
0
 def __init__(self, name='DiscoveryClient'):
     super(DiscoveryClient, self).__init__(name=name)
     self.event = multiprocessing.Event()
     self.zeroconf = Zeroconf()