8 manager = dbus.Interface(bus.get_object("net.connman", "/"),
12 print "Usage: %s <command>" % (sys.argv[0])
16 print " autoconnect <service> [autoconnect]"
17 print " connect <service>"
18 print " disconnect <service>"
19 print " remove <service>"
22 print " enable <type>"
23 print " disable <type>"
24 print " offlinemode [on|off]"
27 def print_services(services):
28 for path, properties in services:
29 identifier = path[path.rfind("/") + 1:]
33 if properties["Favorite"] == dbus.Boolean(1):
36 if properties["AutoConnect"] == dbus.Boolean(1):
41 if properties["State"] == "ready":
43 elif properties["State"] == "online":
48 if "Name" in properties.keys():
49 name = properties["Name"]
51 name = "{" + properties["Type"] + "}"
53 print "%s%s%s %-26s { %s }" % (favorite, autoconnect, state,
56 if sys.argv[1] == "state":
57 properties = manager.GetProperties()
59 print "System is %s" % (properties["State"])
61 elif sys.argv[1] in ["services", "list", "show"]:
62 print_services(manager.GetServices())
64 elif sys.argv[1] in ["autoconnect", "autoconn"]:
65 if (len(sys.argv) < 3):
66 print "Need at least service parameter"
69 path = "/net/connman/service/" + sys.argv[2]
71 service = dbus.Interface(bus.get_object("net.connman", path),
72 "net.connman.Service")
74 if (len(sys.argv) > 3):
75 flag = sys.argv[3].strip().lower()
76 autoconnect = dbus.Boolean(flag not in ['false', 'f', 'n', '0'])
78 service.SetProperty("AutoConnect", autoconnect);
80 print "Auto connect %s for %s" % (autoconnect, sys.argv[2])
82 properties = service.GetProperties()
84 if "Name" in properties.keys():
85 name = properties["Name"]
87 name = "{" + properties["Type"] + "}"
89 if "AutoConnect" in properties.keys():
90 autoconnect = properties["AutoConnect"]
92 autoconnect = dbus.Boolean(0)
94 print "Auto connect %s for %s" % (autoconnect, name)
96 elif sys.argv[1] in ["connect", "conn"]:
97 if (len(sys.argv) < 3):
98 print "Need at least service parameter"
101 path = "/net/connman/service/" + sys.argv[2]
103 service = dbus.Interface(bus.get_object("net.connman", path),
104 "net.connman.Service")
107 service.Connect(timeout=60000)
108 except dbus.DBusException, error:
109 print "%s: %s" % (error._dbus_error_name, error.message)
111 elif sys.argv[1] in ["disconnect", "disc"]:
112 if (len(sys.argv) < 3):
113 print "Need at least service parameter"
116 path = "/net/connman/service/" + sys.argv[2]
118 service = dbus.Interface(bus.get_object("net.connman", path),
119 "net.connman.Service")
123 except dbus.DBusException, error:
124 print "%s: %s" % (error._dbus_error_name, error.message)
126 elif sys.argv[1] in ["remove"]:
127 if (len(sys.argv) < 3):
128 print "Need at least service parameter"
131 path = "/net/connman/service/" + sys.argv[2]
133 service = dbus.Interface(bus.get_object("net.connman", path),
134 "net.connman.Service")
136 properties = service.GetProperties()
138 if properties["Favorite"] == dbus.Boolean(0):
139 print "Only favorite services can be removed"
144 except dbus.DBusException, error:
145 print "%s: %s" % (error._dbus_error_name, error.message)
147 elif sys.argv[1] == "scan":
148 if len(sys.argv) == 3:
149 path = "/net/connman/technology/" + sys.argv[2]
150 technology = dbus.Interface(bus.get_object("net.connman", path),
151 "net.connman.Technology")
154 print "'%s' takes two arguments" % sys.argv[1]
156 elif sys.argv[1] == "enable":
157 if len(sys.argv) == 3:
158 path = "/net/connman/technology/" + sys.argv[2]
159 technology = dbus.Interface(bus.get_object("net.connman", path),
160 "net.connman.Technology")
161 technology.SetProperty("Powered", True)
163 print "'%s' takes two arguments" % sys.argv[1]
165 elif sys.argv[1] == "disable":
166 if len(sys.argv) == 3:
167 path = "/net/connman/technology/" + sys.argv[2]
168 technology = dbus.Interface(bus.get_object("net.connman", path),
169 "net.connman.Technology")
170 technology.SetProperty("Powered", False)
172 print "'%s' takes two arguments" % sys.argv[1]
175 elif sys.argv[1] in ["offlinemode", "flightmode"]:
176 if len(sys.argv) == 3:
177 if sys.argv[2] == "on" or sys.argv[2] == "1" or sys.argv[2] == "yes":
178 active = dbus.Boolean(1)
179 elif sys.argv[2] == "off" or sys.argv[2] == "0" or sys.argv[2] == "no":
180 active = dbus.Boolean(0)
182 print "Use either 'on', '1', 'yes', 'off', '0' or 'no'"
185 manager.SetProperty("OfflineMode", active)
186 elif len(sys.argv) == 2:
187 properties = manager.GetProperties()
188 print "Offline mode is %s" % (properties["OfflineMode"])
190 print "'%s' takes max. two arguments" % sys.argv[1]
193 print "Unknown command"