3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-10-04 10:29:03 +02:00

test: Make runnable with python3

This commit is contained in:
Denis Kenzior 2015-03-19 23:53:16 -05:00
parent dcb5045d8f
commit 31ce761469

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import gobject from gi.repository import GLib
import dbus import dbus
import dbus.service import dbus.service
@ -9,92 +9,90 @@ import sys
from random import randrange from random import randrange
class Canceled(dbus.DBusException): class Canceled(dbus.DBusException):
_dbus_error_name = "net.connman.iwd.Error.Canceled" _dbus_error_name = "net.connman.iwd.Error.Canceled"
class Agent(dbus.service.Object): class Agent(dbus.service.Object):
passphrase = None passphrase = None
@dbus.service.method("net.connman.iwd.Agent", @dbus.service.method("net.connman.iwd.Agent",
in_signature='', out_signature='') in_signature='', out_signature='')
def Release(self): def Release(self):
print("Release") print("Release")
mainloop.quit() mainloop.quit()
def input_passphrase(self): def input_passphrase(self):
response = {} response = {}
if not self.passphrase: if not self.passphrase:
print "Service credentials requested, type cancel to cancel" print("Service credentials requested, type cancel to cancel")
args = raw_input('Answer: ') args = input('Answer: ')
for arg in args.split(): for arg in args.split():
if arg.startswith("cancel"): if arg.startswith("cancel"):
response["Error"] = arg response["Error"] = arg
if arg.startswith("Passphrase="):
passphrase = arg.replace("Passphrase=", "", 1)
response["Passphrase"] = passphrase
else:
if self.passphrase:
response["Passphrase"] = self.passphrase
return response if arg.startswith("Passphrase="):
passphrase = arg.replace("Passphrase=", "", 1)
response["Passphrase"] = passphrase
else:
if self.passphrase:
response["Passphrase"] = self.passphrase
@dbus.service.method("net.connman.iwd.Agent", return response
in_signature='o',
out_signature='s')
def RequestPassphrase(self, path):
print "RequestPassphrase (%s)" % (path)
response = {} @dbus.service.method("net.connman.iwd.Agent",
in_signature='o',
out_signature='s')
def RequestPassphrase(self, path):
print("RequestPassphrase (%s)" % (path))
response.update(self.input_passphrase()) response = {}
response.update(self.input_passphrase())
if response.has_key("Error"): if response.has_key("Error"):
if response["Error"] == "cancel": if response["Error"] == "cancel":
raise Canceled("canceled") raise Canceled("canceled")
return return
print "returning (%s)" % (response["Passphrase"]) print("returning (%s)" % (response["Passphrase"]))
return response["Passphrase"]
return response["Passphrase"]
@dbus.service.method("net.connman.iwd.Agent",
in_signature='', out_signature='')
def Cancel(self):
print "Cancel"
@dbus.service.method("net.connman.iwd.Agent",
in_signature='', out_signature='')
def Cancel(self):
print("Cancel")
def print_usage(): def print_usage():
print "Usage:" print("Usage:")
print "For WPA input:" print("For WPA input:")
print "%s Passphrase=<passphrase>" % (sys.argv[0]) print("%s Passphrase=<passphrase>" % (sys.argv[0]))
print "Help: %s help" % (sys.argv[0]) print("Help: %s help" % (sys.argv[0]))
sys.exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == "help": if len(sys.argv) == 2 and sys.argv[1] == "help":
print_usage() print_usage()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus() bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('net.connman.iwd', "/"), manager = dbus.Interface(bus.get_object('net.connman.iwd', "/"),
'net.connman.iwd.Manager') 'net.connman.iwd.Manager')
path = "/test/agent/" + str(randrange(100)) path = "/test/agent/" + str(randrange(100))
object = Agent(bus, path) object = Agent(bus, path)
if len(sys.argv) >= 2: if len(sys.argv) >= 2:
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg.startswith("Passphrase="): if arg.startswith("Passphrase="):
object.passphrase = arg.replace("Passphrase=", "", 1) object.passphrase = arg.replace("Passphrase=", "", 1)
else: else:
print_usage() print_usage()
try: try:
manager.RegisterAgent(path) manager.RegisterAgent(path)
except: except:
print "Cannot register iwd agent." print("Cannot register iwd agent.")
mainloop = gobject.MainLoop() mainloop = GLib.MainLoop()
mainloop.run() mainloop.run()