Skip to content
Draft
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
10 changes: 9 additions & 1 deletion sdwire/backend/device/sdwire.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
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
from sdwire.constants import (
PRINT_SERIAL_SECTION_WIDTH,
PRINT_PRODUCT_INFO_SECTION_WIDTH,
PRINT_BLOCK_DEV_SECTION_WIDTH,
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,7 +84,10 @@ 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:<30}[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]\t\t{block_dev_str}"
product_info_section = (
f"[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]"
)
return f"{self.serial_string:<{PRINT_SERIAL_SECTION_WIDTH}}{product_info_section:<{PRINT_PRODUCT_INFO_SECTION_WIDTH}}{block_dev_str:<{PRINT_BLOCK_DEV_SECTION_WIDTH}}"

def __repr__(self) -> str:
return self.__str__()
11 changes: 11 additions & 0 deletions sdwire/backend/device/sdwire3_pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging
from sdwire.backend.device.usb_device import PortInfo
from sdwire.backend.device.sdwire import SDWire

log = logging.getLogger(__name__)


class SDWire3Pro(SDWire):

def __init__(self, port_info: PortInfo):
super().__init__(port_info, 2)
8 changes: 7 additions & 1 deletion sdwire/backend/device/sdwirec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
map_usb_device_to_block_device,
find_sibling_storage_device,
)
from sdwire.constants import (
PRINT_SERIAL_SECTION_WIDTH,
PRINT_PRODUCT_INFO_SECTION_WIDTH,
PRINT_BLOCK_DEV_SECTION_WIDTH,
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,7 +42,8 @@ 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:<30}[{self.product_string}::{self.manufacturer_string}]\t\t{block_dev_str}"
product_info_section = f"[{self.product_string}::{self.manufacturer_string}]"
return f"{self.serial_string:<{PRINT_SERIAL_SECTION_WIDTH}}{product_info_section:<{PRINT_PRODUCT_INFO_SECTION_WIDTH}}{block_dev_str:<{PRINT_BLOCK_DEV_SECTION_WIDTH}}"

def __repr__(self) -> str:
return self.__str__()
Expand Down
4 changes: 4 additions & 0 deletions sdwire/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
SDWIREC_PRODUCT_STRING = "sd-wire"

USB_MASS_STORAGE_CLASS_ID = 8

PRINT_SERIAL_SECTION_WIDTH = 30
PRINT_PRODUCT_INFO_SECTION_WIDTH = 20
PRINT_BLOCK_DEV_SECTION_WIDTH = 50
9 changes: 8 additions & 1 deletion sdwire/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import click
from sdwire.backend import utils
from sdwire.backend import detect
from sdwire.constants import (
PRINT_SERIAL_SECTION_WIDTH,
PRINT_PRODUCT_INFO_SECTION_WIDTH,
PRINT_BLOCK_DEV_SECTION_WIDTH,
)


@click.group()
Expand All @@ -24,7 +29,9 @@ def main(debug: Optional[bool] = None) -> None:
@main.command()
def list() -> None:
"""List all connected SDWire devices with their block device information."""
print(f"{'Serial':<30}Product Info\t\tBlock Dev")
print(
f"{'Serial':<{PRINT_SERIAL_SECTION_WIDTH}}{'Product Info':<{PRINT_PRODUCT_INFO_SECTION_WIDTH}}{'Block Dev':<{PRINT_BLOCK_DEV_SECTION_WIDTH}}"
)
for sdwire in detect.get_sdwire_devices():
print(sdwire)

Expand Down
Loading