Configuration max text length via config file

This commit is contained in:
n07070
2026-11-13 19:47:36 +01:00
parent 086a7ae640
commit e8568795b2

View File

@@ -119,6 +119,7 @@ class EscPosPrinter(Printer):
self.usb_args = {} self.usb_args = {}
self.usb_args["idVendor"] = self.vendor_id self.usb_args["idVendor"] = self.vendor_id
self.usb_args["idProduct"] = self.device_id self.usb_args["idProduct"] = self.device_id
self.configuration_file = configuration_file
try: try:
# This also calls open(), which we need to close() # This also calls open(), which we need to close()
@@ -148,13 +149,13 @@ class EscPosPrinter(Printer):
vendor_id=self.vendor_id, vendor_id=self.vendor_id,
product_id=self.device_id, product_id=self.device_id,
serial_number="", serial_number="",
label_type=configuration_file["label_type"], label_type=self.configuration_file["label_type"],
) )
# Setting up the printing options. # Setting up the printing options.
# TODO : Expose this to the web interface # TODO : Expose this to the web interface
p.set( p.set(
align=configuration_file["align_text"], align=self.configuration_file["align_text"],
font="a", font="a",
bold=False, bold=False,
underline=0, underline=0,
@@ -213,25 +214,23 @@ class EscPosPrinter(Printer):
clean_signature = str(signature) clean_signature = str(signature)
# Make checks on the size of the message being printed # Make checks on the size of the message being printed
# TODO: make the max length configurable if len(clean_msg) > int(self.configuration_file["text_max_length"]):
if len(clean_msg) > 4096:
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 RuntimeError( 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 %s caracters long.", str(self.configuration_file["text_max_length"])
) )
# TODO: make the max length configurable if len(signature) > int(self.configuration_file["signature_max_length"]):
if len(signature) > 256:
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 RuntimeError( 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 %s caracters long.", str(self.configuration_file["signature_max_length"])
) )
# Do the actual printing # Do the actual printing
@@ -256,17 +255,17 @@ class EscPosPrinter(Printer):
def _print_img(self, path, signature="", center=True, process=False): def _print_img(self, path, signature="", center=True, process=False):
clean_signature = str(signature) clean_signature = str(signature)
# TODO: make the max length configurable if len(signature) > int(self.configuration_file["signature_max_length"]):
if len(signature) > 256:
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 ValueError( 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 %s caracters long.", str(self.configuration_file["signature_max_length"])
) )
if not os.path.isfile(str(path)): if not os.path.isfile(str(path)):
self.app.logger.warning("File does not exist : " + str(path)) self.app.logger.warning("File does not exist : " + str(path))
raise OSError( raise OSError(