loopback: Improve Error Reporting when Recovering Loopback
[framework/connectivity/connman.git] / test / list-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 ["PrefixLength"]:
10                         val += "%s" % (int(values[key]))
11                 else:
12                         if key in ["Servers", "Excludes"]:
13                                 val += extract_list(values[key])
14                         else:
15                                 val += str(values[key])
16         val += " }"
17         return val
18
19 def extract_list(list):
20         val = "["
21         for i in list:
22                 val += " " + str(i)
23         val += " ]"
24         return val
25
26 bus = dbus.SystemBus()
27
28 manager = dbus.Interface(bus.get_object("net.connman", "/"),
29                                         "net.connman.Manager")
30
31 properties = manager.GetProperties()
32
33 for path in properties["Services"]:
34         service = dbus.Interface(bus.get_object("net.connman", path),
35                                                 "net.connman.Service")
36
37         properties = service.GetProperties()
38
39         print "[ %s ]" % (path)
40
41         for key in properties.keys():
42                 if key in ["IPv4", "IPv4.Configuration",
43                                 "IPv6", "IPv6.Configuration",
44                                         "Proxy", "Proxy.Configuration",
45                                                 "Ethernet", "Provider"]:
46                         val = extract_values(properties[key])
47                 elif key in ["Nameservers", "Nameservers.Configuration",
48                                         "Domains", "Domains.Configuration",
49                                                 "Security"]:
50                         val = extract_list(properties[key])
51                 elif key in ["Favorite", "Immutable", "AutoConnect",
52                                         "LoginRequired", "SetupRequired",
53                                                 "PassphraseRequired"]:
54                         if properties[key] == dbus.Boolean(1):
55                                 val = "true"
56                         else:
57                                 val = "false"
58                 elif key in ["Strength"]:
59                         val = int(properties[key])
60                 else:
61                         val = properties[key]
62                 print "    %s = %s" % (key, val)
63
64         print