X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Ftest-connman;h=45a18d97f9678e9773ab806a88c4d9622d379257;hb=f495d2ed3cb26cba1d2619e3a03a7affa955a7af;hp=ae8cb305352fa6908d915337b6fd0df24d0c1877;hpb=926b10dff37ad869ead0b3add608b7be066875f1;p=platform%2Fupstream%2Fconnman.git diff --git a/test/test-connman b/test/test-connman index ae8cb30..45a18d9 100755 --- a/test/test-connman +++ b/test/test-connman @@ -5,370 +5,189 @@ import dbus bus = dbus.SystemBus() -manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"), - "org.moblin.connman.Manager") +manager = dbus.Interface(bus.get_object("net.connman", "/"), + "net.connman.Manager") if len(sys.argv) < 2: - print "Usage: %s " % (sys.argv[0]) - print "" - print " state" - print " services" - print " passphrase [passphrase]" - print " connect " - print " disconnect " - print " remove " - print "" - print " scan [ ]" - print " dev " - print " dev scan" - print " dev networks" - print " dev connect " - print " dev remember " - print " dev disconnect [network]" - print " dev policy [ignore|off|auto|manual]" - print " dev powered [on|off]" - print " dev priority [0-255]" + print("Usage: %s " % (sys.argv[0])) + print("") + print(" state") + print(" services") + print(" autoconnect [autoconnect]") + print(" connect ") + print(" disconnect ") + print(" remove ") + print("") + print(" scan ") + print(" enable ") + print(" disable ") + print(" offlinemode [on|off]") sys.exit(1) -def print_properties(path, properties): - print "[ %s ]" % (path) - for key in properties.keys(): - if key == "Networks": - continue - - if key in ["Powered", "Scanning", "Connected", - "Available", "Remember", "Default"]: - if properties[key] == dbus.Boolean(1): - val = "true" - else: - val = "false" - elif key in ["Strength", "Priority"]: - val = int(properties[key]) - else: - val = str(properties[key]) - - print " %s = %s" % (key, val) - - if "Networks" in properties.keys(): - list = "" - for path in properties["Networks"]: - val = str(path) - list = list + val[val.rfind("/") + 1:] + " " - print " Networks = [ %s]" % (list) - -def print_networks(networks): - for path in networks: - network = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Network") - - properties = network.GetProperties() - - if properties["Connected"] == dbus.Boolean(1): - connected = "*" - else: - connected = " " - - if "Name" in properties.keys(): - name = properties["Name"] - else: - name = "" - - strength = int(properties["Strength"]) - - details = "" - try: - details += "{" + properties["WiFi.Mode"] + "} " - except: - pass - try: - details += "{" + properties["WiFi.Security"] + "} " - except: - pass - if "WiFi.Passphrase" in properties.keys(): - if properties["WiFi.Passphrase"] != "": - details += "{passphrase present}" - - print "%s %-26s %3d%% %s" % (connected, - name, strength, details) - -def select_network(networks, name): - for path in networks: - network = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Network") - - properties = network.GetProperties() - - if properties["Name"] != name: - continue - - if properties["Connected"] == dbus.Boolean(1): - print "Already connected to network %s" % (name) - break - - print "Selecting network %s" % (name) - - network.Connect() - -def remember_network(networks, name): - for path in networks: - network = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Network") - - properties = network.GetProperties() - - if properties["Name"] != name: - continue - - if properties["Remember"] == dbus.Boolean(1): - print "Already a known network %s" % (name) - break - - print "Remembering network %s" % (name) - - network.SetProperty("Remember", dbus.Boolean(1)) - -def disconnect_network(networks, name): - for path in networks: - network = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Network") - - properties = network.GetProperties() - - if name != "" and properties["Name"] != name: - continue - - if properties["Connected"] == dbus.Boolean(1): - name = properties["Name"] - print "Disconnecting from network %s" % (name) - network.Disconnect() - def print_services(services): - for path in services: - service = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.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 = " " - if "Name" in properties.keys(): + if "Name" in list(properties.keys()): name = properties["Name"] 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"]) + 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 ["passphrase", "pass"]: +elif sys.argv[1] in ["autoconnect", "autoconn"]: if (len(sys.argv) < 3): - print "Need at least service parameter" + print("Need at least service parameter") sys.exit(1) - path = "/profile/default/" + sys.argv[2] + path = "/net/connman/service/" + sys.argv[2] - service = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Service") + service = dbus.Interface(bus.get_object("net.connman", path), + "net.connman.Service") if (len(sys.argv) > 3): - passphrase = sys.argv[3] + flag = sys.argv[3].strip().lower() + autoconnect = dbus.Boolean(flag not in ['false', 'f', 'n', '0']) - service.SetProperty("Passphrase", passphrase); + service.SetProperty("AutoConnect", autoconnect); - print "Passphrase %s set for %s" % (passphrase, sys.argv[2]) + print("Auto connect %s for %s" % (autoconnect, sys.argv[2])) else: properties = service.GetProperties() - if "Name" in properties.keys(): + if "Name" in list(properties.keys()): name = properties["Name"] else: name = "{" + properties["Type"] + "}" - if "Passphrase" in properties.keys(): - passphrase = properties["Passphrase"] + if "AutoConnect" in list(properties.keys()): + autoconnect = properties["AutoConnect"] else: - passphrase = "not set" + autoconnect = dbus.Boolean(0) - print "Passphrase for %s is %s" % (name, passphrase) + print("Auto connect %s for %s" % (autoconnect, name)) elif sys.argv[1] in ["connect", "conn"]: if (len(sys.argv) < 3): - print "Need at least service parameter" + print("Need at least service parameter") sys.exit(1) - path = "/profile/default/" + sys.argv[2] + path = "/net/connman/service/" + sys.argv[2] - service = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Service") + service = dbus.Interface(bus.get_object("net.connman", path), + "net.connman.Service") - service.Connect(timeout=60000) + try: + service.Connect(timeout=60000) + except dbus.DBusException as error: + print("%s: %s" % (error._dbus_error_name, error.message)) elif sys.argv[1] in ["disconnect", "disc"]: if (len(sys.argv) < 3): - print "Need at least service parameter" + print("Need at least service parameter") sys.exit(1) - path = "/profile/default/" + sys.argv[2] + path = "/net/connman/service/" + sys.argv[2] - service = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Service") + service = dbus.Interface(bus.get_object("net.connman", path), + "net.connman.Service") - service.Disconnect() + try: + service.Disconnect() + except dbus.DBusException as error: + print("%s: %s" % (error._dbus_error_name, error.message)) elif sys.argv[1] in ["remove"]: if (len(sys.argv) < 3): - print "Need at least service parameter" + print("Need at least service parameter") sys.exit(1) - path = "/profile/default/" + sys.argv[2] + path = "/net/connman/service/" + sys.argv[2] - service = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Service") + service = dbus.Interface(bus.get_object("net.connman", path), + "net.connman.Service") properties = service.GetProperties() if properties["Favorite"] == dbus.Boolean(0): - print "Only favorite services can be removed" + print("Only favorite services can be removed") sys.exit(1) - service.Remove() + try: + service.Remove() + except dbus.DBusException as error: + print("%s: %s" % (error._dbus_error_name, error.message)) elif sys.argv[1] == "scan": - properties = manager.GetProperties() - - interface = "" - found = 0 - - if len(sys.argv) > 2: - interface = sys.argv[2] - - for path in properties["Devices"]: - device = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Device") - - properties = device.GetProperties() - - if interface != "" and properties["Interface"] != interface: - continue - - if properties["Type"] in ["wifi", "wimax"]: - interface = properties["Interface"] - print "Propose scanning for device %s" % (interface) - device.ProposeScan() - found = 1 - elif interface != "": - print "No scanning support for device %s" % (interface) - found = 1 - - if found == 0: - print "No such device" - -elif sys.argv[1] == "dev": - properties = manager.GetProperties() - - interface = "" - command = "" - value = "" - found = 0 - - if len(sys.argv) > 2: - interface = sys.argv[2] - if len(sys.argv) > 3: - command = sys.argv[3] - if len(sys.argv) > 4: - value = sys.argv[4] - - for path in properties["Devices"]: - device = dbus.Interface(bus.get_object("org.moblin.connman", path), - "org.moblin.connman.Device") - - properties = device.GetProperties() + 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) == 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) == 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]) - if interface != "" and properties["Interface"] != interface: - continue - if command == "scan": - if properties["Type"] in ["wifi", "wimax"]: - interface = properties["Interface"] - print "Scan for device %s" % (interface) - device.ProposeScan() - else: - print "No scanning for device %s" % (interface) - elif command in ["networks", "net"]: - if "Networks" in properties.keys(): - print_networks(properties["Networks"]) - else: - print "Device has no networks" - elif command in ["connect", "conn"] and value != "": - if "Networks" in properties.keys(): - select_network(properties["Networks"], value) - else: - print "Device can't connect networks" - elif command in ["connect", "conn"]: - print "Need to specify network" - elif command in ["remember", "known"] and value != "": - if "Networks" in properties.keys(): - remember_network(properties["Networks"], value) - else: - print "Device has no networks" - elif command in ["remember", "known"]: - print "Need to specify network" - elif command in ["disconnect", "disc"] and value != "": - if "Networks" in properties.keys(): - disconnect_network(properties["Networks"], value) - else: - print "Device has no networks" - elif command in ["discconnect", "disc"]: - if "Networks" in properties.keys(): - disconnect_network(properties["Networks"], "") - else: - print "Device has no networks" - elif command == "policy" and value != "": - policy = value - device.SetProperty("Policy", policy) - elif command == "policy": - interface = properties["Interface"] - policy = properties["Policy"] - print "Policy of device %s is %s" % (interface, policy) - elif command == "powered" and value != "": - if value == "on": - powered = dbus.Boolean(1) - elif value == "off": - powered = dbus.Boolean(0) - else: - powered = dbus.Boolean(value) - device.SetProperty("Powered", powered) - elif command == "powered": - interface = properties["Interface"] - if properties["Powered"] == dbus.Boolean(1): - powered = "on" - else: - powered = "off" - print "Device %s is powered %s" % (interface, powered) - elif command == "priority" and value != "": - priority = int(value) - device.SetProperty("Priority", priority) - elif command == "priority": - interface = properties["Interface"] - priority = properties["Priority"] - print "Device %s has priority of %d" % (interface, priority) - elif command == "list" or command == "": - print_properties(path, properties) +elif sys.argv[1] in ["offlinemode", "flightmode"]: + 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" or sys.argv[2] == "0" or sys.argv[2] == "no": + active = dbus.Boolean(0) else: - print "Unknown command" + print("Use either 'on', '1', 'yes', 'off', '0' or 'no'") + exit() + + manager.SetProperty("OfflineMode", active) + 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" + print("Unknown command")