diff options
| author | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
| commit | 2c032d8f1c6292c1338a615e6ec40252889ba85c (patch) | |
| tree | 1f77182220b2b0264288ba4a476ab47e5bc48716 /examples/python/gi/show-wifi-networks.py | |
| parent | 33491bc4279481db8ae47213e34a6d695a0e8830 (diff) | |
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'examples/python/gi/show-wifi-networks.py')
| -rwxr-xr-x | examples/python/gi/show-wifi-networks.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py index 9d9e3471..7f3bd2db 100755 --- a/examples/python/gi/show-wifi-networks.py +++ b/examples/python/gi/show-wifi-networks.py @@ -20,33 +20,32 @@ # Copyright (C) 2013 Red Hat, Inc. # -from gi.repository import NetworkManager, NMClient +import locale +from gi.repository import NM # # This example lists Wi-Fi access points NetworkManager scanned on Wi-Fi devices. -# It calls libnm-glib functions using GObject introspection. +# It calls libnm functions using GObject introspection. # # Note the second line of the file: coding=utf-8 # It is necessary because we use unicode characters and python would produce # an error without it: http://www.python.org/dev/peps/pep-0263/ # -signal_bars = { - 0 : "____", - 1 : "▂___", - 2 : "▂▄__", - 3 : "▂▄▆_", - 4 : "▂▄▆█" -} - def clamp(value, minvalue, maxvalue): return max(minvalue, min(value, maxvalue)) +def ssid_to_utf8(ap): + ssid = ap.get_ssid() + if not ssid: + return "" + return NM.utils_ssid_to_utf8(ap.get_ssid().get_data()) + def print_device_info(device): active_ap = dev.get_active_access_point() ssid = None if active_ap is not None: - ssid = active_ap.get_ssid() + ssid = ssid_to_utf8(active_ap) info = "Device: %s | Driver: %s | Active AP: %s" % (dev.get_iface(), dev.get_driver(), ssid) print info print '=' * len(info) @@ -54,19 +53,24 @@ def print_device_info(device): def print_ap_info(ap): strength = ap.get_strength() frequency = ap.get_frequency() - print "SSID: %s" % (ap.get_ssid()) + print "SSID: %s" % (ssid_to_utf8(ap)) print "BSSID: %s" % (ap.get_bssid()) print "Frequency: %s" % (frequency) - print "Channel: %s" % (NetworkManager.utils_wifi_freq_to_channel(frequency)) - print "Strength: %s %s%%" % (signal_bars[(clamp(strength-5, 0, 99)+24)/25], strength) + print "Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency)) + print "Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength) print if __name__ == "__main__": - nmc = NMClient.Client.new() + # Python apparently doesn't call setlocale() on its own? We have to call this or else + # NM.utils_wifi_strength_bars() will think the locale is ASCII-only, and return the + # fallback characters rather than the unicode bars + locale.setlocale(locale.LC_ALL, '') + + nmc = NM.Client.new(None) devs = nmc.get_devices() for dev in devs: - if dev.get_device_type() == NetworkManager.DeviceType.WIFI: + if dev.get_device_type() == NM.DeviceType.WIFI: print_device_info(dev) for ap in dev.get_access_points(): print_ap_info(ap) |