sys.exit(1)
def print_services(services):
- for path in services:
- service = dbus.Interface(bus.get_object("net.connman", path),
- "net.connman.Service")
-
- properties = service.GetProperties()
-
+ for path, properties in services:
identifier = path[path.rfind("/") + 1:]
+ state = " "
+ autoconnect = " "
if properties["Favorite"] == dbus.Boolean(1):
favorite = "*"
+
+ if properties["AutoConnect"] == dbus.Boolean(1):
+ autoconnect = " A"
+ else:
+ autoconnect = " "
+
+ if properties["State"] == "ready":
+ state = "R"
+ elif properties["State"] == "online":
+ state = "O"
else:
favorite = " "
else:
name = "{" + properties["Type"] + "}"
- print "%s %-26s { %s }" % (favorite, name, identifier)
+ print "%s%s%s %-26s { %s }" % (favorite, autoconnect, state,
+ name, identifier)
if sys.argv[1] == "state":
properties = manager.GetProperties()
print "System is %s" % (properties["State"])
elif sys.argv[1] in ["services", "list", "show"]:
- properties = manager.GetProperties()
-
- print_services(properties["Services"])
+ print_services(manager.GetServices())
elif sys.argv[1] in ["autoconnect", "autoconn"]:
if (len(sys.argv) < 3):
print "%s: %s" % (error._dbus_error_name, error.message)
elif sys.argv[1] == "scan":
- if len(sys.argv) > 2:
+ if len(sys.argv) == 3:
path = "/net/connman/technology/" + sys.argv[2]
technology = dbus.Interface(bus.get_object("net.connman", path),
"net.connman.Technology")
technology.Scan()
+ else:
+ print "'%s' takes two arguments" % sys.argv[1]
elif sys.argv[1] == "enable":
- if len(sys.argv) > 2:
+ if len(sys.argv) == 3:
path = "/net/connman/technology/" + sys.argv[2]
technology = dbus.Interface(bus.get_object("net.connman", path),
"net.connman.Technology")
technology.SetProperty("Powered", True)
+ else:
+ print "'%s' takes two arguments" % sys.argv[1]
elif sys.argv[1] == "disable":
- if len(sys.argv) > 2:
+ if len(sys.argv) == 3:
path = "/net/connman/technology/" + sys.argv[2]
technology = dbus.Interface(bus.get_object("net.connman", path),
"net.connman.Technology")
technology.SetProperty("Powered", False)
+ else:
+ print "'%s' takes two arguments" % sys.argv[1]
+
elif sys.argv[1] in ["offlinemode", "flightmode"]:
- if len(sys.argv) > 2:
- if sys.argv[2] == "on":
+ if len(sys.argv) == 3:
+ if sys.argv[2] == "on" or sys.argv[2] == "1" or sys.argv[2] == "yes":
active = dbus.Boolean(1)
- elif sys.argv[2] == "off":
+ elif sys.argv[2] == "off" or sys.argv[2] == "0" or sys.argv[2] == "no":
active = dbus.Boolean(0)
else:
- active = dbus.Boolean(sys.argv[2])
+ print "Use either 'on', '1', 'yes', 'off', '0' or 'no'"
+ exit()
+
manager.SetProperty("OfflineMode", active)
- else:
+ elif len(sys.argv) == 2:
properties = manager.GetProperties()
print "Offline mode is %s" % (properties["OfflineMode"])
+ else:
+ print "'%s' takes max. two arguments" % sys.argv[1]
else:
print "Unknown command"