1#!/usr/bin/python
2
3import dbus
4
5def print_sub_properties(key, value):
6    if key == "Profiles":
7        interface = "org.chromium.flimflam.Profile"
8    elif key == "Devices":
9        interface = "org.chromium.flimflam.Device"
10    elif key == "Services":
11        interface = "org.chromium.flimflam.Service"
12    else:
13        return
14
15    print "%s" % (key)
16    for path in value:
17        print "    %s" % (path)
18        obj = dbus.Interface(bus.get_object("org.chromium.flimflam", path),
19                             interface)
20
21        properties = obj.GetProperties(utf8_strings = True)
22
23        for key in properties.keys():
24            if key in ["Networks", "Services"]:
25                continue
26
27            if key in ["Powered", "Scanning", "Connected",
28                       "Available", "Remember", "Default"]:
29                if properties[key] == dbus.Boolean(1):
30                    val = "true"
31                else:
32                    val = "false"
33            elif key in ["Strength", "Priority"]:
34                val = int(properties[key])
35            else:
36                val = str(properties[key])
37
38            print "        %s = %s" % (key, val)
39
40        if "Services" in properties.keys():
41            remove_prefix = lambda x: x[x.rfind("/") + 1]
42            services = [" ".join(
43                map(remove_prefix, map(str, properties["Services"])))]
44            print "        Services = [ %s]" % (services)
45
46def print_properties(properties):
47    for key in properties.keys():
48        if key in ["Profiles", "Devices", "Services"]:
49            print_sub_properties(key, properties[key])
50        elif key in ["AvailableTechnologies", "EnabledTechnologies",
51                     "ConnectedTechnologies"]:
52            print "%s" % (key)
53            print "    [ %s]" % (" ".join(properties[key]))
54        elif key in ["OfflineMode"]:
55            print "%s" % (key)
56            if properties[key] == dbus.Boolean(1):
57                print "    true"
58            else:
59                print "    false"
60        elif key in ["DefaultTechnology"]:
61            print "%s" % (key)
62            if properties[key] == "":
63                print "    <none>"
64            else:
65                print "    %s" % (properties[key])
66        else:
67            print "%s" % (key)
68            print "    %s" % (properties[key])
69
70bus = dbus.SystemBus()
71
72manager = dbus.Interface(bus.get_object("org.chromium.flimflam", "/"),
73                                        "org.chromium.flimflam.Manager")
74
75print_properties(manager.GetProperties(utf8_strings = True))
76