Adding connman-test subpackage
[framework/connectivity/connman.git] / test / get-services
1 #!/usr/bin/python
2
3 import dbus
4
5 def extract_values(values):
6         val = "{"
7         for key in values.keys():
8                 val += " " + key + "="
9                 if key in ["Servers", "Excludes"]:
10                         val += extract_list(values[key])
11                 else:
12                         val += str(values[key])
13         val += " }"
14         return val
15
16 def extract_list(list):
17         val = "["
18         for i in list:
19                 val += " " + str(i)
20         val += " ]"
21         return val
22
23 bus = dbus.SystemBus()
24
25 manager = dbus.Interface(bus.get_object('net.connman', '/'),
26                                         'net.connman.Manager')
27
28 services = manager.GetServices()
29
30 for entry in services:
31         path = entry[0]
32         properties = entry[1]
33
34         print "[ %s ]" % (path)
35
36         for key in properties.keys():
37                 if key in ["IPv4", "IPv4.Configuration",
38                                         "IPv6", "IPv6.Configuration",
39                                         "Proxy", "Proxy.Configuration",
40                                                 "Ethernet", "Provider"]:
41                         val = extract_values(properties[key])
42                 elif key in ["Nameservers", "Nameservers.Configuration",
43                                         "Domains", "Domains.Configuration",
44                                                 "Security"]:
45                         val = extract_list(properties[key])
46                 elif key in ["Favorite", "Immutable", "AutoConnect",
47                                 "PassphraseRequired"]:
48                         if properties[key] == dbus.Boolean(1):
49                                 val = "true"
50                         else:
51                                 val = "false"
52                 elif key in ["Strength"]:
53                         val = int(properties[key])
54                 else:
55                         val = str(properties[key])
56                 print "    %s = %s" % (key, val)
57
58         print