Home | History | Annotate | Download | only in test
      1 #!/usr/bin/python
      2 
      3 import dbus
      4 
      5 bus = dbus.SystemBus()
      6 
      7 manager = dbus.Interface(bus.get_object("org.bluez", "/"),
      8 						"org.bluez.Manager")
      9 
     10 def extract_objects(object_list):
     11 	list = ""
     12 	for object in object_list:
     13 		val = str(object)
     14 		list = list + val[val.rfind("/") + 1:] + " "
     15 	return list
     16 
     17 def extract_uuids(uuid_list):
     18 	list = ""
     19 	for uuid in uuid_list:
     20 		if (uuid.endswith("-0000-1000-8000-00805f9b34fb")):
     21 			if (uuid.startswith("0000")):
     22 				val = "0x" + uuid[4:8]
     23 			else:
     24 				val = "0x" + uuid[0:8]
     25 		else:
     26 			val = str(uuid)
     27 		list = list + val + " "
     28 	return list
     29 
     30 adapter_list = manager.ListAdapters()
     31 
     32 for i in adapter_list:
     33 	adapter = dbus.Interface(bus.get_object("org.bluez", i),
     34 							"org.bluez.Adapter")
     35 	print "[ " + i + " ]"
     36 
     37 	properties  = adapter.GetProperties()
     38 	for key in properties.keys():
     39 		value = properties[key]
     40 		if (key == "Devices"):
     41 			list = extract_objects(value)
     42 			print "    %s = %s" % (key, list)
     43 		else:
     44 			print "    %s = %s" % (key, value)
     45 
     46 	try:
     47 		device_list = properties["Devices"]
     48 	except:
     49 		device_list = []
     50 
     51 	for n in device_list:
     52 		device = dbus.Interface(bus.get_object("org.bluez", n),
     53 							"org.bluez.Device")
     54 		print "    [ " + n + " ]"
     55 
     56 		properties = device.GetProperties()
     57 		for key in properties.keys():
     58 			value = properties[key]
     59 			if (key == "Nodes"):
     60 				list = extract_objects(value)
     61 				print "        %s = %s" % (key, list)
     62 			elif (key == "UUIDs"):
     63 				list = extract_uuids(value)
     64 				print "        %s = %s" % (key, list)
     65 			elif (key == "Class"):
     66 				print "        %s = 0x%06x" % (key, value)
     67 			else:
     68 				print "        %s = %s" % (key, value)
     69 
     70 		try:
     71 			node_list = properties["Nodes"]
     72 		except:
     73 			node_list = []
     74 
     75 		for x in node_list:
     76 			node = dbus.Interface(bus.get_object("org.bluez", x),
     77 							"org.bluez.Node")
     78 			print "        [ " + x + " ]"
     79 
     80 			properties = node.GetProperties()
     81 			for key in properties.keys():
     82 				print "            %s = %s" % (key, properties[key])
     83 
     84 	print
     85