#!/usr/bin/python

import dbus

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object('org.ofono', '/'),
						'org.ofono.Manager')

modems = manager.GetModems()

for path, properties in modems:
	print "[ %s ]" % (path)

	for key in properties.keys():
		if key in ["Interfaces", "Features"]:
			val = ""
			for i in properties[key]:
				val += i + " "
		else:
			val = properties[key]
		print "    %s = %s" % (key, val)

	for interface in properties["Interfaces"]:
		object = dbus.Interface(bus.get_object('org.ofono', path),
								interface)

		print "    [ %s ]" % (interface)

		try:
			properties = object.GetProperties()
		except:
			continue

		for key in properties.keys():
			if key in ["Calls",
					"MultipartyCalls",
					"EmergencyNumbers",
					"SubscriberNumbers",
					"PreferredLanguages",
					"PrimaryContexts",
					"LockedPins",
					"Features"]:
				val = ""
				for i in properties[key]:
					val += i + " "
			elif key in ["ServiceNumbers"]:
				val = ""
				for i in properties[key]:
					val += "[" + i + "] = '"
					val += properties[key][i] + "' "
			elif key in ["MobileNetworkCodeLength",
						"VoicemailMessageCount",
						"MicrophoneVolume",
						"SpeakerVolume",
						"Strength",
						"DataStrength",
						"BatteryChargeLevel"]:
				val = int(properties[key])
			elif key in ["MainMenu"]:
				val = ", ".join([ text + " (" + str(int(icon)) +
					")" for text, icon in properties[key] ])
			elif key in ["Retries"]:
				val = ""
				for i in properties[key]:
					val +=  "[" + i + " = "
					val += str(int(properties[key][i])) + "] "
			elif key in ["Settings"]:
				val = "{"
				for i in properties[key].keys():
					val += " " + i + "="
					if i in ["DomainNameServers"]:
						for n in properties[key][i]:
							val += n + ","
					else:
						val += properties[key][i]
				val += " }"
			else:
				val = properties[key]
			print "        %s = %s" % (key, val)

	print
