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