Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdwire/backend/block_device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ def _is_block_device_match_linux(
# Typical path: /sys/devices/pci.../usb1/1-2/1-2.3/...
# We look for patterns like "1-2.3" which indicate USB bus 1,
# port path 2.3
usb_match = re.search(r"/usb(\d+)/(\d+)-([0-9.]+)/", device_path)
usb_match = re.search(
r"/usb(\d+)/.*/(\d+)-([0-9.]+):.*/host", device_path
)
if usb_match:
bus_num = int(usb_match.group(1))
port_path = usb_match.group(3)
Expand Down
7 changes: 6 additions & 1 deletion sdwire/backend/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ def get_sdwire_devices() -> List[Union[SDWire, SDWireC]]:
bus = getattr(device, "bus", None)
address = getattr(device, "address", None)
serial_num = getattr(device, "serial_number", None) or "unknown"
serial = f"{serial_num}:{bus}.{address}"
port_numbers = getattr(device, "port_numbers", None)
serial = (
f"{serial_num}.{'.'.join(map(str, port_numbers))}"
if port_numbers
else f"{serial_num}:{bus}.{address}"
)
except Exception as e:
log.debug(
"not able to get usb product, serial_number and manufacturer information, err: %s",
Expand Down
2 changes: 1 addition & 1 deletion sdwire/backend/device/sdwire.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def storage_device(self) -> Optional[usb.core.Device]:

def __str__(self) -> str:
block_dev_str = self.block_dev if self.block_dev is not None else "None"
return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]\t\t{block_dev_str}"
return f"{self.serial_string:<30}[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]\t\t{block_dev_str}"

def __repr__(self) -> str:
return self.__str__()
9 changes: 7 additions & 2 deletions sdwire/backend/device/sdwirec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from pyftdi.ftdi import Ftdi
import usb.core
from sdwire.backend.device.usb_device import USBDevice, PortInfo
from sdwire.backend.block_device_utils import map_usb_device_to_block_device, find_sibling_storage_device
from sdwire.backend.block_device_utils import (
map_usb_device_to_block_device,
find_sibling_storage_device,
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -34,7 +37,7 @@ def _update_block_device(self) -> None:

def __str__(self) -> str:
block_dev_str = self.block_dev if self.block_dev is not None else "None"
return f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]\t{block_dev_str}"
return f"{self.serial_string:<30}[{self.product_string}::{self.manufacturer_string}]\t\t{block_dev_str}"

def __repr__(self) -> str:
return self.__str__()
Expand Down Expand Up @@ -66,6 +69,7 @@ def _set_sdwire(self, target: int) -> None:
if not self.usb_device:
log.error("USB device not available")
import sys

print("USB device not available")
sys.exit(1)

Expand All @@ -77,6 +81,7 @@ def _set_sdwire(self, target: int) -> None:
ftdi.close()
except Exception as e:
import sys

log.debug("error while updating ftdi device: %s", e, exc_info=True)
print("couldnt switch sdwire device")
sys.exit(1)
2 changes: 1 addition & 1 deletion sdwire/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main(debug: Optional[bool] = None) -> None:
@main.command()
def list() -> None:
"""List all connected SDWire devices with their block device information."""
print("Serial\t\t\tProduct Info\t\tBlock Dev")
print(f"{'Serial':<30}Product Info\t\tBlock Dev")
for sdwire in detect.get_sdwire_devices():
print(sdwire)

Expand Down
Loading