Fix test-manager
[platform/upstream/connman.git] / test / test-manager
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                         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("org.moblin.connman", "/"),
26                                         "org.moblin.connman.Manager")
27
28 properties = manager.GetProperties()
29
30 def print_properties(key, value):
31         if key == "Profiles":
32                 interface = "org.moblin.connman.Profile"
33         elif key == "Devices":
34                 interface = "org.moblin.connman.Device"
35         elif key in ["Services", "Providers"]:
36                 interface = "org.moblin.connman.Service"
37         elif key == "Technologies":
38                 interface = "org.moblin.connman.Technology"
39         else:
40                 return
41
42         print "%s" % (key)
43         for path in value:
44                 print "    %s" % (path)
45                 obj = dbus.Interface(bus.get_object("org.moblin.connman", path),
46                                                                 interface)
47
48                 properties = obj.GetProperties()
49
50                 for key in properties.keys():
51                         if key in ["Devices", "Networks", "Services",
52                                                 "Providers", "Technologies"]:
53                                 continue
54
55                         elif key in ["Powered", "Scanning", "Connected",
56                                         "Available", "Remember", "Default",
57                                         "Favorite", "Immutable", "AutoConnect",
58                                                 "LoginRequired", "SetupRequired",
59                                                         "PassphraseRequired"]:
60                                 if properties[key] == dbus.Boolean(1):
61                                         val = "true"
62                                 else:
63                                         val = "false"
64
65                         elif key in ["IPv4", "IPv4.Configuration",
66                                         "IPv6", "IPv6.Configuration",
67                                                 "Proxy", "Ethernet", "Provider"]:
68                                 val = extract_values(properties[key])
69
70                         elif key in ["Nameservers", "Nameservers.Configuration",
71                                         "Domains", "Domains.Configuration"]:
72                                 val = extract_list(properties[key])
73
74                         elif key in ["Strength", "Priority"]:
75                                 val = int(properties[key])
76                         else:
77                                 val = str(properties[key])
78
79                         print "        %s = %s" % (key, val)
80
81                 if "Devices" in properties.keys():
82                         list = ""
83                         for path in properties["Devices"]:
84                                 val = str(path)
85                                 list = list + val[val.rfind("/") + 1:] + " "
86                         print "        Devices = [ %s]" % (list)
87                 if "Networks" in properties.keys():
88                         list = ""
89                         for path in properties["Networks"]:
90                                 val = str(path)
91                                 list = list + val[val.rfind("/") + 1:] + " "
92                         print "        Networks = [ %s]" % (list)
93                 if "Services" in properties.keys():
94                         list = ""
95                         for path in properties["Services"]:
96                                 val = str(path)
97                                 list = list + val[val.rfind("/") + 1:] + " "
98                         print "        Services = [ %s]" % (list)
99                 if "Providers" in properties.keys():
100                         list = ""
101                         for path in properties["Providers"]:
102                                 val = str(path)
103                                 list = list + val[val.rfind("/") + 1:] + " "
104                         print "        Providers = [ %s]" % (list)
105
106
107 for key in properties.keys():
108         if key in ["Profiles", "Devices", "Services", "Providers",
109                                                         "Technologies"]:
110                 print_properties(key, properties[key])
111         elif key in ["AvailableTechnologies", "EnabledTechnologies",
112                                         "ConnectedTechnologies",
113                                 "AvailableDebugs", "EnabledDebugs"]:
114                 print "%s" % (key)
115                 list = ""
116                 for val in properties[key]:
117                         list = list + val + " "
118                 print "    [ %s]" % (list)
119         elif key in ["OfflineMode", "Tethering"]:
120                 print "%s" % (key)
121                 if properties[key] == dbus.Boolean(1):
122                         print "    true"
123                 else:
124                         print "    false"
125         elif key in ["DefaultTechnology"]:
126                 print "%s" % (key)
127                 if properties[key] == "":
128                         print "    <none>"
129                 else:
130                         print "    %s" % (properties[key])
131         else:
132                 print "%s" % (key)
133                 print "    %s" % (properties[key])