Skip to content
Snippets Groups Projects
Commit 1454eed5 authored by Antoine Prieels's avatar Antoine Prieels
Browse files

[FIX] hw_drivers,hw_escpos: Check pyusb version


The `get_string` method from the `pyusb` package has changed its
signature after version 1.0.0b1 so we used to force the IoT Box to use
this version to avoid an error. The problem is that version 1.0.0b1
has dependencies that raise DeprecationWarings in Raspbian Buster.
We then want to update the version of pyusb that is installed on the
IoT Box in 14.0.

As the Driver might be loaded to old versions of the IoT Box as well
as new ones, we need to check what version of the package is present
on the IoT Box before calling `get_string`.

This check will be removed in 14.0, as people will have to use the
latest version of the IoT Box.

closes odoo/odoo#52374

X-original-commit: e5475ae8
Signed-off-by: default avatarQuentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: default avatarAntoine Prieëls <aprieels@users.noreply.github.com>
parent 8326643a
Branches
Tags
No related merge requests found
......@@ -11,7 +11,7 @@ from pathlib import Path
import subprocess
import time
from threading import Lock
from usb import util
import usb
import urllib3
from queue import Queue, Empty
......@@ -117,8 +117,12 @@ class KeyboardUSBDriver(Driver):
def _set_name(self):
try:
manufacturer = util.get_string(self.dev, 256, self.dev.iManufacturer)
product = util.get_string(self.dev, 256, self.dev.iProduct)
if usb.__version__ == '1.0.0b1':
manufacturer = usb.util.get_string(self.dev, 256, self.dev.iManufacturer)
product = usb.util.get_string(self.dev, 256, self.dev.iProduct)
else:
manufacturer = usb.util.get_string(self.dev, self.dev.iManufacturer)
product = usb.util.get_string(self.dev, self.dev.iProduct)
return ("%s - %s") % (manufacturer, product)
except ValueError as e:
_logger.warning(e)
......
......@@ -78,7 +78,10 @@ class EscposDriver(Thread):
for printer in printers:
try:
description = usb.util.get_string(printer, 256, printer.iManufacturer) + " " + usb.util.get_string(printer, 256, printer.iProduct)
if usb.__version__ == '1.0.0b1':
description = usb.util.get_string(printer, 256, printer.iManufacturer) + " " + usb.util.get_string(printer, 256, printer.iProduct)
else:
description = usb.util.get_string(printer, printer.iManufacturer) + " " + usb.util.get_string(printer, printer.iProduct)
except Exception as e:
_logger.error("Can not get printer description: %s" % e)
description = 'Unknown printer'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment