diff options
| author | Michael Biebl <biebl@debian.org> | 2020-06-28 18:58:14 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2020-06-28 18:58:14 +0200 |
| commit | a54ac63bbf9b2c71026ac9028a8ffaf186cf3c82 (patch) | |
| tree | 6a32883bd916c4096357b35298beff6db8bcd0b5 /examples/python/dbus/wifi-hotspot.py | |
| parent | 45e8e1149027529194982212c804c0468aa01d98 (diff) | |
New upstream version 1.25.90 upstream/1.25.90
Diffstat (limited to 'examples/python/dbus/wifi-hotspot.py')
| -rwxr-xr-x | examples/python/dbus/wifi-hotspot.py | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/examples/python/dbus/wifi-hotspot.py b/examples/python/dbus/wifi-hotspot.py index d4f17d07..a3c573a6 100755 --- a/examples/python/dbus/wifi-hotspot.py +++ b/examples/python/dbus/wifi-hotspot.py @@ -13,38 +13,42 @@ import dbus, sys, time -our_uuid = '2b0d0f1d-b79d-43af-bde1-71744625642e' - -s_con = dbus.Dictionary({ - 'type': '802-11-wireless', - 'uuid': our_uuid, - 'id': 'Test Hotspot'}) - -s_wifi = dbus.Dictionary({ - 'ssid': dbus.ByteArray("My Hotspot".encode("utf-8")), - 'mode': "ap", - 'band': "bg", - 'channel': dbus.UInt32(1)}) - -s_wsec = dbus.Dictionary({ - 'key-mgmt': 'wpa-psk', - 'psk': 'great password'}) - -s_ip4 = dbus.Dictionary({'method': 'shared'}) -s_ip6 = dbus.Dictionary({'method': 'ignore'}) - -con = dbus.Dictionary({ - 'connection': s_con, - '802-11-wireless': s_wifi, - '802-11-wireless-security': s_wsec, - 'ipv4': s_ip4, - 'ipv6': s_ip6 - }) +our_uuid = "2b0d0f1d-b79d-43af-bde1-71744625642e" + +s_con = dbus.Dictionary( + {"type": "802-11-wireless", "uuid": our_uuid, "id": "Test Hotspot"} +) + +s_wifi = dbus.Dictionary( + { + "ssid": dbus.ByteArray("My Hotspot".encode("utf-8")), + "mode": "ap", + "band": "bg", + "channel": dbus.UInt32(1), + } +) + +s_wsec = dbus.Dictionary({"key-mgmt": "wpa-psk", "psk": "great password"}) + +s_ip4 = dbus.Dictionary({"method": "shared"}) +s_ip6 = dbus.Dictionary({"method": "ignore"}) + +con = dbus.Dictionary( + { + "connection": s_con, + "802-11-wireless": s_wifi, + "802-11-wireless-security": s_wsec, + "ipv4": s_ip4, + "ipv6": s_ip6, + } +) + def usage(): print("Usage: %s <ifname> [up|down]" % sys.argv[0]) sys.exit(0) + bus = dbus.SystemBus() service_name = "org.freedesktop.NetworkManager" proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManager/Settings") @@ -62,9 +66,11 @@ devpath = nm.GetDeviceByIpIface(iface) connection_path = None for path in settings.ListConnections(): proxy = bus.get_object(service_name, path) - settings_connection = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings.Connection") + settings_connection = dbus.Interface( + proxy, "org.freedesktop.NetworkManager.Settings.Connection" + ) config = settings_connection.GetSettings() - if config['connection']['uuid'] == our_uuid: + if config["connection"]["uuid"] == our_uuid: connection_path = path break @@ -84,7 +90,9 @@ if operation == "up": # Wait for the hotspot to start up start = time.time() while time.time() < start + 10: - state = active_props.Get("org.freedesktop.NetworkManager.Connection.Active", "State") + state = active_props.Get( + "org.freedesktop.NetworkManager.Connection.Active", "State" + ) if state == 2: # NM_ACTIVE_CONNECTION_STATE_ACTIVATED print("Access point started") sys.exit(0) @@ -96,4 +104,3 @@ else: usage() sys.exit(0) - |