def get_state(devices): """Returns state information about all the devices connected to the host. """ keys = (u'board.platform', u'build.product', u'build.fingerprint', u'build.id', u'build.type', u'build.version.sdk', u'product.board', u'product.cpu.abi', u'product.device') def fn(device): if not device.is_valid or device.failure: return {u'state': device.failure or 'unavailable'} properties = device.cache.build_props if not properties: return {u'state': 'unavailable'} no_sd_card = properties.get(u'ro.product.model', '') in ['Chromecast'] return { u'battery': device.GetBattery(), u'build': { key: properties.get(u'ro.' + key, '<missing>') for key in keys }, u'cpu': device.GetCPUScale(), u'disk': device.GetDisk(), u'imei': device.GetIMEI(), u'ip': device.GetIPs(), u'max_uid': device.GetLastUID(), u'mem': device.GetMemInfo(), u'other_packages': get_unknown_apps(device), u'port_path': device.port_path, u'processes': device.GetProcessCount(), u'state': (u'available' if no_sd_card or device.IsFullyBooted()[0] else u'booting'), u'temp': device.GetTemperatures(), u'uptime': device.GetUptime(), } start = time.time() state = { u'devices': { device.serial: out for device, out in zip(devices, parallel.pmap(fn, devices)) } } logging.info( 'get_state() (device part) took %gs' % round(time.time() - start, 1)) return state
def _ConnectFromHandles(handles, as_root=False, **kwargs): """Connects to the devices provided by handles.""" def fn(handle): device = HighDevice.Connect(handle, **kwargs) if as_root and device.cache.has_su and not device.IsRoot(): # This updates the port path of the device thus clears its cache. device.Root() return device devices = parallel.pmap(fn, handles) _PER_DEVICE_CACHE.trim(devices) return devices
def test_junk(self): parallel._QUEUE_OUT.put(0) self.assertEqual([1, 2], parallel.pmap(lambda x: x+1, [0, 1])) self.assertEqual(0, parallel._QUEUE_OUT.qsize())
def test_locked(self): with parallel._POOL_LOCK: self.assertEqual([1, 2], parallel.pmap(lambda x: x+1, [0, 1]))
def test_throw_2(self): def fn(_): raise Foo() with self.assertRaises(Foo): parallel.pmap(fn, [0, 1])
def test_2(self): self.assertEqual([1, 2], parallel.pmap(lambda x: x+1, [0, 1]))
def test_1(self): self.assertEqual([1], parallel.pmap(lambda x: x+1, [0]))
def test_0(self): self.assertEqual([], parallel.pmap(self.fail, []))
def test_junk(self): parallel._QUEUE_OUT.put(0) self.assertEqual([1, 2], parallel.pmap(lambda x: x + 1, [0, 1])) self.assertEqual(0, parallel._QUEUE_OUT.qsize())
def test_locked(self): with parallel._POOL_LOCK: self.assertEqual([1, 2], parallel.pmap(lambda x: x + 1, [0, 1]))
def test_2(self): self.assertEqual([1, 2], parallel.pmap(lambda x: x + 1, [0, 1]))
def test_1(self): self.assertEqual([1], parallel.pmap(lambda x: x + 1, [0]))