Fix PASSED_TO_PROC_AFTER_FREE.EX
[platform/upstream/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 list(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                         elif key in ["Ethernet", "IPv4"]:
15                                 val += extract_values(values[key])
16                         else:
17                                 val += str(values[key])
18         val += " }"
19         return val
20
21 def extract_list(list):
22         val = "["
23         for i in list:
24                 val += " " + str(i)
25         val += " ]"
26         return val
27
28 bus = dbus.SystemBus()
29
30 manager = dbus.Interface(bus.get_object("net.connman", "/"),
31                                         "net.connman.Manager")
32
33 for path, properties in manager.GetServices():
34         service = dbus.Interface(bus.get_object("net.connman", path),
35                                                 "net.connman.Service")
36         identifier = path[path.rfind("/") + 1:]
37         print("[ %s ]" % (identifier))
38
39         for key in list(properties.keys()):
40                 if key in ["IPv4", "IPv4.Configuration",
41                                 "IPv6", "IPv6.Configuration",
42                                         "Proxy", "Proxy.Configuration",
43                                         "Ethernet", "Provider",
44                                         "LastAddressConflict"]:
45                         val = extract_values(properties[key])
46                 elif key in ["Nameservers", "Nameservers.Configuration",
47                              "Domains", "Domains.Configuration",
48                              "Timeservers", "Timeservers.Configuration",
49                              "Security"]:
50                         val = extract_list(properties[key])
51                 elif key in ["Favorite", "Immutable", "AutoConnect",
52                                         "LoginRequired", "PassphraseRequired"]:
53                         if properties[key] == dbus.Boolean(1):
54                                 val = "true"
55                         else:
56                                 val = "false"
57                 elif key in ["Strength"]:
58                         val = int(properties[key])
59                 else:
60                         val = properties[key]
61                 print("    %s = %s" % (key, val))
62
63         print()