From bac1e76f8333bed8cf4b0928c7ce91e677f1aed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Tue, 30 Dec 2025 13:09:57 +0100 Subject: [PATCH] cli_pretty: Convert show usb to the new SimpleTable --- src/statd/python/cli_pretty/cli_pretty.py | 37 ++++++----------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/statd/python/cli_pretty/cli_pretty.py b/src/statd/python/cli_pretty/cli_pretty.py index 324d181e..7405e70c 100755 --- a/src/statd/python/cli_pretty/cli_pretty.py +++ b/src/statd/python/cli_pretty/cli_pretty.py @@ -159,18 +159,6 @@ class PadDhcpServer: exp = 10 -class PadUsbPort: - title = 30 - name = 20 - state = 10 - oper = 10 - - @classmethod - def table_width(cls): - """Total width of USB port table""" - return cls.name + cls.state + cls.oper - - class PadSensor: name = 30 value = 20 @@ -841,12 +829,6 @@ class USBport: self.state = get_json_data('', self.data, 'state', 'admin-state') self.oper = get_json_data('', self.data, 'state', 'oper-state') - def print(self): - row = f"{self.name:<{PadUsbPort.name}}" - row += f"{self.state:<{PadUsbPort.state}}" - row += f"{self.oper:<{PadUsbPort.oper}}" - print(row) - class Sensor: def __init__(self, data): @@ -2084,8 +2066,7 @@ def show_hardware(json): sensors = [c for c in components if c.get("class") == "iana-hardware:sensor"] wifi_radios = [c for c in components if c.get("class") == "infix-hardware:wifi"] - # Determine overall width (use the wider of the two sections) - width = max(PadUsbPort.table_width(), PadSensor.table_width(), 100) + width = max(PadSensor.table_width(), 100) # Display full-width inverted heading print(Decore.invert(f"{'HARDWARE COMPONENTS':<{width}}")) @@ -2157,16 +2138,18 @@ def show_hardware(json): if usb_ports: Decore.title("USB Ports", width) - hdr = (f"{'NAME':<{PadUsbPort.name}}" - f"{'STATE':<{PadUsbPort.state}}" - f"{'OPER':<{PadUsbPort.oper}}") - # Pad header to full width - hdr = f"{hdr:<{width}}" - print(Decore.invert(hdr)) + + usb_table = SimpleTable([ + Column('NAME'), + Column('STATE'), + Column('OPER') + ]) for component in usb_ports: port = USBport(component) - port.print() + usb_table.row(port.name, port.state, port.oper) + + usb_table.print() if sensors: Decore.title("Sensors", width)