diff --git a/docs/source/upcoming_release_notes/8-ref_sdfconfig.rst b/docs/source/upcoming_release_notes/8-ref_sdfconfig.rst index 815dbe9..53a9036 100644 --- a/docs/source/upcoming_release_notes/8-ref_sdfconfig.rst +++ b/docs/source/upcoming_release_notes/8-ref_sdfconfig.rst @@ -25,4 +25,3 @@ Maintenance Contributors ------------ - zllentz - diff --git a/docs/source/upcoming_release_notes/9-vlan_index_error.rst b/docs/source/upcoming_release_notes/9-vlan_index_error.rst new file mode 100644 index 0000000..0828c31 --- /dev/null +++ b/docs/source/upcoming_release_notes/9-vlan_index_error.rst @@ -0,0 +1,23 @@ +9 vlan_index_error +################# + +API Breaks +---------- +- N/A + +Features +-------- +- N/A + +Bugfixes +-------- +- Fix an issue where if there are VLANs that don't have hyphens (`-`) in their name, + the GUI crashes. + +Maintenance +----------- +- N/A + +Contributors +------------ +- zllentz diff --git a/switchtool/sdfconfig.py b/switchtool/sdfconfig.py index ff4c28d..a70ccea 100644 --- a/switchtool/sdfconfig.py +++ b/switchtool/sdfconfig.py @@ -10,15 +10,15 @@ """ import functools -import subprocess import json +import subprocess @functools.lru_cache(maxsize=1000) def get_host_for_mac(mac_addr: str) -> str: """ Returns the hostname associated with a mac_addr - + Returns an empty string if the mac as not found. May raise if sdfconfig is not configured for the user. diff --git a/switchtool/ui/widgets/switch.py b/switchtool/ui/widgets/switch.py index f4cfe6d..6117e63 100644 --- a/switchtool/ui/widgets/switch.py +++ b/switchtool/ui/widgets/switch.py @@ -4,10 +4,10 @@ from PyQt5.QtCore import QSettings, QTimer, pyqtSignal, pyqtSlot from ...EpicsQT.qlogdisplay import QLogDisplay +from ...sdfconfig import get_subnet_for_host from ...switch.switch import Switch from .. import dialogs from .vlan import VlanWidget -from ...sdfconfig import get_subnet_for_host class SwitchWidget(QtWidgets.QWidget): @@ -17,11 +17,20 @@ class SwitchWidget(QtWidgets.QWidget): updated = pyqtSignal() update_port = pyqtSignal(str, str, str, str, str, str) - def __init__(self, switch, user="admin", pw=None, switch_type=None, timeout=1.0, parent=None): + def __init__( + self, switch, user="admin", pw=None, switch_type=None, timeout=1.0, parent=None + ): super().__init__(parent=parent) self.resize(660, 700) - self._switch = PyQtSwitch(switch, user=user, pw=pw, enablepw=None, switch_type=switch_type, parent=self) + self._switch = PyQtSwitch( + switch, + user=user, + pw=pw, + enablepw=None, + switch_type=switch_type, + parent=self, + ) self.switch_name = switch.split(".")[0] self.refresh_timeout = timeout * 3600000 # Now ms! @@ -110,7 +119,6 @@ def __init__(self, switch, user="admin", pw=None, switch_type=None, timeout=1.0, self.repaint() QTimer.singleShot(100, self.initial_update) - def initial_update(self): self.updated.connect(self.refresh) self.update_port.connect(self.refresh_port) @@ -326,12 +334,21 @@ def refresh(self): sub = "PCDSN-CDS-LAS" if sub in allsubs.keys(): vl.append(allsubs[sub]) + cds_vl = [] + fez_vl = [] for v in vlist: - if v not in vl and allvlan[v].split("-")[1] == "CDS": - vl.append(v) - for v in vlist: - if v not in vl and allvlan[v].split("-")[1] == "FEZ": - vl.append(v) + if v in vl: + continue + try: + vlan_type = allvlan[v].split("-")[1] + except IndexError: + vlan_type = "NO_TYPE" + if vlan_type == "CDS": + cds_vl.append(v) + elif vlan_type == "FEZ": + fez_vl.append(v) + vl.extend(cds_vl) + vl.extend(fez_vl) self._vlanList = vl # Now, go through the prefered vlan list order. Add the @@ -421,14 +438,24 @@ def write_memory(self): class PyQtSwitch(Switch): - def __init__(self, switchname, user="admin", pw=None, enablepw=None, switch_type=None, parent=None): + def __init__( + self, + switchname, + user="admin", + pw=None, + enablepw=None, + switch_type=None, + parent=None, + ): self.parent = parent if pw is None: - pw = dialogs.passwddialog.getPassword( - "Password for {:}: ".format(user) - ) + pw = dialogs.passwddialog.getPassword("Password for {:}: ".format(user)) super().__init__( - switchname, user=user, pw=pw, enablepw=enablepw, switch_type=switch_type, + switchname, + user=user, + pw=pw, + enablepw=enablepw, + switch_type=switch_type, ) def update(self):