-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 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()
-