sdwire 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sdwire
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: CLI application to interact with Badgerd SDWire devices
5
5
  License: GPL-3
6
6
  Author: Talha Can Havadar
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.12
12
12
  Requires-Dist: adafruit-board-toolkit (>=1.1.1,<2.0.0)
13
13
  Requires-Dist: click (>=8.1.7,<9.0.0)
14
14
  Requires-Dist: pyftdi (>=0.55.4,<0.56.0)
15
+ Requires-Dist: pyudev (>=0.24.3,<0.25.0)
15
16
  Requires-Dist: pyusb (>=1.2.1,<2.0.0)
16
17
  Requires-Dist: semver (>=3.0.2,<4.0.0)
17
18
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "sdwire"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "CLI application to interact with Badgerd SDWire devices"
5
5
  authors = ["Talha Can Havadar <havadartalha@gmail.com>"]
6
6
  license = "GPL-3"
@@ -14,6 +14,7 @@ adafruit-board-toolkit = "^1.1.1"
14
14
  semver = "^3.0.2"
15
15
  pyusb = "^1.2.1"
16
16
  pyftdi = "^0.55.4"
17
+ pyudev = "^0.24.3"
17
18
 
18
19
 
19
20
  [tool.poetry.group.dev.dependencies]
@@ -8,6 +8,7 @@ from .device.sdwire import SDWire, SDWIRE_GENERATION_SDWIRE3
8
8
  from .device.sdwirec import SDWireC
9
9
  from .device.usb_device import PortInfo
10
10
 
11
+ import pyudev
11
12
  import usb.core
12
13
  import usb.util
13
14
  from usb.core import Device
@@ -52,7 +53,11 @@ def get_sdwire_devices() -> List[SDWire]:
52
53
  # Badgerd SDWireC
53
54
  # VID = 0x04e8 PID = 0x6001
54
55
  result = []
55
- devices: List[Device] = usb.core.find(find_all=True)
56
+ devices: List[Device] = pyudev.Context().list_devices(
57
+ subsystem="usb",
58
+ ID_VENDOR_ID=f"{constants.SDWIRE3_VID:04x}",
59
+ ID_MODEL_ID=f"{constants.SDWIRE3_PID:04x}",
60
+ )
56
61
  if not devices:
57
62
  log.info("no usb devices found while searching for SDWire..")
58
63
  return []
@@ -62,14 +67,15 @@ def get_sdwire_devices() -> List[SDWire]:
62
67
  product = None
63
68
  serial = None
64
69
  manufacturer = None
70
+ bus = None
71
+ address = None
65
72
  try:
66
- product = device.idProduct
67
- vendor = device.idVendor
68
- serial = (
69
- usb.util.get_string(device, device.iSerialNumber, None)
70
- + f"{device.bus}{device.port_number}"
71
- )
72
- manufacturer = device.manufacturer
73
+ product = int(f"0x{device.get("ID_MODEL_ID")}", 16)
74
+ vendor = int(f"0x{device.get("ID_VENDOR_ID")}", 16)
75
+ bus = int(device.get("BUSNUM"))
76
+ address = int(device.get("DEVNUM"))
77
+ serial = f"{device.get("ID_USB_SERIAL_SHORT")}:{bus}.{address}"
78
+ manufacturer = ""
73
79
  except Exception as e:
74
80
  log.debug(
75
81
  "not able to get usb product, serial_number and manufacturer information, err: %s",
@@ -77,9 +83,12 @@ def get_sdwire_devices() -> List[SDWire]:
77
83
  )
78
84
 
79
85
  if product == constants.SDWIRE3_PID and vendor == constants.SDWIRE3_VID:
86
+ usb_device: List[Device] = usb.core.find(
87
+ idVendor=vendor, idProduct=product, bus=bus, address=address
88
+ )
80
89
  result.append(
81
90
  SDWire(
82
- port_info=PortInfo(device, product, vendor, serial, device),
91
+ port_info=PortInfo(device, product, vendor, serial, usb_device),
83
92
  generation=SDWIRE_GENERATION_SDWIRE3,
84
93
  )
85
94
  )
@@ -8,10 +8,18 @@ SDWIRE_GENERATION_SDWIRE3 = 2
8
8
 
9
9
 
10
10
  class SDWire(USBDevice):
11
+ __block_dev = None
11
12
 
12
13
  def __init__(self, port_info: PortInfo, generation: int):
13
14
  super().__init__(port_info)
14
15
  self.generation = generation
16
+ for sibling in self.dev_string.parent.children:
17
+ if (
18
+ self.dev_string.device_path != sibling.device_path
19
+ and sibling.device_type == "disk"
20
+ ):
21
+ self.__block_dev = f"/dev/{sibling.device_path.split("/")[-1]}"
22
+ break
15
23
 
16
24
  def switch_ts(self):
17
25
  try:
@@ -33,8 +41,12 @@ class SDWire(USBDevice):
33
41
  e,
34
42
  )
35
43
 
44
+ @property
45
+ def block_dev(self):
46
+ return self.__block_dev
47
+
36
48
  def __str__(self):
37
- return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]"
49
+ return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]\t\t{self.block_dev}"
38
50
 
39
51
  def __repr__(self):
40
52
  return self.__str__()
@@ -7,18 +7,32 @@ log = logging.getLogger(__name__)
7
7
 
8
8
 
9
9
  class SDWireC(USBDevice):
10
+ __block_dev = None
10
11
 
11
12
  def __init__(self, port_info: PortInfo):
12
13
  super().__init__(port_info)
14
+ for d in self._pyudev_context.list_devices(ID_MODEL="sd-wire"):
15
+ d_serial = d.get("ID_USB_SERIAL_SHORT", None)
16
+ if d_serial is not None and d_serial == self.serial_string:
17
+ for sibling in d.parent.children:
18
+ if (
19
+ d.device_path != sibling.device_path
20
+ and sibling.device_type == "disk"
21
+ ):
22
+ self.__block_dev = f"/dev/{sibling.device_path.split("/")[-1]}"
23
+ break
24
+ break
13
25
 
14
26
  def __str__(self):
15
- return (
16
- f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]"
17
- )
27
+ return f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]\t{self.block_dev}"
18
28
 
19
29
  def __repr__(self):
20
30
  return self.__str__()
21
31
 
32
+ @property
33
+ def block_dev(self):
34
+ return self.__block_dev
35
+
22
36
  def switch_ts(self):
23
37
  self._set_sdwire(1)
24
38
 
@@ -1,4 +1,5 @@
1
1
  from collections import namedtuple
2
+ import pyudev
2
3
  from serial.tools.list_ports_common import ListPortInfo
3
4
 
4
5
  PortInfo = namedtuple(
@@ -8,9 +9,11 @@ PortInfo = namedtuple(
8
9
 
9
10
  class USBDevice:
10
11
  __port_info = None
12
+ _pyudev_context = None
11
13
 
12
14
  def __init__(self, port_info: PortInfo):
13
15
  self.__port_info = port_info
16
+ self._pyudev_context = pyudev.Context()
14
17
 
15
18
  @property
16
19
  def usb_device(self):
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env python
2
+ import logging
2
3
  import click
3
4
  from .backend import utils
4
5
  from .backend import detect
@@ -6,14 +7,15 @@ from .backend.device.sdwire import SDWire
6
7
 
7
8
 
8
9
  @click.group()
9
- def main():
10
- pass
10
+ @click.option("--debug", required=False, is_flag=True, help="Enable debug output")
11
+ def main(debug=None):
12
+ if debug:
13
+ logging.basicConfig(level=logging.DEBUG)
11
14
 
12
15
 
13
16
  @main.command()
14
17
  def list():
15
-
16
- print(f"Serial\t\t\tProduct Info")
18
+ print(f"Serial\t\t\tProduct Info\t\tBlock Dev")
17
19
  for sdwire in detect.get_sdwire_devices():
18
20
  print(sdwire)
19
21
 
File without changes
File without changes
File without changes
File without changes
File without changes