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