aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Goger <klaus.goger@theobroma-systems.com>2017-08-14 08:37:11 +0200
committerKlaus Goger <klaus.goger@theobroma-systems.com>2017-08-14 08:42:44 +0200
commit9cb6ca221b9b3273ddc5d72f97a7f69cd80f8e9a (patch)
tree81969d350cba744c0ebfae39cc36c23b64318711
parentc9e495f6ffbf213f50b862121ce7775c30ea1054 (diff)
usb-control: print notice if run into langid error
listing boards can run into a permission problem. Traceback (most recent call last): File "./haikou.py", line 49, in <module> product=PRODUCT_STRING, find_all=True)) File "/usr/lib/python2.7/dist-packages/usb/core.py", line 1249, in device_iter if _interop._all(tests) and (custom_match is None or custom_match(d)): File "/usr/lib/python2.7/dist-packages/usb/core.py", line 1248, in <genexpr> tests = (val == getattr(d, key) for key, val in kwargs.items()) File "/usr/lib/python2.7/dist-packages/usb/core.py", line 841, in product self._product = util.get_string(self, self.iProduct) File "/usr/lib/python2.7/dist-packages/usb/util.py", line 314, in get_string raise ValueError("The device has no langid") ValueError: The device has no langid catch the langid error and print a message that this could be a permission problem. also link to the pyusb ticket https://github.com/walac/pyusb/issues/139
-rwxr-xr-xusb-control/haikou.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/usb-control/haikou.py b/usb-control/haikou.py
index eb49eb4..15beb76 100755
--- a/usb-control/haikou.py
+++ b/usb-control/haikou.py
@@ -51,8 +51,15 @@ if not args.list and not args.power and not args.bios_disable \
sys.exit()
if args.list:
- dev = list(usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, \
- product=PRODUCT_STRING, find_all=True))
+ try:
+ dev = list(usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, \
+ product=PRODUCT_STRING, find_all=True))
+
+ except ValueError, e:
+ if 'langid' in e.message:
+ raise usb.core.USBError(e.message + "\n" +
+ "This may be a permission issue. See: \n"+
+ "https://github.com/walac/pyusb/issues/139")
print "Found %d Baseboard%s:" % (len(dev),"s"[len(dev)==1:])
for idx,cfg in enumerate(dev):
print "%d: %s" % (idx, cfg.serial_number)