From c88e99a067b6bdb356932092e80e127b43812ac4 Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Tue, 31 Oct 2023 10:28:59 +0200 Subject: [PATCH] python: rename ssid_check_valid_length.py & add a docstring --- ...alid-len.py => ssid_check_valid_length.py} | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) rename python/{ssid-valid-len.py => ssid_check_valid_length.py} (59%) diff --git a/python/ssid-valid-len.py b/python/ssid_check_valid_length.py similarity index 59% rename from python/ssid-valid-len.py rename to python/ssid_check_valid_length.py index c75cc75..9810763 100755 --- a/python/ssid-valid-len.py +++ b/python/ssid_check_valid_length.py @@ -4,7 +4,7 @@ This script asks for a SSID name, counts it and tells whether it's of valid length """ # Request input or assume "test" on empty. -givenssid = str( +GIVENSSID = str( input( "Please enter the SSID you are thinking of (preferably 26 chars to fit _nomap): ", ) @@ -13,28 +13,32 @@ givenssid = str( # Ensure it's UTF-8 and store the size. E.g. åäö are longer than oao # TODO: make this a function too -givenssidlen = len(givenssid.encode("utf8")) +GIVENSSIDLEN = len(GIVENSSID.encode("utf8")) # Checking the SSID length is done twice, so thus a function -def checkssidlen(givenssidlen): +def checkssidlen(GIVENSSIDLEN): + """ + This function checks that the given string is below 32 characters long and + can thus be used as an SSID. + """ # 32 bytes should be the maximum SSID length - if givenssidlen <= 32: - print(givenssid, "is", givenssidlen, "long and thus valid length") + if GIVENSSIDLEN <= 32: + print(GIVENSSID, "is", GIVENSSIDLEN, "long and thus valid length") else: print( - givenssid, + GIVENSSID, "is", - givenssidlen, + GIVENSSIDLEN, "to long, please select a different SSID", ) # Checking the SSID without _nomap -checkssidlen(givenssidlen) +checkssidlen(GIVENSSIDLEN) # TODO: make this a function too -givenssidlen = len(givenssid.encode("utf8")) +GIVENSSIDLEN = len(GIVENSSID.encode("utf8")) # Continuing with _nomap to ensure it also fits -givenssid = givenssid + "_nomap" -checkssidlen(givenssidlen) +GIVENSSID = GIVENSSID + "_nomap" +checkssidlen(GIVENSSIDLEN)