Restructure the code and implement a printing queue #29
@@ -69,7 +69,7 @@ class Printer(object):
|
|||||||
|
|
||||||
# TODO: This could happen directly when creating a new Printer class
|
# TODO: This could happen directly when creating a new Printer class
|
||||||
if os.getenv("FLASK_DEBUG"):
|
if os.getenv("FLASK_DEBUG"):
|
||||||
waiting_elapsed = 15
|
waiting_elapsed = 3
|
||||||
else:
|
else:
|
||||||
waiting_elapsed = 10
|
waiting_elapsed = 10
|
||||||
|
|
||||||
@@ -82,19 +82,18 @@ class Printer(object):
|
|||||||
p = escpos.printer.Usb(
|
p = escpos.printer.Usb(
|
||||||
self.device_id, self.vendor_id, 0, profile="TM-P80"
|
self.device_id, self.vendor_id, 0, profile="TM-P80"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except RuntimeError as e:
|
||||||
self.app.logger.error(
|
self.app.logger.error(
|
||||||
"The USB device is not plugged in, trying again %s : %s",
|
"The USB device is not plugged in, trying again %s : %s",
|
||||||
waiting_elapsed,
|
waiting_elapsed,
|
||||||
str(e),
|
str(e),
|
||||||
)
|
)
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if p.is_online():
|
if p.is_online():
|
||||||
self.ready = True
|
self.ready = True
|
||||||
self.app.logger.debug("Printer online !")
|
self.app.logger.debug("Printer online !")
|
||||||
except Exception as e:
|
except RuntimeError as e:
|
||||||
self.app.logger.error(
|
self.app.logger.error(
|
||||||
"Error while getting the printer online %s : %s",
|
"Error while getting the printer online %s : %s",
|
||||||
waiting_elapsed,
|
waiting_elapsed,
|
||||||
@@ -154,7 +153,7 @@ class Printer(object):
|
|||||||
self.app.logger.warning(
|
self.app.logger.warning(
|
||||||
"Could not print message of this length: " + str(len(clean_msg))
|
"Could not print message of this length: " + str(len(clean_msg))
|
||||||
)
|
)
|
||||||
raise Exception(
|
raise RuntimeError(
|
||||||
"Could not print message of this length :"
|
"Could not print message of this length :"
|
||||||
+ str(len(clean_msg))
|
+ str(len(clean_msg))
|
||||||
+ ", needs to be below 4096 caracters long."
|
+ ", needs to be below 4096 caracters long."
|
||||||
@@ -164,7 +163,7 @@ class Printer(object):
|
|||||||
self.app.logger.warning(
|
self.app.logger.warning(
|
||||||
"Could not print signature of this length: " + str(len(clean_signature))
|
"Could not print signature of this length: " + str(len(clean_signature))
|
||||||
)
|
)
|
||||||
raise Exception(
|
raise RuntimeError(
|
||||||
"Could not print signature of this length :"
|
"Could not print signature of this length :"
|
||||||
+ str(len(clean_signature))
|
+ str(len(clean_signature))
|
||||||
+ ", needs to be below 256 caracters long."
|
+ ", needs to be below 256 caracters long."
|
||||||
@@ -256,7 +255,7 @@ class Printer(object):
|
|||||||
self.printer.open(self.usb_args)
|
self.printer.open(self.usb_args)
|
||||||
self.printer.qr(content, center=True)
|
self.printer.qr(content, center=True)
|
||||||
self.printer.close()
|
self.printer.close()
|
||||||
except Exception as e:
|
except RuntimeError as e:
|
||||||
self.printer.close()
|
self.printer.close()
|
||||||
self.app.logger.error(str(e))
|
self.app.logger.error(str(e))
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user