Merge branch 'development' into patch-1

This commit is contained in:
Patrick Kanzler 2019-06-04 23:04:39 +02:00 committed by GitHub
commit 490e0657dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -11,6 +11,7 @@ Dmytro Katyukha
Gerard Marull-Paretas Gerard Marull-Paretas
Hark Hark
Joel Lehtonen Joel Lehtonen
Justin Vieira
kennedy kennedy
Kristi Kristi
ldos ldos
@ -20,6 +21,7 @@ Michael Billington
Michael Elsdörfer Michael Elsdörfer
mrwunderbar666 mrwunderbar666
Nathan Bookham Nathan Bookham
Omer Akram
Patrick Kanzler Patrick Kanzler
primax79 primax79
Qian Linfeng Qian Linfeng

View File

@ -38,7 +38,7 @@ else:
if full_load: if full_load:
logger.debug('Loading and pickling capabilities') logger.debug('Loading and pickling capabilities')
with open(capabilities_path) as cp, open(pickle_path, 'wb') as pp: with open(capabilities_path) as cp, open(pickle_path, 'wb') as pp:
CAPABILITIES = yaml.load(cp) CAPABILITIES = yaml.safe_load(cp)
pickle.dump(CAPABILITIES, pp, protocol=2) pickle.dump(CAPABILITIES, pp, protocol=2)
logger.debug('Finished loading capabilities took %.2fs', time.time() - t0) logger.debug('Finished loading capabilities took %.2fs', time.time() - t0)

View File

@ -68,19 +68,24 @@ class Usb(Escpos):
self.idVendor = self.device.idVendor self.idVendor = self.device.idVendor
self.idProduct = self.device.idProduct self.idProduct = self.device.idProduct
check_driver = None # pyusb has three backends: libusb0, libusb1 and openusb but
# only libusb1 backend implements the methods is_kernel_driver_active()
# and detach_kernel_driver().
# This helps enable this library to work on Windows.
if self.device.backend.__module__.endswith("libusb1"):
check_driver = None
try:
check_driver = self.device.is_kernel_driver_active(0)
except NotImplementedError:
pass
if check_driver is None or check_driver:
try: try:
self.device.detach_kernel_driver(0) check_driver = self.device.is_kernel_driver_active(0)
except usb.core.USBError as e: except NotImplementedError:
if check_driver is not None: pass
print("Could not detatch kernel driver: {0}".format(str(e)))
if check_driver is None or check_driver:
try:
self.device.detach_kernel_driver(0)
except usb.core.USBError as e:
if check_driver is not None:
print("Could not detatch kernel driver: {0}".format(str(e)))
try: try:
self.device.set_configuration() self.device.set_configuration()