sdwire 0.3.0__tar.gz → 0.3.1__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.
- {sdwire-0.3.0 → sdwire-0.3.1}/PKG-INFO +1 -1
- {sdwire-0.3.0 → sdwire-0.3.1}/pyproject.toml +1 -1
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/device/sdwire.py +14 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/utils.py +47 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/main.py +14 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/LICENSE +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/README.md +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/__init__.py +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/__init__.py +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/block_device_utils.py +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/detect.py +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/device/sdwirec.py +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/backend/device/usb_device.py +0 -0
- {sdwire-0.3.0 → sdwire-0.3.1}/sdwire/constants.py +0 -0
|
@@ -17,6 +17,20 @@ class SDWire(USBDevice):
|
|
|
17
17
|
self.generation = generation
|
|
18
18
|
self._update_block_device()
|
|
19
19
|
|
|
20
|
+
def query_device_state(self):
|
|
21
|
+
if not self.usb_device:
|
|
22
|
+
log.error("USB device not available")
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
state = self.usb_device.is_kernel_driver_active(0)
|
|
27
|
+
return state
|
|
28
|
+
except Exception as e:
|
|
29
|
+
log.debug(
|
|
30
|
+
"not able to query device state. err: %s",
|
|
31
|
+
e,
|
|
32
|
+
)
|
|
33
|
+
|
|
20
34
|
def switch_ts(self) -> None:
|
|
21
35
|
if not self.usb_device:
|
|
22
36
|
log.error("USB device not available")
|
|
@@ -82,3 +82,50 @@ def handle_switch_command(ctx, serial):
|
|
|
82
82
|
raise click.UsageError(
|
|
83
83
|
f"There is no such sdwire device connected with serial={serial}"
|
|
84
84
|
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def handle_state_command(ctx, serial):
|
|
88
|
+
"""Handle querying device state.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
ctx: Click context containing device information
|
|
92
|
+
serial: Serial number of the device to query
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
devices = detect.get_sdwire_devices()
|
|
96
|
+
|
|
97
|
+
if serial is None:
|
|
98
|
+
# check the devices
|
|
99
|
+
if len(devices) == 0:
|
|
100
|
+
raise click.UsageError("There is no sdwire device connected!")
|
|
101
|
+
if len(devices) > 1:
|
|
102
|
+
raise click.UsageError(
|
|
103
|
+
"There is more then 1 sdwire device connected, please use --serial|-s to specify!"
|
|
104
|
+
)
|
|
105
|
+
log.info("1 sdwire/sdwirec device detected")
|
|
106
|
+
ctx.obj["device"] = devices[0]
|
|
107
|
+
else:
|
|
108
|
+
for device in devices:
|
|
109
|
+
if device.serial_string == serial:
|
|
110
|
+
ctx.obj["device"] = device
|
|
111
|
+
break
|
|
112
|
+
else:
|
|
113
|
+
raise click.UsageError(
|
|
114
|
+
f"There is no such sdwire device connected with serial={serial}"
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
device = ctx.obj["device"]
|
|
118
|
+
if isinstance(device, (SDWireC)):
|
|
119
|
+
log.info(
|
|
120
|
+
"SDWireC or legacy sdwire devices don't have state functionality"
|
|
121
|
+
)
|
|
122
|
+
print("SDWireC don't have state functionality implemented")
|
|
123
|
+
sys.exit(1)
|
|
124
|
+
try:
|
|
125
|
+
state = device.query_device_state()
|
|
126
|
+
print(f"{'Serial':<30}\tState")
|
|
127
|
+
print(f"{device.serial_string:<30}\t{'Host' if state else 'Target'}")
|
|
128
|
+
except Exception as e:
|
|
129
|
+
log.error(f"Failed to get device state: {e}")
|
|
130
|
+
print(f"Error: Failed to get device state: {e}")
|
|
131
|
+
sys.exit(1)
|
|
@@ -29,6 +29,20 @@ def list() -> None:
|
|
|
29
29
|
print(sdwire)
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
@main.command()
|
|
33
|
+
@click.pass_context
|
|
34
|
+
@click.option(
|
|
35
|
+
"-s",
|
|
36
|
+
"--serial",
|
|
37
|
+
required=False,
|
|
38
|
+
help="Serial number of the sdwire device, if there is only one sdwire connected then it will be used by default",
|
|
39
|
+
)
|
|
40
|
+
def state(ctx: click.Context, serial=None):
|
|
41
|
+
"""Query and display the state of all connected SDWire devices."""
|
|
42
|
+
ctx.ensure_object(dict)
|
|
43
|
+
utils.handle_state_command(ctx, serial)
|
|
44
|
+
|
|
45
|
+
|
|
32
46
|
@main.group()
|
|
33
47
|
@click.pass_context
|
|
34
48
|
@click.option(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|