From 794f9359aa8c5122800b7733a01cc87ea1c4f44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mei=C3=9Fner?= <daniel.meissner@inf.h-brs.de> Date: Tue, 22 Dec 2015 15:51:31 +0100 Subject: [PATCH] hardware: switched methods to static methods --- lib/dependencies.py | 2 +- lib/gui/gui.py | 4 ++-- lib/hardware.py | 16 +++++++++------- tests/lib/test_hardware.py | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/dependencies.py b/lib/dependencies.py index 5bfebaf..e3daa1a 100644 --- a/lib/dependencies.py +++ b/lib/dependencies.py @@ -39,7 +39,7 @@ def check_connected_hardware(): """ Output connected and supported rf hardware. """ - devices = Hardware().get_connected_supported_devices() + devices = Hardware.get_connected_supported_devices() if len(devices) == 0: print(" * no rf hardware connected") else: diff --git a/lib/gui/gui.py b/lib/gui/gui.py index 9a1ecb2..db2bfb5 100644 --- a/lib/gui/gui.py +++ b/lib/gui/gui.py @@ -141,7 +141,7 @@ class SuGui(QtWidgets.QMainWindow): currentText()).group() device_key = '' - for key, value in Hardware().SUPPORTED_HARDWARE.items(): + for key, value in Hardware.SUPPORTED_HARDWARE.items(): if value == device_id: device_key = key @@ -161,7 +161,7 @@ class SuGui(QtWidgets.QMainWindow): QtWidgets.QMessageBox.about(self, "Dumpfile path missing…", \ "Please add dump file path.") return False - elif len(Hardware().get_connected_supported_devices()) == 0: + elif len(Hardware.get_connected_supported_devices()) == 0: QtWidgets.QMessageBox.about(self, "No supported RF hardware "\ "connected…", \ "Please connect RF hardware.") diff --git a/lib/hardware.py b/lib/hardware.py index 1f62bb3..0311e51 100644 --- a/lib/hardware.py +++ b/lib/hardware.py @@ -20,7 +20,8 @@ class Hardware(object): "rtlsdr": "0bda:2838" # Realtek Semiconductor Corp. RTL2838 DVB-T } - def get_usb_devices(self): + @staticmethod + def get_usb_devices(): """ Parse lsusb output and return a list of dictionaries. """ @@ -29,22 +30,23 @@ class Hardware(object): lsusb_output = subprocess.check_output("lsusb", shell=True) for line in lsusb_output.split("\n"): if re.match("^Bus", line): - device = self.parse_lsusb_line(line) + device = Hardware.parse_lsusb_line(line) devices.append(device) else: continue return devices - def get_connected_supported_devices(self): + @staticmethod + def get_connected_supported_devices(): """ Get all connected devices """ - devices = self.get_usb_devices() + devices = Hardware.get_usb_devices() connected_devices = [] for device in devices: - if self.supported_device(self, device): + if Hardware.supported_device(device): connected_devices.append(device) else: continue @@ -67,8 +69,8 @@ class Hardware(object): return device @staticmethod - def supported_device(self, device): + def supported_device(device): """ Check if a given device is supported. """ - return device['id'] in self.SUPPORTED_HARDWARE.values() + return device['id'] in Hardware.SUPPORTED_HARDWARE.values() diff --git a/tests/lib/test_hardware.py b/tests/lib/test_hardware.py index f8fcdb5..b331967 100644 --- a/tests/lib/test_hardware.py +++ b/tests/lib/test_hardware.py @@ -19,9 +19,9 @@ class TestHardware: def test_supported_device(self): not_supported_device = {"id": "ffff:ffff"} supported_device = {"id": "0bda:2838"} - assert Hardware.supported_device(Hardware(), not_supported_device) \ + assert Hardware.supported_device(not_supported_device) \ == False - assert Hardware.supported_device(Hardware(), supported_device) \ + assert Hardware.supported_device(supported_device) \ == True def test_supported_hardware(self): -- GitLab