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 		elif (key == "UUIDs"):
     44 			list = extract_uuids(value)
     45 			print "    %s = %s" % (key, list)
     46 		else:
     47 			print "    %s = %s" % (key, value)
     48 
     49 	try:
     50 		device_list = properties["Devices"]
     51 	except:
     52 		device_list = []
     53 
     54 	for n in device_list:
     55 		device = dbus.Interface(bus.get_object("org.bluez", n),
     56 							"org.bluez.Device")
     57 		print "    [ " + n + " ]"
     58 
     59 		properties = device.GetProperties()
     60 		for key in properties.keys():
     61 			value = properties[key]
     62 			if (key == "Nodes"):
     63 				list = extract_objects(value)
     64 				print "        %s = %s" % (key, list)
     65 			elif (key == "UUIDs"):
     66 				list = extract_uuids(value)
     67 				print "        %s = %s" % (key, list)
     68 			elif (key == "Class"):
     69 				print "        %s = 0x%06x" % (key, value)
     70 			else:
     71 				print "        %s = %s" % (key, value)
     72 
     73 		try:
     74 			node_list = properties["Nodes"]
     75 		except:
     76 			node_list = []
     77 
     78 		for x in node_list:
     79 			node = dbus.Interface(bus.get_object("org.bluez", x),
     80 							"org.bluez.Node")
     81 			print "        [ " + x + " ]"
     82 
     83 			properties = node.GetProperties()
     84 			for key in properties.keys():
     85 				print "            %s = %s" % (key, properties[key])
     86 
     87 	print
     88