diff --git a/cloudmesh/burn/command/burn.py b/cloudmesh/burn/command/burn.py index 90f3305..38b1eed 100644 --- a/cloudmesh/burn/command/burn.py +++ b/cloudmesh/burn/command/burn.py @@ -557,7 +557,7 @@ def execute(label, function): if manager: if not ssid: ssid = get_ssid() - if ssid is None: + if ssid == "" or ssid is None: Console.info('Wireless connection not detected. The user can specify the SSID when running ' 'this command with --ssid=SSID. Skipping SSID') else: diff --git a/cloudmesh/burn/wifi/ssid.py b/cloudmesh/burn/wifi/ssid.py index f98b891..304d40d 100644 --- a/cloudmesh/burn/wifi/ssid.py +++ b/cloudmesh/burn/wifi/ssid.py @@ -3,28 +3,55 @@ from cloudmesh.common.systeminfo import os_is_mac from cloudmesh.common.systeminfo import os_is_pi from cloudmesh.common.systeminfo import os_is_windows +from cloudmesh.common.Printer import Printer +from cloudmesh.common.util import yn_choice +from cloudmesh.common.util import Console +import subprocess def get_ssid(): ssid = "" - try: - if os_is_mac(): - command = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I" - r = Shell.run(command).replace("\t", "").splitlines() - ssid = Shell.cm_grep(r, " SSID:")[0].split(":")[1].strip() - elif os_is_linux(): - command = "iwgetid -r" - ssid = Shell.run(command).strip() - elif os_is_pi(): - command = "iwgetid -r" - ssid = Shell.run(command).strip() - elif os_is_windows(): + r = "" + if os_is_mac(): + command = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I" + r = Shell.run(command).replace("\t", "").splitlines() + ssid = Shell.cm_grep(r, " SSID:")[0].split(":")[1].strip() + elif os_is_linux(): + command = "iwgetid -r" + ssid = Shell.run(command).strip() + elif os_is_pi(): + command = "iwgetid -r" + ssid = Shell.run(command).strip() + elif os_is_windows(): + try: try: r = Shell.run('netsh wlan show interfaces').strip().splitlines() ssid = Shell.cm_grep(r, ' SSID')[0].split(':')[1].strip() - except: - ssid = None - except: # noqa - pass + except subprocess.CalledProcessError as e: + if "The Wireless AutoConfig Service (wlansvc) is not running" in str(e.output): + print("Machine is not configured for wifi") + except: + command = "netsh wlan show profiles" + r = Shell.run(command) # .splitlines() + r = Shell.cm_grep(r, "User Profile") + r = [line.split(":")[1].strip() for line in r] + from cloudmesh.common.prettytable import PrettyTable + x = PrettyTable(["SSIDs"]) + for item in r: + x.add_row([item]) + x.align = "l" + x.align["SSID"] = "l" + looping = True + while looping: + print(x) + ssid = input('Enter ssid from list:\n') + if ssid not in r: + if not yn_choice(f'The entered SSID is not in the list. Are you sure you want to ' + f'use {ssid}? (type Y and press Enter to use {ssid}) '): + Console.ok('Showing the list of SSIDs again...\n') + else: + looping = False + else: + looping = False return ssid