sdwire 0.2.2__py3-none-any.whl → 0.2.3__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 +18 -9
- sdwire/backend/device/sdwire.py +13 -1
- sdwire/backend/device/sdwirec.py +17 -3
- sdwire/backend/device/usb_device.py +3 -0
- sdwire/main.py +6 -4
- {sdwire-0.2.2.dist-info → sdwire-0.2.3.dist-info}/METADATA +2 -1
- sdwire-0.2.3.dist-info/RECORD +14 -0
- sdwire-0.2.2.dist-info/RECORD +0 -14
- {sdwire-0.2.2.dist-info → sdwire-0.2.3.dist-info}/LICENSE +0 -0
- {sdwire-0.2.2.dist-info → sdwire-0.2.3.dist-info}/WHEEL +0 -0
- {sdwire-0.2.2.dist-info → sdwire-0.2.3.dist-info}/entry_points.txt +0 -0
sdwire/backend/detect.py
CHANGED
@@ -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] =
|
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.
|
67
|
-
vendor = device.
|
68
|
-
|
69
|
-
|
70
|
-
|
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,
|
91
|
+
port_info=PortInfo(device, product, vendor, serial, usb_device),
|
83
92
|
generation=SDWIRE_GENERATION_SDWIRE3,
|
84
93
|
)
|
85
94
|
)
|
sdwire/backend/device/sdwire.py
CHANGED
@@ -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__()
|
sdwire/backend/device/sdwirec.py
CHANGED
@@ -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):
|
sdwire/main.py
CHANGED
@@ -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
|
-
|
10
|
-
|
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
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sdwire
|
3
|
-
Version: 0.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
|
@@ -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=5lvoMjgBSAp9egNP7HwsdVAAEoA92_tw7YqcYtNKiSo,3135
|
4
|
+
sdwire/backend/device/sdwire.py,sha256=LevVtz-RkvuJLAxSVok9ftpfIw-HrFSckltg6ur6TIU,1544
|
5
|
+
sdwire/backend/device/sdwirec.py,sha256=62g8ujRXRj7PEJZPNXAUWiVUOqDcyQ8bwSWvQN2YDDw,1683
|
6
|
+
sdwire/backend/device/usb_device.py,sha256=udfCkHZxnLX4m3FwsVuN04e1S4bA3BWBs7t7Kct_k5I,864
|
7
|
+
sdwire/backend/utils.py,sha256=D_eO9LiMCWM9UPPumXfmqY30UxsHn-PvpURKJYFdmEY,1422
|
8
|
+
sdwire/constants.py,sha256=s5mCx5NlJUM3aBbCPq2y3oOFoPPJ5wA3BR1snyK-cMg,119
|
9
|
+
sdwire/main.py,sha256=HVXRAVj2VKkzIeH0ghW9z3VytdaiaB3dQlXFcIFc3xU,2312
|
10
|
+
sdwire-0.2.3.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
11
|
+
sdwire-0.2.3.dist-info/METADATA,sha256=czV1BkIDgIjRCp4VcbTvAzRbSfh0FHG7sLcFZ2Y7FWE,3198
|
12
|
+
sdwire-0.2.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
13
|
+
sdwire-0.2.3.dist-info/entry_points.txt,sha256=pxy0zJKVcNWXPk5PtNjTLExOBpqFNth37wtdYdYRXCE,43
|
14
|
+
sdwire-0.2.3.dist-info/RECORD,,
|
sdwire-0.2.2.dist-info/RECORD
DELETED
@@ -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
|
File without changes
|
File without changes
|