sdwire 0.2.2__py3-none-any.whl → 0.2.4__py3-none-any.whl

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.
sdwire/backend/detect.py CHANGED
@@ -1,13 +1,12 @@
1
1
  import logging
2
2
  from typing import List
3
- from adafruit_board_toolkit import circuitpython_serial as cpserial
4
- from serial.tools.list_ports_common import ListPortInfo
5
3
 
6
4
  from sdwire import constants
7
5
  from .device.sdwire import SDWire, SDWIRE_GENERATION_SDWIRE3
8
6
  from .device.sdwirec import SDWireC
9
7
  from .device.usb_device import PortInfo
10
8
 
9
+ import pyudev
11
10
  import usb.core
12
11
  import usb.util
13
12
  from usb.core import Device
@@ -46,30 +45,31 @@ def get_sdwirec_devices() -> List[SDWireC]:
46
45
 
47
46
 
48
47
  def get_sdwire_devices() -> List[SDWire]:
49
-
50
48
  # Badgerd SDWire3
51
49
  # VID = 0bda PID = 0316
52
50
  # Badgerd SDWireC
53
51
  # VID = 0x04e8 PID = 0x6001
54
52
  result = []
55
- devices: List[Device] = usb.core.find(find_all=True)
53
+ devices: List[Device] = pyudev.Context().list_devices(
54
+ subsystem="usb",
55
+ ID_VENDOR_ID=f"{constants.SDWIRE3_VID:04x}",
56
+ ID_MODEL_ID=f"{constants.SDWIRE3_PID:04x}",
57
+ )
56
58
  if not devices:
57
59
  log.info("no usb devices found while searching for SDWire..")
58
60
  return []
59
61
 
60
- device_list = []
61
62
  for device in devices:
62
63
  product = None
63
64
  serial = None
64
- manufacturer = None
65
+ bus = None
66
+ address = None
65
67
  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
68
+ product = int(f"0x{device.get('ID_MODEL_ID')}", 16)
69
+ vendor = int(f"0x{device.get('ID_VENDOR_ID')}", 16)
70
+ bus = int(device.get("BUSNUM"))
71
+ address = int(device.get("DEVNUM"))
72
+ serial = f"{device.get('ID_USB_SERIAL_SHORT')}:{bus}.{address}"
73
73
  except Exception as e:
74
74
  log.debug(
75
75
  "not able to get usb product, serial_number and manufacturer information, err: %s",
@@ -77,9 +77,12 @@ def get_sdwire_devices() -> List[SDWire]:
77
77
  )
78
78
 
79
79
  if product == constants.SDWIRE3_PID and vendor == constants.SDWIRE3_VID:
80
+ usb_device: List[Device] = usb.core.find(
81
+ idVendor=vendor, idProduct=product, bus=bus, address=address
82
+ )
80
83
  result.append(
81
84
  SDWire(
82
- port_info=PortInfo(device, product, vendor, serial, device),
85
+ port_info=PortInfo(device, product, vendor, serial, usb_device),
83
86
  generation=SDWIRE_GENERATION_SDWIRE3,
84
87
  )
85
88
  )
@@ -1,5 +1,4 @@
1
1
  import logging
2
- from serial import Serial
3
2
  from .usb_device import USBDevice, PortInfo
4
3
 
5
4
  log = logging.getLogger(__name__)
@@ -8,10 +7,18 @@ SDWIRE_GENERATION_SDWIRE3 = 2
8
7
 
9
8
 
10
9
  class SDWire(USBDevice):
10
+ __block_dev = None
11
11
 
12
12
  def __init__(self, port_info: PortInfo, generation: int):
13
13
  super().__init__(port_info)
14
14
  self.generation = generation
15
+ for sibling in self.dev_string.parent.children:
16
+ if (
17
+ self.dev_string.device_path != sibling.device_path
18
+ and sibling.device_type == "disk"
19
+ ):
20
+ self.__block_dev = f"/dev/{sibling.device_path.split('/')[-1]}"
21
+ break
15
22
 
16
23
  def switch_ts(self):
17
24
  try:
@@ -33,8 +40,12 @@ class SDWire(USBDevice):
33
40
  e,
34
41
  )
35
42
 
43
+ @property
44
+ def block_dev(self):
45
+ return self.__block_dev
46
+
36
47
  def __str__(self):
37
- return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]"
48
+ return f"{self.serial_string}\t[{int(self.manufacturer_string):04x}::{int(self.product_string):04x}]\t\t{self.block_dev}"
38
49
 
39
50
  def __repr__(self):
40
51
  return self.__str__()
@@ -1,24 +1,37 @@
1
1
  import logging
2
2
  from pyftdi.ftdi import Ftdi
3
- from serial import Serial
4
3
  from .usb_device import USBDevice, PortInfo
5
4
 
6
5
  log = logging.getLogger(__name__)
7
6
 
8
7
 
9
8
  class SDWireC(USBDevice):
9
+ __block_dev = None
10
10
 
11
11
  def __init__(self, port_info: PortInfo):
12
12
  super().__init__(port_info)
13
+ for d in self._pyudev_context.list_devices(ID_MODEL="sd-wire"):
14
+ d_serial = d.get("ID_USB_SERIAL_SHORT", None)
15
+ if d_serial is not None and d_serial == self.serial_string:
16
+ for sibling in d.parent.children:
17
+ if (
18
+ d.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
23
+ break
13
24
 
14
25
  def __str__(self):
15
- return (
16
- f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]"
17
- )
26
+ return f"{self.serial_string}\t[{self.product_string}::{self.manufacturer_string}]\t{self.block_dev}"
18
27
 
19
28
  def __repr__(self):
20
29
  return self.__str__()
21
30
 
31
+ @property
32
+ def block_dev(self):
33
+ return self.__block_dev
34
+
22
35
  def switch_ts(self):
23
36
  self._set_sdwire(1)
24
37
 
@@ -1,5 +1,5 @@
1
1
  from collections import namedtuple
2
- from serial.tools.list_ports_common import ListPortInfo
2
+ import pyudev
3
3
 
4
4
  PortInfo = namedtuple(
5
5
  "PortInfo", ("device", "product", "manufacturer", "serial", "usb_device")
@@ -8,9 +8,11 @@ PortInfo = namedtuple(
8
8
 
9
9
  class USBDevice:
10
10
  __port_info = None
11
+ _pyudev_context = None
11
12
 
12
13
  def __init__(self, port_info: PortInfo):
13
14
  self.__port_info = port_info
15
+ self._pyudev_context = pyudev.Context()
14
16
 
15
17
  @property
16
18
  def usb_device(self):
sdwire/backend/utils.py CHANGED
@@ -20,9 +20,11 @@ def handle_switch_target_command(ctx):
20
20
 
21
21
  def handle_switch_off_command(ctx):
22
22
  device = ctx.obj["device"]
23
- if isinstance(device, SDWireC):
24
- log.info("SDWireC or legacy sdwire devices dont have off functionality")
25
- print("SDWireC dont have off functionality")
23
+ if isinstance(device, SDWireC) or isinstance(device, SDWire):
24
+ log.info(
25
+ "SDWire3, SDWireC or legacy sdwire devices dont have off functionality"
26
+ )
27
+ print("SDWireC and SDWire3 dont have off functionality implemented")
26
28
  sys.exit(1)
27
29
 
28
30
 
sdwire/main.py CHANGED
@@ -1,19 +1,20 @@
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
5
- from .backend.device.sdwire import SDWire
6
6
 
7
7
 
8
8
  @click.group()
9
- def main():
10
- pass
9
+ @click.option("--debug", required=False, is_flag=True, help="Enable debug output")
10
+ def main(debug=None):
11
+ if debug:
12
+ logging.basicConfig(level=logging.DEBUG)
11
13
 
12
14
 
13
15
  @main.command()
14
16
  def list():
15
-
16
- print(f"Serial\t\t\tProduct Info")
17
+ print("Serial\t\t\tProduct Info\t\tBlock Dev")
17
18
  for sdwire in detect.get_sdwire_devices():
18
19
  print(sdwire)
19
20
 
@@ -88,10 +89,5 @@ def off(ctx: click.Context):
88
89
  utils.handle_switch_off_command(ctx)
89
90
 
90
91
 
91
- # investigate further to use click in circuitpython
92
- # def invoke():
93
- # main.main("switch ts".split(), "sdwire", "_SDWIRE_COMPLETE")
94
-
95
-
96
92
  if __name__ == "__main__":
97
93
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sdwire
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: CLI application to interact with Badgerd SDWire devices
5
5
  License: GPL-3
6
6
  Author: Talha Can Havadar
@@ -9,11 +9,10 @@ Requires-Python: >=3.12,<4.0
9
9
  Classifier: License :: Other/Proprietary License
10
10
  Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.12
12
- Requires-Dist: adafruit-board-toolkit (>=1.1.1,<2.0.0)
13
12
  Requires-Dist: click (>=8.1.7,<9.0.0)
14
- Requires-Dist: pyftdi (>=0.55.4,<0.56.0)
13
+ Requires-Dist: pyftdi (>=0.56.0,<0.57.0)
14
+ Requires-Dist: pyudev (>=0.24.3,<0.25.0)
15
15
  Requires-Dist: pyusb (>=1.2.1,<2.0.0)
16
- Requires-Dist: semver (>=3.0.2,<4.0.0)
17
16
  Description-Content-Type: text/markdown
18
17
 
19
18
  # CLI for Badgerd SDWire Devices
@@ -0,0 +1,14 @@
1
+ sdwire/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ sdwire/backend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ sdwire/backend/detect.py,sha256=jiQ2JS9sMGUuymwyUO4FaGzIkXK3J7Ci45V1X8c94b4,2931
4
+ sdwire/backend/device/sdwire.py,sha256=5Glk4M20sY7EJA5XDewT1F5F1-AUW1fG7mI9_wrABoM,1518
5
+ sdwire/backend/device/sdwirec.py,sha256=imkj2ObrgowiM7DP9TnVbCES-8bju0T69Qzdw5OURgE,1657
6
+ sdwire/backend/device/usb_device.py,sha256=5sdyOyPikIpFydKywzDkvvgLHFdMcsBC8tKosHRhfvQ,808
7
+ sdwire/backend/utils.py,sha256=kMEyBbRO91REgvgICuBONGiImO6jTr6EpqkZaxQH4aU,1507
8
+ sdwire/constants.py,sha256=s5mCx5NlJUM3aBbCPq2y3oOFoPPJ5wA3BR1snyK-cMg,119
9
+ sdwire/main.py,sha256=G1WaVd4kBR3bTfbmHekjx1yObiz4f1NLGqznFepd2NY,2132
10
+ sdwire-0.2.4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
11
+ sdwire-0.2.4.dist-info/METADATA,sha256=ZtSg0QMJGsQF52Aa_GlRkwbjn6mxK0EAiv15r_ITW-E,3104
12
+ sdwire-0.2.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ sdwire-0.2.4.dist-info/entry_points.txt,sha256=pxy0zJKVcNWXPk5PtNjTLExOBpqFNth37wtdYdYRXCE,43
14
+ sdwire-0.2.4.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- sdwire/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- sdwire/backend/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- sdwire/backend/detect.py,sha256=Ze_nmepeuMIiXRmiDBdbAkH4qmnyNd4pylurlWFcSZM,2752
4
- sdwire/backend/device/sdwire.py,sha256=8chgdYm5D83GqJy-v1iHomE_ZTXk6-N9o0Yyw-X9yIY,1122
5
- sdwire/backend/device/sdwirec.py,sha256=BZXvCq3bmJzzA5seCVOYIdmr6FBeAreE95_n-2kiuMQ,1035
6
- sdwire/backend/device/usb_device.py,sha256=6Mt24B22yTD4RdY24LgnRaVtbX60EPE2SAK-pN0ZESc,775
7
- sdwire/backend/utils.py,sha256=D_eO9LiMCWM9UPPumXfmqY30UxsHn-PvpURKJYFdmEY,1422
8
- sdwire/constants.py,sha256=s5mCx5NlJUM3aBbCPq2y3oOFoPPJ5wA3BR1snyK-cMg,119
9
- sdwire/main.py,sha256=ndbRoCkSckItLDH0q3zacC0mqfa0ZL-TJGDkIGJKrBU,2138
10
- sdwire-0.2.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
11
- sdwire-0.2.2.dist-info/METADATA,sha256=POgYay_dxKiDXKHo984s_Xi9u4DdRsOaJK9Igk0PzOo,3157
12
- sdwire-0.2.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
- sdwire-0.2.2.dist-info/entry_points.txt,sha256=pxy0zJKVcNWXPk5PtNjTLExOBpqFNth37wtdYdYRXCE,43
14
- sdwire-0.2.2.dist-info/RECORD,,
File without changes