USB rebind via sudo tee (permission sysfs requiert root)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -124,8 +124,9 @@ def _usb_reset_canon():
|
|||||||
|
|
||||||
|
|
||||||
def _usb_rebind_canon():
|
def _usb_rebind_canon():
|
||||||
"""Unbind/rebind USB Canon — simule un debranchement/rebranchement physique."""
|
"""Unbind/rebind USB Canon — simule un debranchement/rebranchement physique.
|
||||||
import glob
|
Necessite sudoers NOPASSWD pour tee sur /sys/bus/usb/drivers/usb/{un,}bind."""
|
||||||
|
import glob, subprocess, time
|
||||||
try:
|
try:
|
||||||
for f in glob.glob("/sys/bus/usb/devices/*/idVendor"):
|
for f in glob.glob("/sys/bus/usb/devices/*/idVendor"):
|
||||||
if open(f).read().strip() == "04a9":
|
if open(f).read().strip() == "04a9":
|
||||||
@@ -133,12 +134,15 @@ def _usb_rebind_canon():
|
|||||||
__import__("os.path", fromlist=["dirname"]).dirname(f)
|
__import__("os.path", fromlist=["dirname"]).dirname(f)
|
||||||
)
|
)
|
||||||
log.info(f"USB rebind Canon: unbind {dev_id}")
|
log.info(f"USB rebind Canon: unbind {dev_id}")
|
||||||
with open("/sys/bus/usb/drivers/usb/unbind", "w") as fh:
|
subprocess.run(
|
||||||
fh.write(dev_id)
|
["sudo", "tee", "/sys/bus/usb/drivers/usb/unbind"],
|
||||||
import time
|
input=dev_id.encode(), stdout=subprocess.DEVNULL, timeout=5,
|
||||||
|
)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
with open("/sys/bus/usb/drivers/usb/bind", "w") as fh:
|
subprocess.run(
|
||||||
fh.write(dev_id)
|
["sudo", "tee", "/sys/bus/usb/drivers/usb/bind"],
|
||||||
|
input=dev_id.encode(), stdout=subprocess.DEVNULL, timeout=5,
|
||||||
|
)
|
||||||
log.info(f"USB rebind Canon: bind {dev_id}")
|
log.info(f"USB rebind Canon: bind {dev_id}")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user