about summary refs log tree commit diff
path: root/examples/python/gi/show-wifi-networks.py
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
committerMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
commita54ac63bbf9b2c71026ac9028a8ffaf186cf3c82 (patch)
tree6a32883bd916c4096357b35298beff6db8bcd0b5 /examples/python/gi/show-wifi-networks.py
parent45e8e1149027529194982212c804c0468aa01d98 (diff)
New upstream version 1.25.90 upstream/1.25.90
Diffstat (limited to 'examples/python/gi/show-wifi-networks.py')
-rwxr-xr-xexamples/python/gi/show-wifi-networks.py65
1 files changed, 41 insertions, 24 deletions
diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py
index e1ee4c3d..b865a85a 100755
--- a/examples/python/gi/show-wifi-networks.py
+++ b/examples/python/gi/show-wifi-networks.py
@@ -7,7 +7,8 @@
 
 import locale
 import gi
-gi.require_version('NM', '1.0')
+
+gi.require_version("NM", "1.0")
 from gi.repository import NM
 
 #
@@ -19,40 +20,50 @@ from gi.repository import NM
 # an error without it: http://www.python.org/dev/peps/pep-0263/
 #
 
+
 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 = ssid_to_utf8(active_ap)
-    info = "Device: %s | Driver: %s | Active AP: %s" % (dev.get_iface(), dev.get_driver(), ssid)
+    info = "Device: %s | Driver: %s | Active AP: %s" % (
+        dev.get_iface(),
+        dev.get_driver(),
+        ssid,
+    )
     print(info)
-    print('=' * len(info))
+    print("=" * len(info))
+
 
 def mode_to_string(mode):
-    if mode == getattr(NM, '80211Mode').INFRA:
+    if mode == getattr(NM, "80211Mode").INFRA:
         return "INFRA"
-    if mode == getattr(NM, '80211Mode').ADHOC:
+    if mode == getattr(NM, "80211Mode").ADHOC:
         return "ADHOC"
-    if mode == getattr(NM, '80211Mode').AP:
+    if mode == getattr(NM, "80211Mode").AP:
         return "AP"
     return "UNKNOWN"
 
+
 def flags_to_string(flags):
-    if flags & getattr(NM, '80211ApFlags').PRIVACY:
+    if flags & getattr(NM, "80211ApFlags").PRIVACY:
         return "PRIVACY"
     return "NONE"
 
+
 def security_flags_to_string(flags):
-    NM_AP_FLAGS = getattr(NM, '80211ApSecurityFlags')
+    NM_AP_FLAGS = getattr(NM, "80211ApSecurityFlags")
     str = ""
     if flags & NM_AP_FLAGS.PAIR_WEP40:
         str = str + " PAIR_WEP40"
@@ -79,43 +90,50 @@ def security_flags_to_string(flags):
     else:
         return "NONE"
 
+
 def flags_to_security(flags, wpa_flags, rsn_flags):
     str = ""
-    if ((flags & getattr(NM, '80211ApFlags').PRIVACY) and
-        (wpa_flags == 0) and (rsn_flags == 0)):
-        str = str  + " WEP"
+    if (
+        (flags & getattr(NM, "80211ApFlags").PRIVACY)
+        and (wpa_flags == 0)
+        and (rsn_flags == 0)
+    ):
+        str = str + " WEP"
     if wpa_flags != 0:
         str = str + " WPA1"
     if rsn_flags != 0:
         str = str + " WPA2"
-    if ((wpa_flags & getattr(NM, '80211ApSecurityFlags').KEY_MGMT_802_1X) or
-        (rsn_flags & getattr(NM, '80211ApSecurityFlags').KEY_MGMT_802_1X)):
+    if (wpa_flags & getattr(NM, "80211ApSecurityFlags").KEY_MGMT_802_1X) or (
+        rsn_flags & getattr(NM, "80211ApSecurityFlags").KEY_MGMT_802_1X
+    ):
         str = str + " 802.1X"
     return str.lstrip()
 
+
 def print_ap_info(ap):
     strength = ap.get_strength()
     frequency = ap.get_frequency()
     flags = ap.get_flags()
     wpa_flags = ap.get_wpa_flags()
     rsn_flags = ap.get_rsn_flags()
-    print("SSID:      %s"      % (ssid_to_utf8(ap)))
-    print("BSSID:     %s"      % (ap.get_bssid()))
-    print("Frequency: %s"      % (frequency))
-    print("Channel:   %s"      % (NM.utils_wifi_freq_to_channel(frequency)))
-    print("Mode:      %s"      % (mode_to_string(ap.get_mode())))
-    print("Flags:     %s"      % (flags_to_string(flags)))
-    print("WPA flags: %s"      % (security_flags_to_string(wpa_flags)))
-    print("RSN flags: %s"      % (security_flags_to_string(rsn_flags)))
-    print("Security:  %s"      % (flags_to_security(flags, wpa_flags, rsn_flags)))
+    print("SSID:      %s" % (ssid_to_utf8(ap)))
+    print("BSSID:     %s" % (ap.get_bssid()))
+    print("Frequency: %s" % (frequency))
+    print("Channel:   %s" % (NM.utils_wifi_freq_to_channel(frequency)))
+    print("Mode:      %s" % (mode_to_string(ap.get_mode())))
+    print("Flags:     %s" % (flags_to_string(flags)))
+    print("WPA flags: %s" % (security_flags_to_string(wpa_flags)))
+    print("RSN flags: %s" % (security_flags_to_string(rsn_flags)))
+    print("Security:  %s" % (flags_to_security(flags, wpa_flags, rsn_flags)))
     print("Strength:  %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength))
     print
 
+
 if __name__ == "__main__":
     # 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, '')
+    locale.setlocale(locale.LC_ALL, "")
 
     nmc = NM.Client.new(None)
     devs = nmc.get_devices()
@@ -125,4 +143,3 @@ if __name__ == "__main__":
             print_device_info(dev)
             for ap in dev.get_access_points():
                 print_ap_info(ap)
-